Ask Your Question

How to detect rotation angle 0 , -90 ,+90 or 180

asked 2016-11-01 14:10:39 -0500

essamzaky gravatar image

updated 2016-11-02 11:32:57 -0500

I would like to detect the rotation angle of scanned ID card here there are the sample images

[C:\fakepath\+90 Degree.jpg](/upfiles/147810224236179.jpg)

C:\fakepath\0 Degree.jpg C:\fakepath-90 Degree.jpg C:\fakepath\180 Degree.jpg

The first method Use Template matching , the idea is as follow

 1-Select the Template object which is the area not changed in the card  printing  i used the following area to be a template, it's the card logo

image description

2-Use the following tutorial Features2D + Homography to find a known object

3-The result will be as follow image description

The drawbacks of the method are

1-Detection for one type of ID's and i have a lot of card types.
2-it seems this method is slow

Thanks for help any idea is appreciated to find Generic method for different ID cards

edit retag flag offensive close merge delete



It took me 5 seconds to come up with around four ideas and you really have none? Where is your own work?

FooBar gravatar imageFooBar ( 2016-11-01 14:42:02 -0500 )edit

If you are only interested to the angles (-90, +90, 180), an ID card is pretty standardized so you should be able to use for example the photo location with respect to ID card for your task.

Or you can use features matching, estimate the affine transformation and extract the rotation angle.

Eduardo gravatar imageEduardo ( 2016-11-02 11:45:07 -0500 )edit

Thanks @FooBar i had added one method to solve the problem, i'm working on finding other methods such as

1-Detect face orientation
2-Use connected components and find contour to find Text Lines  , use baselines and horizontal Histograms to correct the 180 if exist.
3-Use Hough Transform to find lines of card area , you can use the previouse tip to correct 180 angle
4-The implemented one in the question.

These these are the four methods come in my mind , do you have another ideas ?

essamzaky gravatar imageessamzaky ( 2016-11-02 11:50:42 -0500 )edit

Thanks @Eduarado the cards are only standard in size only , the image location and the text data inside are changing from type to type so how to use affine transformation to detect the angle.

essamzaky gravatar imageessamzaky ( 2016-11-02 12:01:12 -0500 )edit

Hey! These are possible approaches, have you also thought about template matching without features: cv::matchTemplate I also thought about detecting (or reading the barcode. e.g. using zbar). OpenCV has also some OCR capabilities: OCRTesseract

FooBar gravatar imageFooBar ( 2016-11-02 12:13:54 -0500 )edit

@FooBar , matchTemplate very time consuming , i have nearly 40 card type so i must prepare 4 templates for every type(0.-90,+90,180), finally i will have 4*40 = 160 template , if i have new scanned card i will do 160 matchtemplate to detect the orintation , it's very expensive in time , regarding the bardcode it's a good idea but it will not succeed in the cards which does not have bardcode . i will check if tesseract contain automatic rotation correction for ID , tesseract use library called leptonica to do image processing

essamzaky gravatar imageessamzaky ( 2016-11-02 12:36:30 -0500 )edit

If you have additional requirements (e.g. cards without barcode) it would be helpful to integrate this information into the question. How do you expect someone to guess this?

FooBar gravatar imageFooBar ( 2016-11-02 12:44:56 -0500 )edit

OK i will do , thanks

essamzaky gravatar imageessamzaky ( 2016-11-02 13:04:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-11-01 21:18:13 -0500

unxnut gravatar image

You may want to check getAffineTransform.

edit flag offensive delete link more


Thanks @unxnut , i will read about getAffineTransform

essamzaky gravatar imageessamzaky ( 2016-11-03 07:15:13 -0500 )edit

HI @unxnut i read about getAffineTranseform but i'm not able to detect the rotation angle using this function , the function need 3 point in Image1 and their equivalent in Image2 , if i know these point in Image2 i can find the angle without this function.

essamzaky gravatar imageessamzaky ( 2016-11-03 09:30:41 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-11-01 14:10:39 -0500

Seen: 2,451 times

Last updated: Nov 02 '16