List of usage examples for org.opencv.core MatOfPoint toList
public List<Point> toList()
From source file:emotion.Eyebrow.java
public static void Harris(Mat img, boolean rightEyeFlag) { //Harris point extraction Mat harrisTestimg;//ww w. j av a2 s.co m harrisTestimg = img.clone(); cvtColor(harrisTestimg, harrisTestimg, Imgproc.COLOR_BGR2GRAY); threshold(harrisTestimg, harrisTestimg, 200, 255, Imgproc.THRESH_BINARY_INV); Mat struct = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3)); erode(harrisTestimg, harrisTestimg, struct); dilate(harrisTestimg, harrisTestimg, struct); imwrite("intermediateHaaris.jpg", harrisTestimg); harrisTestimg.convertTo(harrisTestimg, CV_8UC1); ArrayList<MatOfPoint> contours = new ArrayList<>(); Mat hierarchy = new Mat(); Imgproc.findContours(harrisTestimg, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_NONE); //System.out.println("Average Y for contours:"); float[] averageY = new float[contours.size()]; for (int i = 0; i < contours.size(); ++i) { //We calculate mean of Y coordinates for each contour for (int j = 0; j < contours.get(i).total(); ++j) { int val = (int) contours.get(i).toArray()[j].y; averageY[i] += val; } averageY[i] /= contours.get(i).total(); //System.out.println(i+") "+averageY[i]); if (averageY[i] <= img.height() / 2 && //We consider just up half of an image contours.get(i).total() >= img.width()) //and longer than threshold Imgproc.drawContours(harrisTestimg, contours, i, new Scalar(255, 255, 255)); else Imgproc.drawContours(harrisTestimg, contours, i, new Scalar(0, 0, 0)); } MatOfPoint features = new MatOfPoint(); Imgproc.goodFeaturesToTrack(harrisTestimg, features, 100, 0.00001, 0); //We draw just 2 extreme points- first and last Point eyebrowsPoints[] = new Point[2]; for (int i = 0; i < features.toList().size(); i++) { if (i == 0) { eyebrowsPoints[0] = new Point(harrisTestimg.width() / 2, 0); eyebrowsPoints[1] = new Point(harrisTestimg.width() / 2, 0); } if (features.toArray()[i].x < eyebrowsPoints[0].x && features.toArray()[i].y < harrisTestimg.height() / 2) { eyebrowsPoints[0] = features.toArray()[i]; } if (features.toArray()[i].x > eyebrowsPoints[1].x && features.toArray()[i].y < harrisTestimg.height() / 2) { eyebrowsPoints[1] = features.toArray()[i]; } } StaticFunctions.drawCross(img, eyebrowsPoints[1], StaticFunctions.Features.EYEBROWS_ENDS); StaticFunctions.drawCross(img, eyebrowsPoints[0], StaticFunctions.Features.EYEBROWS_ENDS); imwrite("testHaris.jpg", img); if (rightEyeFlag) { EyeRegion.rightInnerEyebrowsCorner = eyebrowsPoints[0]; EyeRegion.rightInnerEyebrowsCorner.x += Eye.rightRect.x; EyeRegion.rightInnerEyebrowsCorner.y += Eye.rightRect.y; EyeRegion.rightOuterEyebrowsCorner = eyebrowsPoints[1]; EyeRegion.rightOuterEyebrowsCorner.x += Eye.rightRect.x; EyeRegion.rightOuterEyebrowsCorner.y += Eye.rightRect.y; } else { EyeRegion.leftInnerEyebrowsCorner = eyebrowsPoints[1]; EyeRegion.leftInnerEyebrowsCorner.x += Eye.leftRect.x; EyeRegion.leftInnerEyebrowsCorner.y += Eye.leftRect.y; EyeRegion.leftOuterEyebrowsCorner = eyebrowsPoints[0]; EyeRegion.leftOuterEyebrowsCorner.x += Eye.leftRect.x; EyeRegion.leftOuterEyebrowsCorner.y += Eye.leftRect.y; } }
From source file:opencv_ext.TGG_OpenCV_Util.java
private static MatOfPoint hull2Points(MatOfInt hull, MatOfPoint contour) { // Contains indexes of pointing to corner points of contours ArrayList<Integer> indexes = new ArrayList<>(hull.toList()); // Contains list of points found in contour List<Point> pointList = contour.toList(); // Destination for corner points ArrayList<Point> points = new ArrayList<>(); // Reads corner points into `points` for (Integer index : indexes) { points.add(pointList.get(index)); }/* w w w . ja v a2s . c o m*/ // Converts list to Mat representation MatOfPoint mop = new MatOfPoint(); mop.fromList(points); return mop; }
From source file:org.ar.rubik.Rhombus.java
License:Open Source License
/** * Rhombus Constructor//from w w w. ja va 2 s . c o m * * * @param polygon */ public Rhombus(MatOfPoint polygon) { this.polygonMatrix = polygon; polygonPointList = polygon.toList(); polygonePointArray = polygon.toArray(); }
From source file:org.pattern.image.viewer.renderer.RenderUtil.java
/** * Creates countour path from {@link MatOfPoint}. * @param contour /* ww w .j ava 2 s . c o m*/ * @return */ public static Path2D createContour(MatOfPoint contour) { List<Point> points = contour.toList(); Path2D.Double path = new Path2D.Double(); Iterator<Point> it = points.iterator(); if (it.hasNext()) { Point point = it.next(); path.moveTo(point.x, point.y); } while (it.hasNext()) { Point point = it.next(); path.lineTo(point.x, point.y); } path.closePath(); return path; }
From source file:org.sahyagiri.rpi.opencv.DetectCar.java
License:Mozilla Public License
private MatOfPoint combineContourPoints(ArrayList<MatOfPoint> contours) { MatOfPoint matPoints = new MatOfPoint(); List<Point> points = new ArrayList<Point>(); for (MatOfPoint point : contours) { points.addAll(point.toList()); }//from w w w . ja va2s . co m matPoints.fromList(points); return matPoints; }