iOS实时确定名片的角落 [英] iOS Determine the corners of a Business Card in realtime

查看:226
本文介绍了iOS实时确定名片的角落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现名片检测功能,例如此应用程序(。有了它,您可以检测线条。我会敦促你检测直线,然后发现四条线彼此大致成直角,并采用最大面积的矩形。



步骤将be:


  1. 使用Sobel滤波器进行边缘检测。

  2. Hough变换找到所有直线图片。

  3. 查看所有平行线,然后查看与这些平行线对成90度的所有线,以找到可能的矩形。

  4. 选择矩形你最喜欢。这可以是按区域,也可以是与手机最佳对齐,或者您要求所有边缘都在可见的相机图像内,或其他方法。

最后:计算机视觉很难......不要指望轻松的结果。



附录



我应该注意上面的第3步非常简单,因为线条的角度只是你的霍夫空间的一个维度。因此,平行线在此维度中将具有相等的值,并且正交线将移位pi或90度。


I want to implement a business card detecting functionality like this app (https://scanbot.io). The camera should detect a business card and automatically take a picture of it (only the business card).

My idea was using BradLarson's GPUImage library, detect the corners (using the Harris corner detection algorithm), calculate the biggest rectangle with the corners obtained and crop the image contained inside the rectangle.

Here is my code:

 - (void)setupFilter {
    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];

    filter = [[GPUImageHarrisCornerDetectionFilter alloc] init];
    [(GPUImageHarrisCornerDetectionFilter *)filter setThreshold:0.01f];
    [(GPUImageHarrisCornerDetectionFilter *)filter setSensitivity:0.5f];
    [(GPUImageHarrisCornerDetectionFilter *)filter setBlurRadiusInPixels:2.0f];

    [videoCamera addTarget:filter];
    videoCamera.runBenchmark = YES;
    GPUImageView *filterview = [[GPUImageView alloc] init];
    self.view=filterview;

    GPUImageCrosshairGenerator *crosshairGenerator = [[GPUImageCrosshairGenerator alloc] init];
    crosshairGenerator.crosshairWidth = 22.0;
    [crosshairGenerator forceProcessingAtSize:CGSizeMake(480.0, 640.0)];

    [(GPUImageHarrisCornerDetectionFilter *)filter setCornersDetectedBlock:^(GLfloat* cornerArray, NSUInteger cornersDetected, CMTime frameTime) {
        [crosshairGenerator renderCrosshairsFromArray:cornerArray count:cornersDetected frameTime:frameTime];
    }];

    GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
    [blendFilter forceProcessingAtSize:CGSizeMake(480.0, 640.0)];
    GPUImageGammaFilter *gammaFilter = [[GPUImageGammaFilter alloc] init];
    [videoCamera addTarget:gammaFilter];
    [gammaFilter addTarget:blendFilter];

    [crosshairGenerator addTarget:blendFilter];
    [blendFilter addTarget:filterview];

    [videoCamera startCameraCapture];

}

The problem is I don't know how to adjust property the threshold and sensibility attributes to get the corners (now I'm getting the corners for all the objects in the image).

I also don't know how to work with this GLfloat* cornerArray.

I don't know if I am on the right way... any other ideas about how to implement this functionality or is there any existing library?

Thanks!

解决方案

Read about Hough Transform. With it, you can detect lines. I would urge you to detect straight lines and then find four lines that are approximately at a right angle to each other and take the rectangle with the biggest area.

The steps would be:

  1. Edge detection using Sobel filter.
  2. Hough transform to find all straight lines in the image.
  3. Look at all parallel lines and then all lines 90 degrees to those parallel line pairs, to find possible rectangles.
  4. Pick the rectangle you like best. This could be by area, or by being best aligned to the phone, or you require that all edges are inside the visible camera image, or some other method.

Lastly: Computer Vision is hard... don't expect easy results.

Addendum

I should note that step 3 above is very simple, because the angle the lines take are simply one dimension of your Hough space. So parallel lines will have in this dimension equal values, and orthogonal lines will be shifted by pi or 90 degrees.

这篇关于iOS实时确定名片的角落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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