Ask Your Question

Tilted image reconstruction

asked 2014-05-20 08:08:08 -0500

Nagaraj gravatar image

updated 2020-11-02 11:20:58 -0500

image description


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 flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2014-05-23 04:24:11 -0500

Witek gravatar image

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
edit flag offensive delete link more


Thanks for replay :)

Nagaraj gravatar imageNagaraj ( 2014-05-27 06:24:36 -0500 )edit

answered 2014-05-20 10:35:26 -0500

zerog80 gravatar image

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.

edit flag offensive delete link more


Hi zerog80,

Thanks for reply .

Nagaraj gravatar imageNagaraj ( 2014-05-21 01:26:31 -0500 )edit

answered 2014-05-27 06:37:24 -0500

Nagaraj gravatar image

updated 2014-05-27 06:42:15 -0500

image description

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

My code goes here:

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

using namespace std; using namespace cv;

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


//adaptiveThreshold(gray,thr,255,ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY,99,7);

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 ?

edit flag offensive delete link 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.

Witek gravatar imageWitek ( 2014-05-27 14:49:54 -0500 )edit

ok thanku :)

Nagaraj gravatar imageNagaraj ( 2014-05-28 01:13:16 -0500 )edit

Question Tools

1 follower


Asked: 2014-05-20 08:08:08 -0500

Seen: 565 times

Last updated: May 27 '14