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

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)


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


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

3-The result will be as follow

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

3

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

( 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.

( 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 ?

( 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.

( 2016-11-02 12:01:12 -0500 )edit
1

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

( 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

( 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?

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

OK i will do , thanks

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

Sort by ยป oldest newest most voted

You may want to check getAffineTransform.

more

Thanks @unxnut , i will read about getAffineTransform

( 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.

( 2016-11-03 09:30:41 -0500 )edit

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 2,451 times

Last updated: Nov 02 '16