Compare commits
3 Commits
5a87e37bb2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d3467c98c | |||
| 671c5085e9 | |||
| 644c61e9fe |
45
scripts/detect_vin.py
Normal file
45
scripts/detect_vin.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
"""
|
||||||
|
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 не обнаружен.")
|
||||||
|
|
||||||
Reference in New Issue
Block a user