Ask Your Question
2

How to detect page corners using openCV

asked 2013-04-24 05:50:59 -0600

iOSDev gravatar image

updated 2013-04-24 05:52:16 -0600

I tried below code:

    IplImage* eig_image = 0;
    IplImage* temp_image = 0;

    // Create grayscale IplImage from UIImage
    IplImage *img_color = [self CreateIplImageFromUIImage:imageView.image];
    IplImage *img1 = cvCreateImage(cvGetSize(img_color), IPL_DEPTH_8U, 1);
    cvCvtColor(img_color, img1, CV_BGR2GRAY);
    cvReleaseImage(&img_color);

    if(img1==0) {
        printf("oh no!");
    }

    eig_image = cvCreateImage(cvGetSize(img1),IPL_DEPTH_32F, 1);
    temp_image = cvCreateImage(cvGetSize(img1),IPL_DEPTH_32F, 1);

    const int MAX_CORNERS = 100;
    CvPoint2D32f corners[MAX_CORNERS];
    int corner_count = MAX_CORNERS;
    double quality_level = 0.1;
    double min_distance = 1;
    int eig_block_size = 3;
    int use_harris = true;
    double k  = .4;

    cvGoodFeaturesToTrack(img1, eig_image, temp_image,corners,&corner_count,quality_level,min_distance,NULL,eig_block_size,use_harris,k);

    NSLog(@"corners %d",corner_count);

But got result : corners = 0

Can anyone help me with this issue.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2013-04-24 05:57:12 -0600

zerog80 gravatar image

updated 2013-04-24 05:58:24 -0600

I think a better and more robust way to find page corners is applying a Hough Line Transform, look for lines of sufficient length and compute intersections between each pair of them.

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html

edit flag offensive delete link more

Comments

Hi zerog80, Thank you for your answer. Actually i am new to OpenCV. I don't have any idea how to call Hough Line Transform function. Will you give me some sample code which will help me to detect corners or lines of page.

iOSDev gravatar imageiOSDev ( 2013-04-24 06:33:02 -0600 )edit
0

answered 2013-04-24 07:31:52 -0600

zerog80 gravatar image

Hi, it is not so difficult, the basic steps are the following:

  1. Convert image to grayscale (cvtColor function).
  2. Apply an edge detector (Canny or Sobel, for example) to obtain a binary image (0 on the background, 1 on edges).
  3. Run the Probabilistic Hough Line Transform (better suited for finding few long lines) with the HoughLinesP function to obtain a vector of lines (you have to tweak the parameters to accomodate your scenario).
  4. Iterate through this vector to keep only lines with angles similar to 0° or 90° (supposing your page is almost perpendicular to axes).
  5. For each pair of lines with perpendicular angles, find the intersection point (here is better to solve the equivalent system of line equations for more robustness).
  6. You have a bunch of points for each of the four page corners, you must run a distance threshold filtering to merge them to obtain at most 4 of them.

Two excellent tutorials for the first three steps are part of the OpenCV documentation and you can find here and here.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-24 05:50:59 -0600

Seen: 2,381 times

Last updated: Apr 24 '13