diff --git a/app/ml/streaming.py b/app/ml/streaming.py index 02e75fa..611ae48 100644 --- a/app/ml/streaming.py +++ b/app/ml/streaming.py @@ -49,7 +49,7 @@ def clean_plate_text(text): text = ''.join(c for c in text.upper() if c in allowed_chars) if len(text) < 4: return "" - ru_pattern = r'^[А-Я][0-9]{3}[А-Я]{2}[0-9]{2,3}$|^[0-9]{3}[А-Я]{2}[0-9]{2,3}$' + ru_pattern = r'^([A-ZА-Я])\s?([0-9]{3})\s?([A-ZА-Я]{2})\s?([0-9]{2,3})$' general_pattern = r'^[A-ZА-Я0-9]{4,}$' if re.match(ru_pattern, text) or re.match(general_pattern, text): return text @@ -67,32 +67,33 @@ def paddle_ocr(frame, x1, y1, x2, y2): plate_region = frame[y1_pad:y2_pad, x1_pad:x2_pad] if plate_region.size == 0: print("❌ Пустая область номера") - return "", 0 + return "" results = ocr.ocr(plate_region, det=True, rec=True, cls=False) if not results or not results[0]: print("❌ Текст не обнаружен") - return "", 0 - texts, confidences = [], [] + return "" + + full_text = "" for line in results[0]: if line: text = line[1][0] conf = line[1][1] print(f"Найден текст: {text} (уверенность: {conf*100:.1f}%)") - cleaned_text = clean_plate_text(text) - if cleaned_text: - texts.append(cleaned_text) - confidences.append(conf) - print(f"Очищенный текст: {cleaned_text}") - else: - print("❌ Текст отклонен") - if not texts: - + full_text += " " + text # Склеиваем все куски текста через пробел + + full_text = full_text.strip() + print(f"📦 Собранный текст перед очисткой: {full_text}") + + cleaned_text = clean_plate_text(full_text) + if cleaned_text: + print(f"✅ Очищенный текст: {cleaned_text}") + return cleaned_text + else: + print("❌ Текст отклонен после объединения") return "" - best_idx = np.argmax(confidences) - best_text = texts[best_idx] - return str(best_text) + except Exception as e: print(f"❌ Ошибка OCR: {str(e)}") return ""