Search in sources :

Example 31 with Point

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;
}
Also used : Size(org.opencv.core.Size) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint)

Example 32 with Point

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;
}
Also used : Mat(org.opencv.core.Mat) ArrayList(java.util.ArrayList) MatOfPoint(org.opencv.core.MatOfPoint) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint)

Example 33 with Point

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;
}
Also used : MatOfPoint(org.opencv.core.MatOfPoint) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint)

Example 34 with Point

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;
}
Also used : Mat(org.opencv.core.Mat) ArrayList(java.util.ArrayList) MatOfPoint(org.opencv.core.MatOfPoint) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint)

Example 35 with Point

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;
}
Also used : MatOfPoint2f(org.opencv.core.MatOfPoint2f) Point(org.opencv.core.Point) MatOfPoint(org.opencv.core.MatOfPoint)

Aggregations

Point (org.opencv.core.Point)56 MatOfPoint (org.opencv.core.MatOfPoint)30 Mat (org.opencv.core.Mat)23 ArrayList (java.util.ArrayList)11 Scalar (org.opencv.core.Scalar)9 Line (com.disnodeteam.dogecv.math.Line)7 Rect (org.opencv.core.Rect)7 Size (org.opencv.core.Size)7 MatOfPoint2f (org.opencv.core.MatOfPoint2f)4 TimingLogger (android.util.TimingLogger)2 Ponto (br.edu.ifspsaocarlos.sdm.kifurecorder.processing.cornerDetector.Ponto)2 KeyPoint (org.opencv.core.KeyPoint)2 MatOfKeyPoint (org.opencv.core.MatOfKeyPoint)2 Pair (android.util.Pair)1 Corner (br.edu.ifspsaocarlos.sdm.kifurecorder.processing.cornerDetector.Corner)1 Rectangle (java.awt.Rectangle)1 List (java.util.List)1 ImageNotFoundException (org.getopentest.exceptions.ImageNotFoundException)1 Core (org.opencv.core.Core)1 MinMaxLocResult (org.opencv.core.Core.MinMaxLocResult)1