Main code Reference 79589506
Github:https://github.com/yinghualuowu
The reply has passed, the completion ~
With an affine transformation.
defImg_transform (car_contours,oldimg,pic_width,pic_hight): Car_imgs= [] forCar_rectinchcar_contours:ifCAR_RECT[2] >-1 andCAR_RECT[2] < 1: Angle= 1#For an angle of 1 1, the default is 1 Else: Angle= Car_rect[2] Car_rect= (Car_rect[0], (Car_rect[1][0] + 5, car_rect[1][1] + 5), angle) box=cv2.boxpoints (car_rect) Heigth_point= Right_point =[0, 0] left_point= Low_point =[Pic_width, Pic_hight] forPointinchBox:ifLeft_point[0] >point[0]: Left_point= PointifLOW_POINT[1] > Point[1]: Low_point= PointifHEIGTH_POINT[1] < point[1]: Heigth_point= PointifRight_point[0] <point[0]: Right_point= PointifLEFT_POINT[1] <= right_point[1]:#Positive AngleNew_right_point = [Right_point[0], heigth_point[1]] Pts2= Np.float32 ([Left_point, Heigth_point, New_right_point])#characters are only highly needed to changePts1 =Np.float32 ([Left_point, Heigth_point, Right_point]) M=Cv2.getaffinetransform (Pts1, pts2) DST=cv2.warpaffine (Oldimg, M, (Pic_width, Pic_hight)) Point_limit (New_right_point) point_limit (Heig Th_point) Point_limit (left_point) car_img= Dst[int (left_point[1]): Int (heigth_point[1]), int (left_point[0]): Int (new_right_point[0]) car_imgs.append (car_img)elifLEFT_POINT[1] > Right_point[1]:#Negative AngleNew_left_point = [Left_point[0], heigth_point[1]] Pts2= Np.float32 ([New_left_point, Heigth_point, Right_point])#characters are only highly needed to changePts1 =Np.float32 ([Left_point, Heigth_point, Right_point]) M=Cv2.getaffinetransform (Pts1, pts2) DST=cv2.warpaffine (Oldimg, M, (Pic_width, Pic_hight)) Point_limit (Right_point) point_limit (heigth_p oint) Point_limit (new_left_point) car_img= Dst[int (right_point[1]): Int (heigth_point[1]), int (new_left_point[0]): Int (right_point[0]) car_imgs.append (car_img)returnCar_imgs
Graduation Design python OPENCV realization of plate recognition rectangle correction