# Tilted image reconstruction

Hi,

I have attached scanned image of 500 Rs, I got extra region in green color and also image tilted at curtain angle .

At right side of my image some part has been removed or not scanned(due to tilt).

o/p expected is remove angle of tilt and i have to find exact corner points in the image .

plz plz let me know methods to solve this problem .

I have tried with finding skew angle, Hough transform but i am not find solution.

edit retag close merge delete

Sort by ยป oldest newest most voted

I think this will work and is quite simple:

1. Cut out the bill from your image (use thresholding and/or mask based on the green color)
2. Find the contour of your bill
3. Find the minAreaRect for your contour (bill)
4. Get the angle straight from the resulting RotatedRect and use it to create a rotation matrix with getRotationMatrix2D
5. Use warpAffine to rotate your image
more

Thanks for replay :)

( 2014-05-27 06:24:36 -0600 )edit

There is a common technique used in OCR software that does the following (pseudocode):

threshold the image with an automatic global method (i.e. Otsu)
foreach (angle in angleRange)
{
rotate original image by angle degrees
count the number of white pixels (background) in each row
store this number in a vector together with the associated angle
}
find the angle corresponding to the maximum value in the vector


This works because when the image is straight, in every row there is the maximum value of background pixels.

more

Hi zerog80,

Thanks for reply .

( 2014-05-21 01:26:31 -0600 )edit

@Witek, @zerog80, Hi I am beginner to opencv, I tried upto find mask.

My code goes here:

# include <iostream>

using namespace std; using namespace cv;

int main( ){ Mat src1; Mat src=imread("img.png",1); Mat thr,gray;

cvtColor(src,gray,CV_BGR2GRAY);

threshold(gray, thr, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); namedWindow( "gryimage", 1 ); imshow( "gryimage", thr);

vector< vector <point> > contours; // Vector for storing contour vector< Vec4i > hierarchy;

int largest_contour_index=0; int largest_area=0; Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image

findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, 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 } }

vector<vector<point> >hull(1); convexHull(contours[largest_contour_index], hull[0],false,true ); drawContours( mask, hull, 0, Scalar(125), -1, 8, vector<vec4i>(), 0, Point() ); namedWindow( "mask Image", 1 ); imshow( "mask Image", mask ); waitKey(0); return 0;

}

My question is how to find angle by using corner points ?

more

This mask does not agree with the first image. Start with a slightly larger area around your bill. The result should be a tilted rectangle. Then points 3, 4 and 5 should be straightforward.

( 2014-05-27 14:49:54 -0600 )edit

ok thanku :)

( 2014-05-28 01:13:16 -0600 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2014-05-20 08:08:08 -0600

Seen: 971 times

Last updated: May 27 '14