Подробности о приспособлении
В этом приспособлении 5 вращается правильно, тогда как приспособление 6 не вращается должным образом и находится в вертикальном положении. Пожалуйста, помогите
def deskew2(image):
coords = np.column_stack(np.where(image > 0))
print(coords[:,(1,0)])
angle = cv2.minAreaRect(coords[:,(1,0)])[-1]
if angle < -45:
angle = -(90 + angle)
else:
angle = -angle
print(angle)
(h, w) = image.shape[:2]
center = (w // 2, h // 2) # Adjust the center to the middle of the image
M = cv2.getRotationMatrix2D(center, angle, 1.0)
# Calculate the new bounding dimensions of the image
cos = np.abs(M[0, 0])
sin = np.abs(M[0, 1])
new_w = int((h * sin) + (w * cos))
new_h = int((h * cos) + (w * sin))
# Adjust the rotation matrix to take into account translation
M[0, 2] += (new_w / 2) - center[0]
M[1, 2] += (new_h / 2) - center[1]
rotated = cv2.=arpAffine(image, M, (new_w, new_h), flags=cv2.INTER_CUBIC,
borderMode=cv2.BORDER_REPLICATE)
return rotated
Подробнее здесь: https://stackoverflow.com/questions/788 ... n-it-to-co