我想找到最大轮廓的凸起和凸起缺陷。这是我找到最大轮廓的代码。我使用opencv for android。请某人公会我。
Imgproc.cvtColor (inputFrame.rgba(), mIntermediateMat, Imgproc.COLOR_RGB2YCrCb, 4);
Core.inRange(mIntermediateMat, new Scalar(1, 133, 77), new Scalar(255, 173, 127), mGray);
Imgproc.erode(mGray,mGray, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4)));
Imgproc.dilate(mGray, mGray, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4, 4)));
Imgproc.blur(mGray, mGray, new Size(3.0, 3.0));
Imgproc.adaptiveThreshold(mGray, mcontour, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY_INV, 3, 1);
mRgba = inputFrame.rgba();
maxContourArea=0;
contours= new ArrayList<MatOfPoint>();
Imgproc.findContours(mcontour, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
for (int idx = 0; idx < contours.size(); idx++)
{
contour = contours.get(idx);
double contourarea = Imgproc.contourArea(contour);
if (contourarea > maxContourArea )
{
maxContourArea = contourarea;
maxAreaIdx = idx;
}
}
if(maxContourArea>1000)
{
Imgproc.drawContours ( mRgba, contours, maxAreaIdx, new Scalar(120,120,120),2);
}
contours.clear();
答案 0 :(得分:0)
有关于
的功能 cv::convexityDefects()
找出轮廓的凸性缺陷
cv::isContourConvex()
测试轮廓凸度
http://docs.opencv.org/3.0.0/d3/dc0/group__imgproc__shape.html