Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 图像中车牌号的提取_Python_Opencv_Image Processing_Computer Vision_Detection - Fatal编程技术网

Python 图像中车牌号的提取

Python 图像中车牌号的提取,python,opencv,image-processing,computer-vision,detection,Python,Opencv,Image Processing,Computer Vision,Detection,我想在数据库中找到要搜索的车牌号。由于沙特板块不同,我面临这个问题 代码的结果 我目前的方法是使用边缘检测在openCV中搜索交叉点。我怎样才能找到十字架并取下下面的字符(使用容器和边缘检测) 感谢您的帮助这里有一个方法: 将图像转换为灰度和高斯模糊 获得二值图像的大津阈值 查找轮廓并从左到右对轮廓排序,以保持顺序 遍历轮廓并过滤底部的两个矩形 提取ROI和OCR 在转换为灰度和高斯模糊后,我们使用大津阈值得到二值图像。我们找到轮廓,然后使用从左到右参数对轮廓进行排序。这一步使轮廓保持

我想在数据库中找到要搜索的车牌号。由于沙特板块不同,我面临这个问题

代码的结果

我目前的方法是使用边缘检测在openCV中搜索交叉点。我怎样才能找到十字架并取下下面的字符(使用容器和边缘检测)

感谢您的帮助

这里有一个方法:

  • 将图像转换为灰度和高斯模糊
  • 获得二值图像的大津阈值
  • 查找轮廓并从左到右对轮廓排序,以保持顺序
  • 遍历轮廓并过滤底部的两个矩形
  • 提取ROI和OCR

在转换为灰度和高斯模糊后,我们使用大津阈值得到二值图像。我们找到轮廓,然后使用
从左到右
参数对轮廓进行排序。这一步使轮廓保持有序。在此,我们迭代轮廓,并使用以下三种过滤条件执行轮廓过滤:

  • 轮廓必须大于某些指定的阈值区域(
    3000
  • 宽度必须大于高度
  • 每个ROI的中心必须位于图像的下半部分。我们找到每个轮廓的中心,并将其与图像上的位置进行比较
如果一个ROI通过了这些过滤条件,我们使用numpy切片提取ROI,然后将其放入PyteSeract。以下是检测到的通过过滤器的ROI,以绿色突出显示

因为我们已经有了边界框,所以我们提取每个ROI

我们将每个单独的ROI逐个放入PyteSeract中,以构建我们的车牌字符串。这是结果

License plate: 430SRU
代码


你想检测到“430SRU”?是的,我想要。谢谢你的帮助,它能在rassbrry pi4中使用吗?是的,你可以,只要你安装所需的库。只有当我通过一个图版图像时,它才能工作。但是当我经过汽车图像时。它无法检测。是的,此代码基于您输入的车牌图像的假设。如果你给它一个普通的汽车图像,它应该不起作用。你需要提取投资回报率的地方,然后你可以使用这个代码我怎么可以这样做?
License plate: 430SRU
import cv2
import pytesseract
from imutils import contours

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

image = cv2.imread('1.png')
height, width, _ = image.shape
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5,5), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
cnts, _ = contours.sort_contours(cnts, method="left-to-right")

plate = ""
for c in cnts:
    area = cv2.contourArea(c)
    x,y,w,h = cv2.boundingRect(c)
    center_y = y + h/2
    if area > 3000 and (w > h) and center_y > height/2:
        ROI = image[y:y+h, x:x+w]
        data = pytesseract.image_to_string(ROI, lang='eng', config='--psm 6')
        plate += data

print('License plate:', plate)