2016-08-22 175 views
2

我正在使用Python和Opencv。我正在做一个项目来识别汽车摄像头的车牌。车牌照检测车牌摄像头

我试过使用Canny(),但我仍然无法识别板。

这是我拍摄的框架。 enter image description here

1)

首先,我将图像转换为灰度,增加颜色的合同并最终将其转换成 “一柄图像

img = cv2.imread("plate.jpg") 
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 
gray = cv2.equalizeHist(gray) 
edged = cv2.Canny(gray, 200, 255) 

这里是我得到的结果: enter image description here

2)

然后,我试图找到一个矩形轮廓如下,我试图通过convexHull()滤除由面积和长度以及不规则多边形不相干矩形

(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) 
cnts=sorted(cnts, key = cv2.contourArea, reverse = True)[:10] 

# loop over our contours 
plate_candidates = [] 
    for c in cnts: 
     peri = cv2.arcLength(c, True) 
     approx = cv2.approxPolyDP(c, 0.02 * peri, True) 
     area = cv2.contourArea(approx) 
     if len(approx) == 4 and area <=1000 and area >=500 and self._length_checking(approx): 
      hull = cv2.convexHull(approx,returnPoints = True) 
      if len(hull) ==4: 
       plate_candidates.append(approx) 
       cv2.drawContours(show, [approx], -1, (0,255,0), 3) 

但是,我仍然无法辨认板子。我正在寻找帮助,我如何检测车牌。谢谢。

回答

1

您可以使用凸包来计算你的候选轮廓的“rectangleness”的最小边界矩形(在OpenCV中的最新版本,你可以使用cv2.boxPoints计算rectPoints):在不过

def rectangleness(hull): 
    rect = cv2.boundingRect(hull) 
    rectPoints = np.array([[rect[0], rect[1]], 
          [rect[0] + rect[2], rect[1]], 
          [rect[0] + rect[2], rect[1] + rect[3]], 
          [rect[0], rect[1] + rect[3]]]) 
    intersection_area = cv2.intersectConvexConvex(np.array(rectPoints), hull)[0] 
    rect_area = cv2.contourArea(rectPoints) 
    rectangleness = intersection_area/rect_area 
    return rectangleness 

您这种情况实际上是过度的,只要使用多边形的面积就足够了 - 可以使用区域中的多边形(cnts中的前两个轮廓)来获取车牌周围的边界矩形。

+0

感谢您的回复。你的意思是我使用的限制太严格了吗?通过使用'area'和'rectangleness'就足以检测矩形? – VICTOR

+0

在你的情况下,你甚至不需要矩形,你可以使用区域 – maxymoo

+0

我以前使用过这种方法,但是,有时我会检测到一些非四边形的形状。为了过滤掉这些非四边形或不规则形状,我使用'len(hull)== 4'来确定 – VICTOR