У меня есть блок кода на Python, который должен вращать документ, но не в правильном направлении. При применении поворота он вращается в неправильном направлении, и я не могу извлечь из него текст, если он непрямой >
def rotate_if_needed(image, contour):
# Get the minimum area bounding box for the contour
rect = cv2.minAreaRect(contour)
box = cv2.boxPoints(rect)
box = np.int0(box)
# Calculate the angle of rotation
angle = rect[-1]
# Adjust the angle to ensure the document is straight
if angle < -45:
angle += 90
# Expand the canvas size to prevent cutting off during rotation
(h, w) = image.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
# Calculate the new bounding dimensions after rotation
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]
# Perform the rotation
rotated = cv2.warpAffine(image, M, (new_w, new_h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
return rotated
я пытался изменить угол поворота, но результат тот же
У меня есть блок кода на Python, который должен вращать документ, но не в правильном направлении. При применении поворота он вращается в неправильном направлении, и я не могу извлечь из него текст, если он непрямой > [code]def rotate_if_needed(image, contour): # Get the minimum area bounding box for the contour rect = cv2.minAreaRect(contour) box = cv2.boxPoints(rect) box = np.int0(box)
# Calculate the angle of rotation angle = rect[-1]
# Adjust the angle to ensure the document is straight if angle < -45: angle += 90
# Expand the canvas size to prevent cutting off during rotation (h, w) = image.shape[:2] center = (w // 2, h // 2) M = cv2.getRotationMatrix2D(center, angle, 1.0)
# Calculate the new bounding dimensions after rotation 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]
# Perform the rotation rotated = cv2.warpAffine(image, M, (new_w, new_h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
return rotated [/code] я пытался изменить угол поворота, но результат тот же
В этом коде у меня есть блок кода, который автоматически поворачивает документ, если он находится в неправильном положении, поэтому сценарий обнаружения текста работает правильно, но проблема, с которой я столкнулся, заключается в том, что...
В этом коде у меня есть блок кода, который автоматически поворачивает документ, если он находится в неправильном положении, поэтому сценарий обнаружения текста работает правильно, но проблема, с которой я столкнулся, заключается в том, что...
Я пытался распечатать PDF-документ из Java с помощью PDFRenderer и ICEpdf. В обоих случаях часть текста повернулась на 180 градусов, а изображения остались правильными. В PDFREndere вращается весь текст, а в ICEpdf — только некоторые строки. Есть...
I tried to print a PDF document from Java using PDFRenderer and ICEpdf. In both cases some of the text came out rotated in 180 degrees while the images stayed correct. With PDFREndere all the text is rotated and in ICEpdf only some of the lines. Any...
Я хочу, чтобы высота и ширина холста менялись при повороте изображения и работали соответствующим образом. Наложение также должно соответствовать повернутому холсту, и обрезка должна работать соответствующим образом.