List of usage examples for org.opencv.core Point Point
public Point(double x, double y)
From source file:net.bsrc.cbod.opencv.OpenCV.java
public static Point getCenterPoint(Rect rect) { double centerX = rect.x + (rect.width / 2.0); double centerY = rect.y + (rect.height / 2.0); return new Point(centerX, centerY); }
From source file:net.bsrc.cbod.opencv.OpenCV.java
/** * @param imagePath name of the orginal image * @param mapFilePath name of the orginal image's map file * @return/*w ww. j ava2 s . c o m*/ */ public static List<Mat> getSegmentedRegions(String imagePath, String mapFilePath, boolean isBlackBg) { Mat org = getImageMat(imagePath); RegionMap regionMap = RegionMapFactory.getRegionMap(imagePath, mapFilePath); List<Mat> result = new ArrayList<Mat>(); Mat map = regionMap.getMap(); for (Integer label : regionMap.getLabels()) { List<Point> points = new ArrayList<Point>(); for (int i = 0; i < map.rows(); i++) { for (int j = 0; j < map.cols(); j++) { double[] temp = map.get(i, j); if (temp[0] == label) { // Warning! col=x=j , row=y=i points.add(new Point(j, i)); } } } Point[] arr = points.toArray(new Point[points.size()]); Rect rect = Imgproc.boundingRect(new MatOfPoint(arr)); Mat region; if (isBlackBg) { region = getImageWithBlackBg(org, points).submat(rect); } else { region = org.submat(rect); } result.add(region); } return result; }
From source file:net.bsrc.cbod.opencv.OpenCV.java
/** * @param imagePath//from w w w . j a v a 2 s . co m * @param mapFilePath * @param isBlackBg * @return */ public static List<ImageModel> getSegmentedRegionsAsImageModels(String imagePath, String mapFilePath, boolean isBlackBg) { Mat org = getImageMat(imagePath); RegionMap regionMap = RegionMapFactory.getRegionMap(imagePath, mapFilePath); List<ImageModel> result = new ArrayList<ImageModel>(); Mat map = regionMap.getMap(); for (Integer label : regionMap.getLabels()) { List<Point> points = new ArrayList<Point>(); for (int i = 0; i < map.rows(); i++) { for (int j = 0; j < map.cols(); j++) { double[] temp = map.get(i, j); if (temp[0] == label) { // Warning! col=x=j , row=y=i points.add(new Point(j, i)); } } } Point[] arr = points.toArray(new Point[points.size()]); Rect rect = null; try { rect = Imgproc.boundingRect(new MatOfPoint(arr)); } catch (Exception ex) { logger.error("", ex); continue; } Mat region; if (isBlackBg) { region = getImageWithBlackBg(org, points).submat(rect); } else { region = org.submat(rect); } ImageModel imgModel = new ImageModel(); imgModel.setMat(region); imgModel.setRelativeToOrg(rect); result.add(imgModel); } return result; }
From source file:net.bsrc.cbod.opencv.OpenCV.java
/** * 0------1//from w ww . ja v a 2 s .c o m * | | * | | * 3------2 */ public static Point[] getCornerPoints(Rect rect) { Point[] arr = new Point[] { new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Point(rect.x, rect.y + rect.height) }; return arr; }
From source file:nz.ac.auckland.lablet.views.graph.AbstractGraphAdapter.java
License:Open Source License
/** * Saves plot data into png and csv formats. * @param dir directory in which to save the files * @param pngFilename filename for png file * @param csvFilename filename for csv file *///w ww . j av a 2 s .c om private void saveToExperiment(final File dir, final String pngFilename, final String csvFilename) { final FileOutputStream pngFile = experimentFileOutputStream(dir, pngFilename); final FileWriter csvFile = experimentFileWriter(dir, csvFilename); int width = getWidth(); int height = getHeight(); int measureWidth = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); int measureHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (pngFile != null) { // draw graph to a bitmap setAdapter(adapter); measure(measureWidth, measureHeight); layout(0, 0, getMeasuredWidth(), getMeasuredHeight()); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); draw(canvas); // compress and save bitmap bitmap.compress(Bitmap.CompressFormat.PNG, 100, pngFile); try { pngFile.close(); } catch (IOException e) { Log.e(TAG, "Graph PNG file could not be closed for some reason."); } } if (csvFile != null) { // save data points to CSV file List<Point> dataPoints = new ArrayList<>(); for (int i = 0; i < adapter.getSize(); i++) { dataPoints.add(new Point(adapter.getX(i).floatValue(), adapter.getY(i).floatValue())); } FileHelper.writePlotDataToCSV(dataPoints, csvFile); } Toast.makeText(getContext(), "Graph data saved", Toast.LENGTH_LONG).show(); }
From source file:nz.ac.auckland.lablet.vision.CamShiftTracker.java
License:Open Source License
/** * Gets the location of an object in a frame. Assumes you have called setRegionOfInterest, * which informs CamShiftTracker which object to track. * * @param frame The frame to search for the object in. * @return The location and bounds of the object, represented by a Rect. *//*from w ww . j av a 2s. c o m*/ public Rect getObjectLocation(Bitmap frame) { Mat image = new Mat(); Utils.bitmapToMat(frame, image); // Mat out = new Mat(image.rows(), image.cols(), image.type()); // image.convertTo(out, -1, 2.0, 2.0); // image = out; toHsv(image, hsvMin, hsvMax); ArrayList<Mat> hsvs = new ArrayList<>(); hsvs.add(hsv); Imgproc.calcBackProject(hsvs, new MatOfInt(0), hist, backproj, ranges, 1); Core.bitwise_and(backproj, mask, backproj); try { Rect tempTrackWindow = trackWindow.clone(); RotatedRect result = Video.CamShift(backproj, trackWindow, termCriteria); if (result.size.equals(new Size(0, 0)) && result.angle == 0 && result.center.equals(new Point(0, 0))) { trackWindow = tempTrackWindow; return null; } } catch (Exception e) { Log.e(TAG, "Shit went down: ", e); return null; } return trackWindow.clone(); }
From source file:openbjk.detectar.java
public void run(Canvas c, Mat image) throws IOException { System.out.println("Rodando DetectFace"); CascadeClassifier faceDetector = new CascadeClassifier( "C:\\Users\\Gertrude\\Documents\\NetBeansProjects\\TCC-FacialRecognize\\src\\resources\\lbpcascade_frontalface.xml"); //Mat image = Highgui.imread("C:/Users/Gertrude/Desktop/TCC/img/lena.png"); MatOfRect faceDetections = new MatOfRect(); faceDetector.detectMultiScale(image, faceDetections); System.out.printf("Detected %s faces", faceDetections.toArray().length); for (Rect rect : faceDetections.toArray()) { Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0)); }// w w w . ja v a 2 s.c o m String filename = "C:/Users/DS-007/Pictures/faceDetection.png"; System.out.println(String.format("Writing %s", filename)); Highgui.imwrite(filename, image); int type = BufferedImage.TYPE_BYTE_GRAY; MatOfByte bytemat = new MatOfByte(); Highgui.imencode(".png", image, bytemat); byte[] bytes = bytemat.toArray(); InputStream in = new ByteArrayInputStream(bytes); BufferedImage render = ImageIO.read(in); // c.setSize(render.getWidth(), render.getHeight()); Graphics g = c.getGraphics(); g.drawImage(render, 1, 1, c.getHeight(), c.getWidth(), Color.LIGHT_GRAY, c); }
From source file:opencltest.YetAnotherTestT.java
private static void paintLines(Mat targetImg, Mat lines) { for (int x = 0; x < lines.rows(); x++) { double[] vec = lines.get(x, 0); double x1 = vec[0], y1 = vec[1], x2 = vec[2], y2 = vec[3]; Point start = new Point(x1, y1); Point end = new Point(x2, y2); Imgproc.line(targetImg, start, end, new Scalar(255, 0, 0), 1); }/*from ww w .java2 s . c o m*/ }
From source file:opencltest.YetAnotherTestT.java
private static void drawCross(double x, double y, Mat foundSquare) { Imgproc.line(foundSquare, new Point(x, 0), new Point(x, foundSquare.height()), new Scalar(255, 0, 0, 180), 1);//ww w. java 2 s. c om Imgproc.line(foundSquare, new Point(0, y), new Point(foundSquare.width(), y), new Scalar(255, 0, 0, 180), 1); }
From source file:opencltest.YetAnotherTestT.java
private static void draw(List<Double> result, Mat test) { for (int i = 1; i < result.size() - 1; i++) { if (result.get(i) > result.get(i + 1) && result.get(i) > result.get(i - 1)) { Imgproc.line(test, new Point(i, 0), new Point(i, test.height()), // new Scalar(result.get(i), 0, 0), 1 new Scalar(0, 0, 255), 1); }/*from w ww . j a va 2 s. c o m*/ // Imgproc.line(test, // new Point(i, 0), new Point(i, test.height()), // new Scalar(result.get(i), 0, 0), 1 //// new Scalar(0,0,255),1 // ); } }