检测纸边并裁切 [英] Detecting Paper Edge and Crop it

查看:226
本文介绍了检测纸边并裁切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#编写程序来检测纸张边缘并从图像中裁剪出纸张的方形边缘.

I am using C# to write a program to detect the paper edges and crop out the square edges of the paper from the images.

下面是我想要裁剪的图像.纸张将始终显示在页面底部.

Below is the image I wish to crop. The paper will always appear at the bottom of the pages.

我已经阅读了这些链接,但是我仍然不知道该怎么做.

I had read through these links but I still have no idea how to do it.

OpenCV C ++/Obj-C:检测一张纸/正方形检测

我正在将EMGU用于该OCR项目

I am using EMGU for this OCR project

推荐答案

您还可以:

  1. 将图像转换为灰度
  2. 通过像素强度应用ThresholdBinary
  3. 查找轮廓.
    要查看有关查找轮廓的示例,请查看示例.

  1. Convert your image to grayscale
  2. Apply ThresholdBinary by the pixel intensity
  3. Find contours.
    To see examples on finding contours you can look on this post.
    FundContours method doesn't care about the contours size. The only thing to be done here before finding contours is emphasizing them by binarizing the image (and we do this in step 2).
    For more info also look at OpenCV docs: findContours, example.

通过边界框的大小和位置找到合适的轮廓.
(在这一步中,我们遍历所有在轮廓上找到的轮廓,并尝试使用已知的纸张尺寸,比例和相对位置,找出纸张轮廓中的哪一个.-图片的左下角).

Find proper contour by the size and position of its bounding box.
(In this step we iterate over all found on contours and try to figure out, which one the contour of the paper sheet, using known paper dimensions, proportions of them and the relative positon - left bottom corner of the image ).

使用纸的边框裁剪图像.

Crop the image using bounding box of the sheet of paper.

Image<Gray, byte> grayImage = new Image<Gray, byte>(colorImage);
Image<Bgr, byte> color = new Image<Bgr, byte>(colorImage);

grayImage = grayImage.ThresholdBinary(new Gray(thresholdValue), new Gray(255));

using (MemStorage store = new MemStorage())
for (Contour<Point> contours= grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE, store); contours != null; contours = contours.HNext)
{
    Rectangle r = CvInvoke.cvBoundingRect(contours, 1);

    // filter contours by position and size of the box
}

// crop the image using found bounding box

UPD::我添加了更多详细信息.

UPD: I have added more details.

这篇关于检测纸边并裁切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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