简体   繁体   English

使用opencv java检测图像中文档的边界

[英]Detect boundaries of a document in an image using opencv java

I want to detect the 4 corners of the document in android. 我想在android中检测文档的4个角。 Iam using opencv library. 我使用opencv库。

Iam using the following approach- (1) grayscale the image (2) Apply median blur (3) Apply adaptive threshold (4) Canny Edge detection (5) find contours (6) find the largest contour (7) get the edges and corners of the largest contour Iam使用以下方法 - (1)灰度图像(2)应用中值模糊(3)应用自适应阈值(4)Canny边缘检测(5)找到轮廓(6)找到最大轮廓(7)得到边缘和角点最大的轮廓

My code is 我的代码是

srcImg = Utils.loadResource(this, R.drawable.test1, Highgui.CV_LOAD_IMAGE_COLOR);
Imgproc.cvtColor(srcImg, srcImg, Imgproc.COLOR_BGR2GRAY);
Imgproc.medianBlur(srcImg, srcImg, 9);
Imgproc.adaptiveThreshold(srcImg, srcImg, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 11, 2);
Imgproc.Canny(srcImg, srcImg, 50, 80);


Imgproc.findContours(srcImg,contours , hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);

After canny edge detection, the outlining boundary at many points are broken due to which the largest contour detected in the image is not the actual boundary of the document. 在精确边缘检测之后,许多点处的轮廓边界被破坏,由此在图像中检测到的最大轮廓不是文档的实际边界。 In some images the largest contour is showing some part of the boundary but in some images it is pointing to the center of the document or completely outside the document 在某些图像中,最大轮廓显示边界的某些部分,但在某些图像中,它指向文档的中心或完全位于文档外部

(A)How do I proceed further in this condition ? (A)如何在这种情况下继续前进?

Another approach i applied was to apply houghes line transform and calculate the point of intersection of the lines which are intersecting at 90 degree angle but in that case am not getting exactpoints. 我应用的另一种方法是应用houghes线变换并计算以90度角相交的线的交点,但在这种情况下没有获得精确点。 when I put 88 当我把88

(B)How to handle that much number of points (B)如何处理那么多分

(C)or do I need to follow completely different approach ? (C)还是我需要遵循完全不同的方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM