การพัฒนาโปรแกรมตรวจจับตัวหนังสือในภาพ (OCR)
การพัฒนาโปรแกรมตรวจจับตัวหนังสือในภาพ (OCR) ซึ่งมีขั้นตอนดังนี้ คลิกเพื่อโหลดภาพ
👉การเปิดข้อมูล (Read Data)
import easyocr
import cv2
# Initialize the EasyOCR reader
# Specify the languages you want to detect (e.g., Thai and English)
reader = easyocr.Reader(['en','th']) # 'th' for Thai, 'en' for English
# Load the image
image_path = r'C:\Users\user\Desktop\ocr.jpg'
image = cv2.imread(image_path)
# Perform text detection
results = reader.readtext(image)
# Print the detected text
for (bbox, text, confidence) in results:
print(f"Text: {text}, Confidence: {confidence}")
# Optionally, display the image with bounding boxes
for (bbox, text, confidence) in results:
# Draw bounding box
top_left = tuple(map(int, bbox[0]))
bottom_right = tuple(map(int, bbox[2]))
cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 2)
# Put text label
cv2.putText(image, text, top_left, cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
# Show the image with bounding boxes
cv2.imshow('Detected Text', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
เมื่อรันโปรแกรมแล้วผลลัพท์ที่ได้