关于图像:查找牌照内的旋转角度

Finding rotation angle inside a license plate

我正在尝试纠正牌照内的变形,例如:

Distorted license plates

然而,我找不到一个强有力的方法来检测旋转角度。我试着用特征值,但是失败了。

我也在考虑霍夫线检测,但结果仍然很差。

如何改进旋转检测?


找板轮廓,用cv2.minAreaRect求板的角度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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))