计算机视觉知识点-车牌识别

 

今天我来实现一个简单版本的车牌识别,目的是识别上边的这张图片中的车牌。我参考的开源代码是这个github地址。我的大体方案是:

车牌检测 :我采用检测轮廓,如果有4个点就是车牌。虽然这种方法方法有些流氓做派,但是简单啊,不要嘲笑我没有使用ssd/yolo/级联分类器/纹理扫描的方法。

车牌剪切:检测到区域后,把图片剪切下来。

车牌识别:我是用tesseract进行识别。

#1.1 gray and reisize
img = cv2.resize(img, (620,480) )
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #convert to grey scale

 

 

#1.2 blur
gray = cv2.bilateralFilter(gray, 13, 15, 15)

#1.3 edeg detect
edged = cv2.Canny(gray, 30, 200) #Perform Edge detection

#1.4 get rect from contours
contours=cv2.findContours(edged.copy(),cv2.RETR_TREE,
                                            cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(contours)
contours = sorted(contours,key=cv2.contourArea, reverse = True)[:10]
screenCnt = None

for c in cnts:
    # approximate the contour
    peri = cv2.arcLength(c, True)
    approx = cv2.approxPolyDP(c, 0.018 * peri, True)
    # if our approximated contour has four points, then
    # we can assume that we have found our screen
    if len(approx) == 4:
        screenCnt = approx
        break

#1.5 show plate
# Masking the part other than the number plate
mask = np.zeros(gray.shape,np.uint8)
new_image = cv2.drawContours(mask,[screenCnt],0,255,-1,)
new_image = cv2.bitwise_and(img,img,mask=mask)

#2.1 crop
# Now crop
(x, y) = np.where(mask == 255)
(topx, topy) = (np.min(x), np.min(y))
(bottomx, bottomy) = (np.max(x), np.max(y))
Cropped = gray[topx:bottomx+1, topy:bottomy+1]

#3.1  recognise
#Read the number plate
text = pytesseract.image_to_string(Cropped, config='--psm 11')
print("Detected license plate Number is:",text)

总结:

      这种车牌识别方案不能在现实中使用,首先检测方法找轮廓在实际中是不行的,实际中可以使用对垂直边缘进行分析、yolo检测、级联分类器等方法来实现。

       tesseract对于扫描图片效果可以,但是对于实际的车牌图片效果比较差,可以采用通过模板匹配的方法进行车牌字符分割,然后调用一个小分类器进行识别,也可以直接使用lstm方法进行一行的识别。

最后的话:

我是一个工作10年的程序员,工作中经常会遇到需要查一些关键技术,但是很多技术名词的介绍都写的很繁琐,为什么没有一个简单的/5分钟能说清楚的博客呢. 我打算有空就写写这种风格的指南文档.CSDN上搜蓝色的杯子, 没事多留言,指出我写的不对的地方,写的排版风格之类的问题,让我们一起爱智求真吧.wisdomfriend@126.com是我的邮箱,也可以给我邮箱留言.

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值