首页 > 解决方案 > 识别车内车辆登记的轮廓区域

问题描述

我正在尝试识别德国车辆登记的轮廓区域。我遵循了一些教程,并有了将 cv2 findContours 与 HoughLinesP 结合使用的想法。挑战在于注册是由坐在车内的人持有的。

  1. 手打破注册的轮廓
  2. 汽车有其他轮廓,例如注册,例如汽车收音机
  3. 配准超出了图像的边界。

当我根据我创建的线条裁剪图像时,我从收音机而不是注册中得到了一些东西。因为注册的线路没有连接。

如果有人能指出我正确的方向,我将不胜感激。

原图: 登记

精明: 在此处输入图像描述

带线条的图像: 用线注册

种植面积: 裁剪图像

def crop_image(dilated):
    binary = cv2.threshold(dilated, 150, 255, cv2.THRESH_BINARY)[1]
    cv2.imshow("binary", binary)

    edges = cv2.Canny(binary, 150, 84, apertureSize=3)
    cv2.imshow("canny", edges)
    dilted_lines = dilated
    lines = cv2.HoughLinesP(edges, 1, 3.14 / 180, 100, minLineLength=15, maxLineGap=500)
    for line in lines:
        l = line[0]
        cv2.line(dilted_lines, (l[0], l[1]), (l[2], l[3]),
                 (0, 255, 0), 4)

    cv2.imshow("lines", dilted_lines)

    contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    sortedCnt = sorted(contours, key=lambda x: cv2.contourArea(x))
    x, y, w, h = cv2.boundingRect(sortedCnt[-1])
    cv2.imshow("crop", dilated[y:y + h, x:x + w])

标签: pythonopencvimage-processingcomputer-visionocr

解决方案


推荐阅读