我正在开发一个应用程序,我必须从相机拍照,然后在图片中检测边缘广场(如文档页面 . )...经过长时间的搜索,我发现OpenCV库实现这一点,我已成功导入用于android的java库,但问题是当我调用opencv的方法来检测Square时(该方法是
Imgproc.findContours(converted, contours,hierarchy,Imgproc.CHAIN_APPROX_SIMPLE,Imgproc.RETR_LIST) )..它给了我
异常... OpenCV Error: _CvContourScanner * cvStartFindContours(void *,CvMemStorage *,int,int,int,CvPoint),file / home / reports / ci / slave /中不支持的格式或格式组合(FindContours仅支持8uC1和32sC1图像) 50-SDK / opencv / modules / imgproc / src / contours.cpp,第196行
我发给你一些代码------------------------------------------ -----------
public void convertImage(){
Mat ori = new Mat();
Mat converted = new Mat(200, 200, CvType.CV_8UC1, new Scalar(0));
try {
ori = Utils.loadResource(MainActivity.this, R.drawable.ic_launcher, Highgui.CV_LOAD_IMAGE_COLOR);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Imgproc.cvtColor(ori, converted, Imgproc.COLOR_RGB2GRAY, 4); // convert Image to grayscale
Imgproc.threshold(ori, converted, 50, 250, Imgproc.ADAPTIVE_THRESH_MEAN_C); // threshold the image
List<MatOfPoint> contours = new ArrayList<MatOfPoint>(10);
Mat hierarchy = new Mat(200, 200, CvType.CV_32FC1, new Scalar(0));
Imgproc.findContours(converted, contours, hierarchy,Imgproc.CHAIN_APPROX_SIMPLE,Imgproc.RETR_LIST);
ImageView frame = (ImageView) findViewById(R.id.imageView1);
Imgproc.cvtColor(converted, converted, Imgproc.COLOR_GRAY2RGBA, 4); // convert Image back to RGB
Bitmap bmp = Bitmap.createBitmap(converted.cols(), converted.rows(), Bitmap.Config.ARGB_8888);
frame.setImageBitmap(bmp);
}
任何帮助都会被贬低------------------提前致谢
3 回答
在'cvFindCounters'中第一个参数是输入图像;此图像应为8位单通道图像,并将被解释为二进制 . 因此,您应该传递单个通道图像,而不是传递4通道图像 .
这对你有用 .
Imgproc.cvtColor(ori,转换后,Imgproc.COLOR_RGB2GRAY, 1 );
尝试使用
代替
因为你需要使用1个 Channels .
首先加载位图为 -
然后将位图转换为Mat -
执行你的阈值和findcontours如上所述..基本的想法是将Bitmap转换为Mat,这是单通道..