0

I am trying to correct the distortion inside license plates such as:

Distorted license plates

However, I can't find a robust way to detect the rotation angle. I was trying to use eigenvalues as here but it fails.

I was also thinking about Hough lines detection but results remain poor.

What can I do to improve the rotation detection?

guhur
  • 2,500
  • 1
  • 23
  • 33

1 Answers1

1

Find plate contour and then find the angle of the plate by 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))
Ha Bom
  • 2,787
  • 3
  • 15
  • 29