【发布时间】:2015-07-23 07:09:05
【问题描述】:
我想找到最大轮廓的凸面并获得凸面缺陷。这是我寻找最大轮廓的代码。我使用 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();
【问题讨论】:
-
看看here