use of org.opencv.core.Point in project kifu-recorder by leonardost.
the class FirstEllipseDetector method preprocessImage.
private Mat preprocessImage(Mat image) {
// Blur image to smooth noise
Imgproc.blur(image, image, new Size(3, 3));
// Imgcodecs.imwrite(filePrefix + "_preprocessed_image_0.png", image);
// Detect borders with Canny filter
image = detectBordersIn(image);
// Imgcodecs.imwrite(filePrefix + "_preprocessed_image_1.png", image);
Imgproc.dilate(image, image, Mat.ones(3, 3, CvType.CV_32F), new Point(-1, -1), 3);
Imgproc.erode(image, image, Mat.ones(3, 3, CvType.CV_32F), new Point(-1, -1), 3);
// Imgcodecs.imwrite(filePrefix + "_preprocessed_image_2.png", image);
// Invert regions
Core.bitwise_not(image, image);
Imgproc.erode(image, image, Mat.ones(3, 3, CvType.CV_32F), new Point(-1, -1), 1);
// Imgcodecs.imwrite(filePrefix + "_preprocessed_image_3.png", image);
return image;
}
use of org.opencv.core.Point in project kifu-recorder by leonardost.
the class InitialBoardDetector method detectContours.
private List<MatOfPoint> detectContours(Mat imageWithBordersInEvidence) {
// The contours delimited by lines are found
List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(imageWithBordersInEvidence, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
Log.d("kifu-recorder", "Number of contours found: " + contours.size());
// Remove very small contours which are probably noise
for (Iterator<MatOfPoint> it = contours.iterator(); it.hasNext(); ) {
MatOfPoint contour = it.next();
// The ideal would be to do this as a ratio on the area of the image
if (Imgproc.contourArea(contour) < 700) {
it.remove();
}
}
// Image is converted to a color format again
Imgproc.cvtColor(imageWithBordersInEvidence, image, Imgproc.COLOR_GRAY2BGR, 4);
imageWithBordersInEvidence.release();
return contours;
}
use of org.opencv.core.Point in project kifu-recorder by leonardost.
the class DetectBoardActivity method convertToMatOfPoint.
private MatOfPoint convertToMatOfPoint(Mat boardPositionInImage) {
Point[] corners = { new Point(boardPositionInImage.get(0, 0)[0], boardPositionInImage.get(0, 0)[1]), new Point(boardPositionInImage.get(1, 0)[0], boardPositionInImage.get(1, 0)[1]), new Point(boardPositionInImage.get(2, 0)[0], boardPositionInImage.get(2, 0)[1]), new Point(boardPositionInImage.get(3, 0)[0], boardPositionInImage.get(3, 0)[1]) };
boardContour = new MatOfPoint(corners);
return boardContour;
}
use of org.opencv.core.Point in project kifu-recorder by leonardost.
the class SecondEllipseDetector method findContoursIn.
private List<MatOfPoint> findContoursIn(Mat image) {
List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
removeSmallContours(contours);
// System.out.println("Number of contours found in scene: " + contours.size());
return contours;
}
use of org.opencv.core.Point in project kifu-recorder by leonardost.
the class QuadrilateralHierarchy method isInside.
/**
* Checks if a quadrilateral is inside another
*
* @param externalQuadrilateral
* @param internalQuadrilateral
* @return
*/
private boolean isInside(MatOfPoint externalQuadrilateral, MatOfPoint internalQuadrilateral) {
final double IS_INSIDE_CONTOUR = 1;
double result;
MatOfPoint2f externalQuadrilateral2f = new MatOfPoint2f();
externalQuadrilateral.convertTo(externalQuadrilateral2f, CvType.CV_32FC2);
for (Point point : internalQuadrilateral.toList()) {
result = Imgproc.pointPolygonTest(externalQuadrilateral2f, point, false);
if (result != IS_INSIDE_CONTOUR) {
return false;
}
}
return true;
}
Aggregations