Page 957 - 3-3
P. 957
roFlag=True
# 어느 방향으로 각도를 계산할지 정하는 플래그
dx=plateList[0][0]-plateList[3][0]
#x 증가량
dy=abs(plateList[0][1]-plateList[3][1])
#y 증가량
if plateList[0][1]<plateList[3][1]:roFlag=False
#y 축을 비교하여 어느 방향으로 각도를 구할지 계산
inCl=dy/dx
# 기울기를 계산한다
atan=math.atan(inCl)
# 아크 탄젠트를 이용하여 각도를 구한다
atan=math.degrees(atan)
# 단위를 'radian' 으로 바꾼다
M=None
# 기울여야하는 각도를 저장하기위한 변수
if roFlag:
center=(plateList[0][0],plateList[0][1])
# 센터를 지정
M=cv2.getRotationMatrix2D(center,atan,1)
# 다음 방향으로 atan 만큼 기울인다
else:
center=(plateList[3][0],plateList[3][0])
# 센터를 지정
M=cv2.getRotationMatrix2D(center,-atan,1)
# 다음 방향으로 – atan 만큼 기울인다
num_rows,num_cols=image.shape[:2]
#image 의 0 번과 1 번을 각각 저장한다
dst=cv2.warpAffine(ori2,M,(num_cols,num_rows))
# 최종적으로 각도를 조정
startPos=()
# 최종적인 번호판 부분의 왼쪽 위 좌표
endPos=()
# 최종적인 번호판 부분의 오른쪽 아래 좌표
#y 좌표에 따라서 변경
if plateList[0][1] < plateList[3][1]:
startPos=(int(round(plateList[0][0]+
plateList[0][2]*2.2)),int(round(plateList[0][1]-plateList[0][3]*0.5)))
endPos=(int(round(-plateList[0][0]-plateList[0][2]+plateList[3][0]*1.99))
,int(round(plateList[3][1]+plateList[3][3]*1.5)))
else:
startPos=(int(round(plateList[0][0]+plateList[0][2]*2.2)),
- 957 -