Android OpenCV 查找最大的正方形或矩形 [英] Android OpenCV Find Largest Square or Rectangle
问题描述
这可能已经得到回答,但我迫切需要一个答案.我想在 Android 中使用 OpenCV 找到图像中最大的正方形或矩形.我找到的所有解决方案都是 C++,我尝试转换它但它不起作用,我不知道我错在哪里.
This might have been answered but I desperately need an answer for this. I want to find the largest square or rectangle in an image using OpenCV in Android. All of the solutions that I found are C++ and I tried converting it but it doesn't work and I do not know where I'm wrong.
private Mat findLargestRectangle(Mat original_image) {
Mat imgSource = original_image;
Imgproc.cvtColor(imgSource, imgSource, Imgproc.COLOR_BGR2GRAY);
Imgproc.Canny(imgSource, imgSource, 100, 100);
//I don't know what to do in here
return imgSource;
}
我在这里想要完成的是基于原始图像中找到的最大正方形(返回值 Mat 图像)创建一个新图像.
What I am trying to accomplish in here is to create a new image that is based on the largest square found in the original image (return value Mat image).
这就是我想要发生的:
1 个 http://img14.imageshack.us/img14/7855/s7zr.jpg
我只得到最大正方形的四个点也没关系,我想我可以从那里得到它.但如果我能返回裁剪后的图像会更好.
It's also okay that I just get the four points of the largest square and I think I can take it from there. But it would be better if I can just return the cropped image.
推荐答案
精明之后
1- you need to reduce noises with gaussian blur and find all the contours
2- 查找并列出所有轮廓区域.
2- find and list all the contours' areas.
3- 最大的轮廓就是画.
3- the largest contour will be nothing but the painting.
4- 现在使用透视变换将您的形状变换为矩形.
4- now use perpective transformation to transform your shape to a rectangle.
检查数独求解器示例以查看类似的处理问题.(最大轮廓+透视)
check sudoku solver examples to see the similar processing problem. (largest contour + perspective)
这篇关于Android OpenCV 查找最大的正方形或矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!