Android的OpenCV中找到最大的正方形或长方形 [英] Android OpenCV Find Largest Square or Rectangle

查看:1580
本文介绍了Android的OpenCV中找到最大的正方形或长方形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能已经回答了,但我迫切需要一个这样的答案。我想找到在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;
}

我试图完成这里就是创建一个基于原始图像中发现的最大的广场新形象(返回值垫图像)。

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).

这是我希望发生的:

这也没关系,我只是得到了四点最大的广场,我想我可以把它从那里。但它会更好,如果我可以只返回裁剪后的图像。

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,你需要减少噪音与<一个href="http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=gaussianblur#gaussianblur">gaussian模糊和<一href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findcontours#findcontours">find所有轮廓

1- you need to reduce noises with gaussian blur and find all the contours

2 - 找到并列出所有的<一个href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=contourarea#contourarea">contours'地区的。

2- find and list all the contours' areas.

3的大轮廓将是什么,但画。

3- the largest contour will be nothing but the painting.

4-现在使用<一个href="http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#warpperspective">perpective改造来改变你的形状,以长方形。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆