Это изображение отлично показывает ожидаемый результат. Как вы можете видеть, текст на изображении выпрямлен.
Я написал python, используя openCV. Он повернул изображение, но не текст. Я использовал разные методы. Пожалуйста, предоставьте объяснение с кодом, поскольку я новичок в openCV.
import numpy as np
import cv2
import math
from scipy import ndimage
img = cv2.imread(r'curved.jpg');
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
points=[]
i=0
for contour in contours:
area = cv2.contourArea(contour)
if area > 1 and area < 800:
x,y,w,h = cv2.boundingRect(contour)
cv2.rectangle(thresh,(x,y),(x+w,y+h),(0,255,0),2)
center = (int(x),int(y))
position = (center[0], center[1])
points.append(position)
text_color = (255,0,255)
cv2.putText(thresh,str(i+1), position, cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 2)
i=i+1
pnts = np.array(points)
rect = cv2.minAreaRect(pnts)
box = cv2.boxPoints(rect)
box = np.int0(box)
cv2.drawContours(thresh,[box],0,(0,255,0),2)
(h, w) = img.shape[:2]
root_mat = cv2.getRotationMatrix2D(rect[0], 0 , 1)
rotated = cv2.warpAffine(img, root_mat,(w,h), flags=cv2.INTER_CUBIC)
cv2.getRectSubPix(rotated, (w,h), center)
cv2.imwrite( r'rotated.jpg',rotated);