我需要提取图像的最大轮廓 . 这是我目前正在使用的代码 . 在线收集了几个片段
List contours = new ArrayList();
Imgproc.findContours(outerBox, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
double maxArea = -1;
int maxAreaIdx = -1;
for (int idx = 0; idx < contours.size(); idx++) {
Mat contour = contours.get(idx);
double contourarea = Imgproc.contourArea(contour);
if (contourarea > maxArea) {
maxArea = contourarea;
maxAreaIdx = idx;
}
}
它似乎工作 . 但是,我不太确定如何从这里开始 . 我尝试使用 Imgproc.floodFill ,但我不太清楚如何 . 此功能需要与原始 Mat 2水平和2垂直相同大小的桅杆 Mat . 当我在轮廓 contours.get(maxAreaIdx) 上运行它时,它给了我一个错误 . 代码:
Mat mask = Mat.zeros(contour.rows() + 2, contour.cols() + 2, CvType.CV_8UC1);
int area = Imgproc.floodFill(contour, mask, new Point(0,0), new Scalar(255, 255, 255));
错误:
11-18 19:07:49.406: E/cv::error()(3117): OpenCV Error: Unsupported format or combination of formats () in void cvFloodFill(CvArr*, CvPoint, CvScalar, CvScalar, CvScalar, CvConnectedComp*, int, CvArr*), file /home/oleg/sources/opencv/modules/imgproc/src/floodfill.cpp, line 621
所以基本上我的问题是,在找到面积最大的轮廓后,我怎么能“突出”它呢?我希望其他一切都是黑色的,轮廓是白色的
谢谢!