# Help consistently rotating a meter image from any angle

Hello, I am a novice at image processing and I just started taking my first jabs at opencv and ocr.

I'm trying to develop an ocr that can automatically read the digits of a meter and store that information. Through testing and research, I have the ocr part down assuming I have the digits cropped out and horizontal. But I am struggling with the image processing stage of getting the source image prepared enough so that I can feed my ocr digits that it can read.

My meter images can come into the program at any angle. Additionally, they are not always the same image of a meter so I cannot predict the pixel coordinates of where features might be because there is a chance the meter will be shifted to the side and or at another completely different angle.

Right now, I am using adaptivethreshold, canny, erode, dilate and houghlinesp. I am trying to get the long lines of the meter face and rotate it based on those lines so that the image will be rotated on the horizontal plane and the digits will be readable. For meter images that are angled too far away from what I expect, this works fine and I am able to rotate so those lines are horizontal along the x-axis, but as soon as meters appear angled beyond that I struggle to find the valuable horizontal lines that I need. I need this to work for all cases because no meter comes angled in any direction more than another.

I cannot make any physical changes to the meters or cameras, so I can't use template matching or object detection to rotate based on that. I'm stuck with what I have, but I do have an immense library of meter images to play with.

I have attached images to illustrate my issues.

ok example:

problem example:

edit retag close merge delete

There are two things to play around with values of threshold and houghlineP. Btw, I'm using OpenCV 4.0.1/linux/raspberry pi 3B/+