Đang tải dữ liệu...
Đang tải dữ liệu...
“Chào dev! Hôm nay đã nạp code cho ESP32 chưa? 🚀”
Tóm tắt dự án:
Thuật toán xử lý ảnh nhận diện vùng biển số xe máy, cân chỉnh góc nghiêng và trích xuất ký tự chữ số bằng Tesseract OCR siêu chuẩn xác.import cv2import numpy as npimport pytesseract # Cấu hình đường dẫn Tesseract nếu cần# pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/tesseract' def detect_plate(image_path): img = cv2.imread(image_path) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Khử nhiễu và làm mịn blurred = cv2.bilateralFilter(gray, 11, 17, 17) # Tìm cạnh Canny edged = cv2.Canny(blurred, 30, 200) # Tìm Contours contours, _ = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10] plate_contour = None for c in contours: perimeter = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.018 * perimeter, True) if len(approx) == 4: plate_contour = approx break if plate_contour is None: print("Không tìm thấy biển số xe") return None x, y, w, h = cv2.boundingRect(plate_contour) roi = gray[y:y+h, x:x+w] # Nhị phân hóa Otsu _, thresh = cv2.threshold(roi, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) # Đọc ký tự OCR text = pytesseract.image_to_string(thresh, config='--psm 8 -c tessedit_char_whitelist=0123456789ABCDEFGHKLMNPSTUVXYZ-') print("Biển số nhận diện:", text.strip()) return text.strip() if __name__ == '__main__': detect_plate('test_bike.jpg')@haile_iot
Kỹ sư IoT, Embedded Developer và Web Full-Stack. Đam mê ESP32, Arduino và AI Automation.