# Smart Straighten Function #236

Closed
opened this Issue Oct 30, 2012 · 10 comments

Projects
None yet
4 participants
Contributor

### kscottz commented Oct 30, 2012

 Create a function that looks at the longest and strongest lines and sets them to be horizontal and vertical images. A good example would be scanning a business card at an arbitrary angle and the function would rotate it so the edges are horizontal and vertical.

Contributor

### mfkaptan commented Apr 14, 2013

 Hi, is this issue still open?

Closed

Contributor

### vighneshbirodkar commented Apr 23, 2013

 @kscottz So i tried it with around 50 images. My original idea was to get the best possible rotation to get all the lines as straight as possible. But is there are lines at many orientations it will find a compromise. I think that's why you suggested using bins. So I gave the bins idea a shot. The problem was if there are many small ( insignificant ) lines at an orientaion they will fill the bin more. Instead of incrementing the bin by 1 for each line at that angle, I am incrementing by the length of the line, so that I can get length into consideration . I then pick the biggest bin and rotate to the average of angles of the lines in that bin. The problem still persists. Too many smaller lines tend to influence the rotation. See the results here. I am drawing all the lines in the seected bins. http://imgur.com/a/zRjSN I am thinking of setting a threshold, like consider only the 'k' longest lines(taken from user).
Contributor

### vighneshbirodkar commented Apr 23, 2013

 Side by Side album http://imgur.com/a/R01vV
Contributor

### vighneshbirodkar commented Apr 27, 2013

 @kscottz I added the feature you said, the code now tries to decide how to rotate ( vertical or horizontal ). I couldn't find any literature/projects that do exactly the same thing. I found some work on rotating documents and rotating knowing the original object. Also a few regarding rotating at right angles ( 90,180,270 ). Let me know how you find this. http://imgur.com/a/fap0V Best of the lot http://imgur.com/a/fap0V#32 It couldn't rotate all, it threw warnings on the images in which both sides are identical, since it couldn't find lines.
Contributor

### vighneshbirodkar commented Apr 29, 2013

 @kscottz Canny thresholds do the trick. Here are the results , no funny business going on . Have a look and tell me if I should send a pull . http://imgur.com/a/aI4XQ
Contributor

### kscottz commented Apr 29, 2013

 @vighneshbirodkar Send me the pull request so I can see the code. Looks good to me. See simple works :). Learn your zen of python.
Contributor

### jayrambhia commented Apr 29, 2013

 Try this on titanic! :D
Contributor

### vighneshbirodkar commented Apr 29, 2013

 For god's sake , it straightened the Leaning Tower, what more do you want ? Got this with default parameters :D
Contributor

### kscottz commented Apr 29, 2013

 COMPUTER VISION WILL SAVE THE WORLD!!!
Contributor

### vighneshbirodkar commented Apr 29, 2013

 I'll send the pull after sometime, complete with unit tests and use case example

Merged