Gibt es eine Möglichkeit, die Bildorientierung zu erkennen und das Bild im rechten Winkel zu drehen?Python

Python-Programme
Anonymous
 Gibt es eine Möglichkeit, die Bildorientierung zu erkennen und das Bild im rechten Winkel zu drehen?

Post by Anonymous »

Ich erstelle ein Skript, das gescannte Dokumente repariert, und ich brauche jetzt eine Möglichkeit, die Bildorientierung zu erkennen und das Bild zu drehen, damit seine Drehung korrekt ist. < /p>

Im Moment suche ich nach einer Zeile und es rotiert die erste Zeile, die es richtig sieht, aber dies funktioniert kaum mit Ausnahme einiger Bilder < /p>

Code: Select all

img_before = cv2.imread('rotated_377.jpg')

img_gray = cv2.cvtColor(img_before, cv2.COLOR_BGR2GRAY)
img_edges = cv2.Canny(img_gray, 100, 100, apertureSize=3)
lines = cv2.HoughLinesP(img_edges, 1, math.pi / 180.0, 100, minLineLength=100, maxLineGap=5)

angles = []

for x1,y1,x2,y2 in lines[0]:
angle = math.degrees(math.atan2(y2 - y1, x2 - x1))
angles.append(angle)

median_angle = np.median(angles)
img_rotated = ndimage.rotate(img_before, median_angle)

print("Angle is {}".format(median_angle))
cv2.imwrite('rotated.jpg', img_rotated)
I want to make a script that gets an image like this one(don't mind the image its for testing purposes)
Image

and rotates it in the right way so I get a correctly Orientiertes Bild.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post