OpenCV的机器人:复制图像,以新材料的一部分 [英] OpenCv android : Copy part of an image to new Mat
问题描述
我是新来的OpenCV,并试图通过实施学习。我需要借助我的新垫检测的轮廓,所以我可以与他们合作。
I am new to OpenCv and trying to learn by implementing. I need to draw the contours i have detected in new Mat so I can work with them.
这是我原来的形象
This is my Original image
在做一些工作,我通过查找和绘制轮廓做到了这一点后,
After doing some work I achieved this by finding and drawing contours
下面是我的code
m = Utils.loadResource(MainActivity.this, R.drawable.sheet1, Highgui.CV_LOAD_IMAGE_COLOR);
Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),Bitmap.Config.ARGB_8888);
Imgproc.cvtColor(m, m, Imgproc.COLOR_BGR2GRAY);
Imgproc.medianBlur(m, m, 3);
Imgproc.threshold(m, m, 0, 255, Imgproc.THRESH_OTSU);
Core.bitwise_not(m, m);
Imgproc.dilate(m, m, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,118)));
//Contours detection
java.util.List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(m, contours, new Mat() ,Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);
Imgproc.cvtColor(m, m, Imgproc.COLOR_GRAY2BGR);
//Contour drawing
Mat matArray = new Mat();
Imgproc.drawContours(m, contours, -1, new Scalar(153,255,204), 3);
Utils.matToBitmap(m, bm);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(bm);
现在,我要保存新Mat.How每MCQ这可以在Android中Java实现?
Now, I want to save every MCQ in new Mat.How can this be implemented in android Java?
推荐答案
您可以使用 boundingRect
有矩形轮廓。
然后,对于每个轮廓,可以使用存储在其中的点来创建新垫。您可以使用 CV :: getPerspectiveTransform
和 CV :: warpPerspective
通过点和一个空垫。
You can use boundingRect
to have rectangular contours.
Then, for each contour, you can use the Point stored in it to create the new Mat. You can use cv::getPerspectiveTransform
and cv::warpPerspective
with the points and an empty Mat.
我不知道它是如何工作在Java中,但在C ++的类似的东西。
I don't know how it works in Java, but in C++ its something similar to that.
您可以看看这个:<一href=\"http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html\" rel=\"nofollow\">http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html
希望它帮助。
这篇关于OpenCV的机器人:复制图像,以新材料的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!