Android OpenCV - 确定 MatOfPoint 是否包含一个点
Android OpenCV - determine if MatOfPoint contains a point
我正在使用 Android 的 OpenCV3 库,我能够成功扫描特定颜色的色块。
我尝试扩展此功能,以便能够通过对我想要的 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
的文档,似乎没有直接的方法来检查它是否包含某个点。
您必须使用实用程序 class Imgproc
.
中声明的方法 pointPolygonTest
我正在使用 Android 的 OpenCV3 库,我能够成功扫描特定颜色的色块。
我尝试扩展此功能,以便能够通过对我想要的 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
的文档,似乎没有直接的方法来检查它是否包含某个点。
您必须使用实用程序 class Imgproc
.
pointPolygonTest