List of usage examples for org.opencv.core Mat height
public int height()
From source file:org.lasarobotics.vision.image.Filter.java
License:Open Source License
/** * Upsample and blur an image (using a Gaussian pyramid kernel) * * @param img The image/*www.j a v a2 s .c o m*/ * @param scale The scale, a number greater than 1 */ public static void upsample(Mat img, double scale) { Imgproc.pyrUp(img, img, new Size((double) img.width() * scale, (double) img.height() * scale)); }
From source file:org.lasarobotics.vision.image.Transform.java
License:Open Source License
/** * Rotate an image by an angle (counterclockwise) * * @param image Transform matrix// www . jav a 2s . c o m * @param angle Angle to rotate by (counterclockwise) from -360 to 360 */ public static void rotate(Mat image, double angle) { //Calculate size of new matrix double radians = Math.toRadians(angle); double sin = Math.abs(Math.sin(radians)); double cos = Math.abs(Math.cos(radians)); int newWidth = (int) (image.width() * cos + image.height() * sin); int newHeight = (int) (image.width() * sin + image.height() * cos); // rotating image Point center = new Point(newWidth / 2, newHeight / 2); Mat rotMatrix = Imgproc.getRotationMatrix2D(center, angle, 1.0); //1.0 means 100 % scale Size size = new Size(newWidth, newHeight); Imgproc.warpAffine(image, image, rotMatrix, image.size()); }
From source file:org.mixare.MixView.java
License:Open Source License
@Override public Mat onCameraFrame(CvCameraViewFrame inputFrame) { Mat rgba = inputFrame.rgba();//ww w. j a v a 2 s .c om if (createBitmap == true) { try { Point p1 = new Point(selectionStart.x, selectionStart.y); Point p2 = new Point(selectionEnd.x, selectionEnd.y); org.opencv.core.Rect rect = new org.opencv.core.Rect(p1, p2); Mat thumnailMat = new Mat(rgba, rect); thumbnail = Bitmap.createBitmap(thumnailMat.width(), thumnailMat.height(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(thumnailMat, thumbnail); createBitmap = false; } catch (Exception ex) { // Toast.makeText(this, "Please try selecting object again!!", // Toast.LENGTH_SHORT).show(); Log.e("Mixare", "Error while selecting object", ex); } } return rgba; }
From source file:org.openpnp.machine.reference.ReferenceCamera.java
License:Open Source License
private Mat rotate(Mat mat, double rotation) { if (rotation == 0D) { return mat; }//from ww w . jav a 2 s.c o m // See: // http://stackoverflow.com/questions/22041699/rotate-an-image-without-cropping-in-opencv-in-c Point center = new Point(mat.width() / 2D, mat.height() / 2D); Mat mapMatrix = Imgproc.getRotationMatrix2D(center, rotation, 1.0); // determine bounding rectangle Rect bbox = new RotatedRect(center, mat.size(), rotation).boundingRect(); // adjust transformation matrix double[] cx = mapMatrix.get(0, 2); double[] cy = mapMatrix.get(1, 2); cx[0] += bbox.width / 2D - center.x; cy[0] += bbox.height / 2D - center.y; mapMatrix.put(0, 2, cx); mapMatrix.put(1, 2, cy); Mat dst = new Mat(bbox.width, bbox.height, mat.type()); Imgproc.warpAffine(mat, dst, mapMatrix, bbox.size(), Imgproc.INTER_LINEAR); mat.release(); mapMatrix.release(); return dst; }
From source file:org.sikuli.android.ADBDevice.java
License:MIT License
public BufferedImage captureDeviceScreen(int x, int y, int w, int h) { Mat matImage = captureDeviceScreenMat(x, y, w, h); BufferedImage bImage = null;//from ww w .ja v a 2s . c om if (matImage != null) { bImage = new BufferedImage(matImage.width(), matImage.height(), BufferedImage.TYPE_3BYTE_BGR); byte[] bImageData = ((DataBufferByte) bImage.getRaster().getDataBuffer()).getData(); matImage.get(0, 0, bImageData); } return bImage; }
From source file:org.sikuli.script.Finder.java
License:MIT License
private static Rect getSubMatRect(Mat mat, int x, int y, int w, int h, int margin) { x = Math.max(0, x - margin);/*from ww w. j a va 2 s. c o m*/ y = Math.max(0, y - margin); w = Math.min(w + 2 * margin, mat.width() - x); h = Math.min(h + 2 * margin, mat.height() - y); return new Rect(x, y, w, h); }
From source file:org.usfirst.frc.team2084.CMonster2016.vision.ImageConvertor.java
License:Open Source License
public BufferedImage toBufferedImage(Mat image) { int width = image.width(); int height = image.height(); int type = image.type(); // Get BufferedImage type int javaType = toJavaImageType(type); // If the Mat does not match the BufferedImage, create a new one. if (javaImage == null || width != javaImage.getWidth() || height != javaImage.getHeight() || javaType != javaImage.getType()) { javaImage = new BufferedImage(width, height, javaType); }//from w w w . j a v a2 s. c o m // Copy Mat data to BufferedImage image.get(0, 0, ((DataBufferByte) javaImage.getRaster().getDataBuffer()).getData()); return javaImage; }
From source file:org.usfirst.frc2084.CMonster2016.vision.ImageFrame.java
License:Open Source License
/** * Shows the specified image in the frame. The frame resizes to fit the * image.//from ww w . ja va 2 s . com * * @param image the image to show */ public void showImage(Mat image) { // Get the properties of the Mat int width = image.width(); int height = image.height(); synchronized (this) { // Copy Mat data to BufferedImage javaImage = convertor.toBufferedImage(image); } setSize(width, height); repaint(); }
From source file:Recognizer.Recognizer.java
public Image TemplateMatching(Image imQuery, Image imDB, int match_method) { System.out.println("Running Template Matching ..."); //Mat img = Highgui.imread(inFile); // Image in which area has to be searched //Mat template_img = Highgui.imread(templateFile); // Search Image Mat matQuery = imQuery.Image3CtoMat_CV(); Mat matDB = imDB.Image3CtoMat_CV(); Mat hsvQ = new Mat(), hsvDB = new Mat(); Imgproc.cvtColor(matQuery, hsvQ, COLOR_RGB2HSV); Imgproc.cvtColor(matDB, hsvDB, COLOR_RGB2HSV); // Create result image matrix int resultImg_cols = matDB.cols() - matQuery.cols() + 1; int resultImg_rows = matDB.rows() - matQuery.rows() + 1; Mat matRes = new Mat(resultImg_rows, resultImg_cols, CvType.CV_32FC1); // Template Matching with Normalization Imgproc.matchTemplate(hsvDB, hsvQ, matRes, match_method); Core.normalize(matRes, matRes, 0, 1, Core.NORM_MINMAX, -1, new Mat()); // / Localizing the best match with minMaxLoc Core.MinMaxLocResult Location_Result = Core.minMaxLoc(matRes); Point matchLocation;//from w w w . j a va 2 s .co m if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) { matchLocation = Location_Result.minLoc; } else { matchLocation = Location_Result.maxLoc; } // Display Area by Rectangle Core.rectangle(matDB, matchLocation, new Point(matchLocation.x + matQuery.cols(), matchLocation.y + matQuery.rows()), new Scalar(0, 255, 0)); Image imOut = new Image(matDB.width(), matDB.height()); //Image imOut = new Image(matQuery.cols(), matQuery.rows()); //Mat m = new Mat(matDB); //m =//matDB.submat((int)matchLocation.y, (int)matchLocation.y + matQuery.rows(),(int)matchLocation.x, (int)matchLocation.x + matQuery.cols()); imOut.Mat_CVtoImage3C(matDB); System.out.println("Location: " + Location_Result.minLoc.x + " " + Location_Result.minLoc.y + " " + Location_Result.maxLoc.x + " " + Location_Result.maxLoc.y); return imOut; }
From source file:servershootingstar.BallDetector.java
public static void initSwing(Mat mat) { guiFrame = new JFrame("window"); guiFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // image size is 640x480 guiFrame.setSize(mat.width() + 20, mat.height() + 40); guiFrame.setLayout(new FlowLayout()); guiLabel = new JLabel(); guiFrame.add(guiLabel);//from w ww .j a v a 2 s .co m guiFrame.setVisible(true); updateSwing(mat); }