I am creating a python program that can analyze an image of a circuit board and identify parts of the image that have a label on them:
The green text under the labels is what the program is attempting to read from the label. Obviously, it is incorrect due to the label being upside-down or askew. The text is being read by passing the segmented image into pytesseract.image_to_string. In order to help the program rotate the image, I added a black border to the label:
My question is, how can I align the segmented image so that the rectangle is oriented correctly? Is this even the right way to go about it? Or would a fiducial work better? I am open to any suggestions that can help me achieve my goal of reading text off these labels. Thank you!
If you know where the corners of the rectangle are, you can use
math.atan2()to get the angle you need to rotate the image, eg:If you know the angle, there's a lot of libraries that can rotate the image for you, like Pillow or OpenCV.