车牌号文字识别问题

Car plate number text recognition problem

提问人:syuk study 提问时间:11/14/2023 最后编辑:syuk study 更新时间:11/14/2023 访问量:24

问:

我们都知道,现在任何OCR都已经建立起来了。但我做对了。我正在尝试从汽车的车牌图像中识别文本。我做过图像处理。这是我的代码。

import cv2
import pytesseract
import os
import csv

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

def ocr_with_threshold(image):
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    threshold = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
    text = pytesseract.image_to_string(threshold)
    return text.strip()

# Folder path containing the image files
folder_path = "nombor_plat_s_resize"

# Create a CSV file to store the results
csv_file = open('results.csv', 'w', newline='')
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['Image', 'Min Threshold', 'Max Threshold', 'Extracted Text'])

# Iterate over all image files in the folder
for filename in os.listdir(folder_path):
    if filename.endswith(".png") or filename.endswith(".jpg"):
        image_path = os.path.join(folder_path, filename)

        min_threshold_successful = 1.0
        max_threshold_successful = 1.0
        successful_text = None

        image = cv2.imread(image_path)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        mser = cv2.MSER_create()
        regions, _ = mser.detectRegions(gray)

        for region in regions:
            x, y, w, h = cv2.boundingRect(region)
            roi = image[y:y+h, x:x+w]
            result = ocr_with_threshold(roi)

            if result:
                if min_threshold_successful == 1.0 and max_threshold_successful == 1.0:
                    min_threshold_successful = max_threshold_successful = result
                    successful_text = result
                else:
                    if result < min_threshold_successful:
                        min_threshold_successful = result
                    if result > max_threshold_successful:
                        max_threshold_successful = result
                    if successful_text != result:
                        successful_text = None

        # Write the results to the CSV file
        csv_writer.writerow([filename, min_threshold_successful, max_threshold_successful, successful_text])

# Close the CSV file
csv_file.close()

这是一些结果:在此处输入图像描述

有人可以帮助我理解图像吗?

我尝试在阈值和 MSER 技术的帮助下使用 pytesseract 进行文本识别。我希望它至少能得到 60% 的正确率,但 100% 不正确。这是肉眼可以看到的实际车牌号或文字。实际车牌号这是用于测试的图像。https://drive.google.com/drive/folders/1qHKQDhXy0W--AyV2YAFErSLV67xsNT9m?usp=drive_link

图像处理 文本 python-tesseract 识别 文本 分割

评论


答: 暂无答案