python
import cv2
import pytesseract
# 이미지 로드
image = cv2.imread('car_plate.jpg')
# 그레이 스케일로 변환
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 엣지 검출
edged = cv2.Canny(gray, 30, 200)
# 윤곽선 찾기
contours, _ = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]
# 번호판 추출 시도
for contour in contours:
approx = cv2.approxPolyDP(contour, 0.018 * cv2.arcLength(contour, True), True)
if len(approx) == 4:
screenCnt = approx
break
# 관심 영역(ROI) 추출
mask = cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 3)
# OCR로 번호판 읽기
roi = mask
custom_config = r'--oem 3 --psm 6'
print(pytesseract.image_to_string(roi, config=custom_config))
# 결과 표시
cv2.imshow("Image", image)
cv2.waitKey(0)