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

feat(ocr): 차량 로그 조회 웹 API 추가

parent 4ee502a6
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,11 @@ import re ...@@ -3,6 +3,11 @@ import re
import time import time
import socket import socket
from paddleocr import PaddleOCR from paddleocr import PaddleOCR
import http.server
import json
import os
import threading
from urllib.parse import urlparse
paddle_ocr = PaddleOCR(lang='korean', show_log=False, use_angle_cls=False) paddle_ocr = PaddleOCR(lang='korean', show_log=False, use_angle_cls=False)
print("모델 로딩이 완료되었습니다.") print("모델 로딩이 완료되었습니다.")
...@@ -61,5 +66,54 @@ def start_server(host='127.0.0.1', port=3000): ...@@ -61,5 +66,54 @@ def start_server(host='127.0.0.1', port=3000):
print(f"클라이언트 연결 종료: {addr}") print(f"클라이언트 연결 종료: {addr}")
client_socket.close() client_socket.close()
def handle_http_request(handler):
path = urlparse(handler.path).path
if path == '/api/images':
send_file_list(handler, '../images')
elif path == '/api/plates':
send_file_list(handler, '../plates')
elif path.startswith('/images/') or path.startswith('/plates/'):
send_image(handler, '../' + path.lstrip('/'))
else:
handler.send_error(404, "File not found")
def send_file_list(handler, dir_path):
try:
files = [file for file in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, file))]
handler.send_response(200)
handler.send_header('Content-Type', 'application/json')
handler.send_header('Access-Control-Allow-Origin', '*')
handler.send_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
handler.end_headers()
handler.wfile.write(json.dumps(files).encode())
except Exception as e:
handler.send_error(500, str(e))
def send_image(handler, file_path):
if os.path.exists(file_path):
with open(file_path, 'rb') as f:
handler.send_response(200)
handler.send_header('Content-Type', 'image/jpeg')
handler.send_header('Access-Control-Allow-Origin', '*')
handler.send_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
handler.end_headers()
handler.wfile.write(f.read())
else:
handler.send_error(404, "File not found")
def start_http_server(port=8000):
class RequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
handle_http_request(self)
server = http.server.HTTPServer(('', port), RequestHandler)
print(f"HTTP 서버가 포트 {port}에서 시작되었습니다.")
server.serve_forever()
if __name__ == "__main__": if __name__ == "__main__":
http_thread = threading.Thread(target=start_http_server)
http_thread.daemon = True
http_thread.start()
start_server() start_server()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment