You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

import easyocr
import cv2
from matplotlib import pyplot as plt
import time # ⬅ 추가
# 1. EasyOCR Reader 생성
reader = easyocr.Reader(['ko', 'en'], gpu=False)
# 2. 이미지 불러오기
# image_path = '/home/cuuva/다운로드/test/ocr_resized.png'
image_path = '/home/cuuva/experiment/custom_LP_detect/ocr2.png'
image = cv2.imread(image_path)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# ------------------------
# 3. OCR 수행 및 시간 측정
# ------------------------
start_time = time.time()
results = reader.readtext(image_rgb, detail=1)
end_time = time.time()
print(f"Inference time: {end_time - start_time:.3f} seconds")
# 4. 결과 출력 및 시각화
for (bbox, text, prob) in results:
print(f"Detected text: {text}, Confidence: {prob:.2f}")
# 바운딩 박스
top_left = tuple(map(int, bbox[0]))
bottom_right = tuple(map(int, bbox[2]))
cv2.rectangle(image_rgb, top_left, bottom_right, (0, 255, 0), 2)
cv2.putText(image_rgb, text, (top_left[0], top_left[1]-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
# 5. 시각화
plt.figure(figsize=(10,6))
plt.imshow(image_rgb)
plt.axis('off')
plt.show()