Razgriz
Razgriz

Reputation: 7343

Android OpenCV - determine if MatOfPoint contains a point

I am using the OpenCV3 Library for Android and I am able to scan a color blob of a certain color successfully.

I tried to extend this capability to be able to scan contours in a grid that's shaded by certain colour by hard coding the HSV values I want. What I want to do next is to be able to determine if a Point is contained in my contour.

mDetector.process(inputMat); //inputMat is the mat that I process.
List<MatOfPoint> contours = mDetector.getContours();

Mat colorLabel = inputMat.submat(4, 68, 4, 68);
colorLabel.setTo(mBlobColorRgba);

Mat spectrumLabel = inputMat.submat(4, 4 + mSpectrum.rows(), 70, 70 + mSpectrum.cols());
mSpectrum.copyTo(spectrumLabel);

MatOfPoint2f approxCurve = new MatOfPoint2f();

//For each contour found
for (int i = 0; i < contours.size(); i++) {
    //Convert contours(i) from MatOfPoint to MatOfPoint2f
    MatOfPoint2f contour2f = new MatOfPoint2f( contours.get(i).toArray() );

    //Processing on mMOP2f1 which is in type MatOfPoint2f
    double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
    Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

    Imgproc.drawContours(inputMat, contours, -1, new Scalar(0, 150, 0));

    Point p = new Point(x,y);
}

Now I am not sure how to proceed with checking if my contours List (of a MatOfPoint) contains a certain point p. I checked the documentation for MatOfPoint and it seems like it does not have a straightforward way to check if it contains a certain point.

Upvotes: 1

Views: 906

Answers (1)

ArtemStorozhuk
ArtemStorozhuk

Reputation: 8725

You have to use method pointPolygonTest that is declared in utility class Imgproc.

Upvotes: 2

Related Questions