Ask Your Question
0

Detecting Page Corners

asked 2015-11-22 05:31:45 -0600

gvandyk gravatar image

updated 2015-11-22 09:59:20 -0600

I would like to detect the corners of the "rectangle" within the below images as marked by the "arrows". Any suggestions on how to approach this or what to use would be appreciated.

I am new to OpenCV and are trying some of the examples using canny edge detection and hough lines, but are a bit at a loss.

What I am trying to achieve is to extract the scanned pages from the images, and as such need to determine the rectangle of each page.

image description image description

The below is the 2 original images from which the images outlines was derived.

image description image description

edit retag flag offensive close merge delete

Comments

please provide an original image and explain what do you want to do.

sturkmen gravatar imagesturkmen ( 2015-11-22 07:23:46 -0600 )edit

I need to extract pages from scanned images, and are trying to determine the page boundaries .There are a lof of different pages from different books.

I added the 2 pages within the original post

gvandyk gravatar imagegvandyk ( 2015-11-22 09:54:22 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2015-11-22 13:26:38 -0600

for a starting point you can try the code below.

it finds the biggest contour and cut bounding rectangle.

you will get result images like:

image description image description

after that you can do some other improvements if you need

#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    int largest_area=0;
    int largest_contour_index=0;
    cv::Rect bounding_rect;

    Mat img=imread(argv[1],1);
    Mat thr,dst;

    cvtColor(img,thr,COLOR_BGR2GRAY); //Convert to gray
    threshold(thr, thr,125, 255,THRESH_BINARY); //Threshold the gray

    vector<vector<cv::Point> > contours; // Vector for storing contour

    findContours( thr, contours,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image

    for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
    {
        double a=contourArea( contours[i],false);  //  Find the area of contour
        if(a>largest_area)
        {
            largest_area=a;
            largest_contour_index=i;                //Store the index of largest contour
            bounding_rect=boundingRect(contours[i]); // Find the bounding rectangle for biggest contour
        }
    }

    Mat biggest_contour_rect = img( bounding_rect ).clone();
    imshow("biggest_contour_rect", biggest_contour_rect );
    waitKey(0);
    return 0;
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-11-22 05:31:45 -0600

Seen: 1,041 times

Last updated: Nov 22 '15