Android的OpenCV中找到最大的正方形或长方形正方形、长方形、中找到、最大

2023-09-03 21:34:04 作者:我丑,别理我i

这可能已经回答了,但我迫切需要一个这样的答案。我想找到在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,你需要减少噪音与gaussian模糊和find所有轮廓

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

2 - 找到并列出所有的contours'地区的。

2- find and list all the contours' areas.

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

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

4-现在使用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)