Skip to content
Snippets Groups Projects
Commit cebe2ded authored by 한동현's avatar 한동현
Browse files

feat(ocr): Paddle OCR 기반 번호판 OCR

parent 559c58f0
No related branches found
No related tags found
No related merge requests found
......@@ -13,3 +13,6 @@ plates/
# 시스템 파일
.DS_Store
.directory
# 파이썬
venv/
\ No newline at end of file
import cv2
import re
import time
import socket
from paddleocr import PaddleOCR
paddle_ocr = PaddleOCR(lang='korean', show_log=False, use_angle_cls=False)
print("모델 로딩이 완료되었습니다.")
def ocr(img_path):
plate_img = cv2.imread(img_path)
start_time = time.time()
result = paddle_ocr.ocr(plate_img, cls=True)
if not result or not result[0]:
return "No text detected"
# 모든 텍스트를 x 좌표 기준으로 정렬하여 처리
all_words = []
for line in result:
for word_info in line:
x_coord = word_info[0][0][0]
text = word_info[1][0]
all_words.append((x_coord, text))
all_words.sort(key=lambda x: x[0])
full_text = ''.join(word[1] for word in all_words)
full_text = re.sub(r'[^0-9가-힣]', '', full_text)
process_time = time.time() - start_time
print(f"처리 시간: {process_time:.2f}")
# 번호판 형식 검증
if re.search(r'\d{2,3}[가-힣]\d{4}', full_text):
print(f"인식된 번호판: {full_text}")
return full_text
else:
return "Invalid plate format"
def start_server(host='127.0.0.1', port=3000):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((host, port))
server_socket.listen(1)
print("OCR 서버가 시작되었습니다.")
while True:
client_socket, addr = server_socket.accept()
print(f"클라이언트 연결됨: {addr}")
try:
while True:
data = client_socket.recv(1024).decode()
ocr_text = ocr(data)
client_socket.send(ocr_text.encode())
except Exception as e:
print(f"오류 발생: {e}")
finally:
print(f"클라이언트 연결 종료: {addr}")
client_socket.close()
if __name__ == "__main__":
start_server()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment