答案 0 :(得分:0)
找到板轮廓,然后通过cv2.minAreaRect
#preprocessing steps
...
#find angle
im2, contours, hierarchy = cv2.findContours(preprocessed_sloping_plate,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#contour with the largest area is possibly the plate
max_area = 0
max_cnt = None
for cnt in contours:
area = cv2.contourArea(cnt)
if(area > max_area):
max_area = area
max_cnt = cnt
min_rect = cv2.minAreaRect(max_cnt)
(x,y,w,h,angle) = min_rect
#rotate
M = cv2.getRotationMatrix2D((w/2, h/2), angle, 1.0)
rotated_plate = cv2.warpAffine(preprocessed_sloping_plate, M, (w,h))