Android OpenCV - 确定MatOfPoint是否包含一个点。

问题描述 投票:1回答:1

我正在使用Android的OpenCV3库,我能够成功地扫描某种颜色的颜色blob。

我试图扩展这个功能,通过硬编码我想要的HSV值,能够扫描某个颜色阴影的网格中的轮廓。接下来我想做的是能够确定一个点是否包含在我的轮廓中。

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);
}

现在我不知道该如何继续检查我的 contours 名单 MatOfPoint)包含某一点 p. 我查了一下文件 MatOfPoint 而它好像没有一个直接的方法来检查它是否包含某个点。

android opencv opencv4android
1个回答
2
投票

你必须使用方法 pointPolygonTest 实用类中声明的 Imgproc.

© www.soinside.com 2019 - 2024. All rights reserved.