IOS Real-time identification of business card angles

I want to implement a business card detection feature such as this application ( https://scanbot.io ). The camera should detect a business card and automatically take a picture (business card only).

image is delimited by the green lines

My idea was to use the BradLarson GPUImage library, determine the angles (using the Harris angle detection algorithm), calculate the largest rectangle with the obtained angles, 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 that I don’t know how to set the threshold and sensibility attribute property to get angles (now I get angles for all objects in the image).

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

I don’t know if I am right ... any other ideas on how to implement this functionality or is there an existing library?

Thanks!

+6
source share
1 answer

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

Stages:

  • Edge detection using the Sobel filter.
  • Convert Hough to find all direct images.
  • Look at all the parallel lines and then all the lines at 90 degrees for pairs of parallel lines to find possible rectangles.
  • Choose the rectangle that you like best. This may be the area or, if you are best compatible with the phone, or you want all the edges to be inside the visible image of the camera or some other method.

Finally: computer vision is difficult ... don't expect easy results.

Adding

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

+9
source

Source: https://habr.com/ru/post/977021/


All Articles