在Android findContours OpenCV的抛出异常 [英] OpenCV on Android findContours throws Exception
本文介绍了在Android findContours OpenCV的抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用在Android 2.4.0 OpenCV的,并设法找到轮廓二进制imgage。
I use OpenCV 2.4.0 on Android and try to find contours in a binary imgage.
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或不支持数组类型...异常。
But the function throws a "Unrecognized or unsupported array type in function CvMat..." exception.
此外,我试试这个垫子作为输入:
Also i try this Mat as input:
Mat mIntermediateMat = new Mat(height, width, CvType.CV_8UC1, new Scalar(0));
但我得到相同的异常。
But i get the same exception.
推荐答案
试试这个功能找到等高线:
Try this function to find contours :
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;
}
这篇关于在Android findContours OpenCV的抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文