【问题标题】:cv2.error (-215:Assertion failed) reader.ptr != NULL in function cvDrawContourscv2.error (-215:Assertion failed) reader.ptr != 函数 cvDrawContours 中的 NULL
【发布时间】:2021-05-30 20:10:59
【问题描述】:

所以我正在尝试创建一个车牌检测程序,并且我一直在按照指南进行操作, (https://github.com/nicknochnack/ANPRwithPython/blob/main/ANPR%20-%20Tutorial.ipynb) 但是我目前遇到了问题。

img = cv2.imread('image4.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

bfilter = cv2.bilateralFilter(gray, 11, 17, 17) #Noise reduction
edged = cv2.Canny(bfilter, 30, 200) #Edge detection

keypoints = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(keypoints)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]

location = None
for contour in contours:
    approx = cv2.approxPolyDP(contour, 10, True)
    if len(approx) == 4:
        location = approx
        break

mask = np.zeros(gray.shape, np.uint8)
new_image = cv2.drawContours(mask, [location], 0,255, -1)
new_image = cv2.bitwise_and(img, img, mask=mask)

我也尝试将“位置”更改为 0 或 [0],但没有成功。

【问题讨论】:

    标签: python machine-learning ocr cv2


    【解决方案1】:

    找到了解决这个问题的“解决方案”,虽然它不是一个很大的解决方案。 这种情况不断发生的原因是因为我一直在测试的图像中没有任何可识别的形状,所以由于它无法设置“位置”,它也无法正确调用该函数。 希望遇到此问题的人能看到这一点并检查他们的数据。

    【讨论】:

      【解决方案2】:

      我刚刚遇到了同样的问题,实际上似乎是因为没有要识别的轮廓/形状。

      就我而言,我将 pdf(文本 pdf)的每一页提取为图像。出现此错误是因为输出图像是 1x1 白色像素图像,因此这些“图像”上确实没有轮廓/形状。 如果您遇到与我相同的问题,以下是帮助我解决此问题的链接: https://github.com/Belval/pdf2image/issues/34

      我只需要参数size= 就可以解决这个问题,如下所示:

      from pdf2image import convert_from_path
      convert_from_path("test.pdf", size=(3000,))[0].save("out.png")
      

      【讨论】:

        猜你喜欢
        • 2020-06-07
        • 2019-08-30
        • 2021-07-30
        • 2021-08-16
        • 1970-01-01
        • 2019-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多