我在Android上使用OpenCV 2.4.0并尝试在二进制邮件中找到轮廓。
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat mIntermediateMat = new Mat();
Imgproc.Canny(img, mIntermediateMat, 50, 100);
Imgproc.findContours(mIntermediateMat, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
但该函数会抛出“函数CvMat中无法识别或不支持的数组类型...”异常。
我也尝试将此Mat作为输入:
Mat mIntermediateMat = new Mat(height, width, CvType.CV_8UC1, new Scalar(0));
但我得到同样的例外。
答案 0 :(得分:1)
尝试此功能查找轮廓:
public static ArrayList<Rect> detection_contours(Mat outmat) {
Mat v = new Mat();
Mat vv = outmat.clone();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(vv, contours, v, Imgproc.RETR_LIST,
Imgproc.CHAIN_APPROX_SIMPLE);
double maxArea = 100;
int maxAreaIdx = -1;
Rect r = null;
ArrayList<Rect> rect_array = new ArrayList<Rect>();
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;
r = Imgproc.boundingRect(contours.get(maxAreaIdx));
rect_array.add(r);
// Imgproc.drawContours(imag, contours, maxAreaIdx, new Scalar(0,0, 255));
}
}
v.release();
return rect_array;
}
答案 1 :(得分:0)
确保在Canny()调用之后,mIntermediateMat的类型为CvType.CV_8 *