微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何仅绘制最大的矩形轮廓来检测车牌专门针对摩托车车牌

如何解决如何仅绘制最大的矩形轮廓来检测车牌专门针对摩托车车牌

我一直致力于仅使用 OpenCV 检测摩托车牌照。我的问题是:

  1. 我能否仅找到并绘制最大的轮廓(在车牌周围)?
  2. 如果没有,我该怎么办?
  3. 还有其他检测摩托车牌照的方法吗?

Here is my original image

And here is the image after I detect every rectangle contours

这是源代码

import cv2

image = cv2.imread('image_0002.jpg')
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray,(3,3),0)
canny = cv2.Canny(blurred,120,255,1)

# Find contours
cnts = cv2.findContours(canny,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

# Iterate thorugh contours and draw rectangles around contours
for c in cnts:
    x,y,w,h = cv2.boundingRect(c)
    cv2.rectangle(image,(x,y),(x + w,y + h),(36,12),2)

cv2.imshow('canny',canny)
cv2.imshow('image',image)
cv2.imwrite('canny.png',canny)
cv2.imwrite('image.png',image)
cv2.waitKey(0)

解决方法

1- 对于最大的矩形 - 计算所有矩形的面积

largest_area = 0
for c in cnts:
    x,y,w,h = cv2.boundingRect(c)
    area = 4*w*h
    if area > largest_area:
        largest_area = area
        largest_area_contour = c

现在,我们得到了最大的矩形。让我们绘制它(在 for loop 之外)。

x,h = cv2.boundingRect(largest_area_contour)
cv2.rectangle(image,(x,y),(x + w,y + h),(36,255,12),2)

2- 你的模型给了你太多的误报。确保最大矩形方法始终有效。

3- 车牌(汽车或自行车无关紧要)阅读是一个经过充分研究的玩具问题。你会在互联网上找到很多讨论。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。