""" exec(open("scripts/detect_vin.py").read()) """ from paddleocr import PaddleOCR import cv2 import re ocr = PaddleOCR(lang='en', use_textline_orientation=True) def cut_vin(ocr, input_image, output_image): """ Вырезать VIN из изображения. """ image = cv2.imread(input_image) result = ocr.predict(image) processed_image = result[0]["doc_preprocessor_res"]["output_img"] vin_pattern = re.compile(r'^[A-HJ-NPR-Z0-9]{17}$') found_vin = None for text, bbox in zip(result[0]["rec_texts"], result[0]["rec_boxes"]): if vin_pattern.match(text): found_vin = text break if found_vin: x_min, y_min = bbox[0], bbox[1] x_max, y_max = bbox[2], bbox[3] vin_region = processed_image[y_min:y_max, x_min:x_max] cv2.imwrite(output_image, vin_region) return found_vin vin = cut_vin(ocr, "input/image.jpg", "output/vin.jpg") if vin: print(f"VIN найден: {vin}.") else: print("VIN не обнаружен.")