python opencv 车牌识别代码并打印
时间: 2023-10-11 18:14:32 浏览: 51
抱歉,作为AI语言模型,我无法为您提供打印代码服务。以下是Python OpenCV车牌识别的示例代码,您可以自行使用print()函数打印输出结果。
```
import cv2
import numpy as np
# 读取图片
img = cv2.imread('car.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 高斯滤波
blur = cv2.GaussianBlur(gray, (5, 5), 0)
# 边缘检测
edged = cv2.Canny(blur, 100, 200)
# 车牌识别
_, contours, _ = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
x, y, w, h = cv2.boundingRect(contour)
aspect_ratio = float(w)/h
if aspect_ratio > 2.5 and aspect_ratio < 5:
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
roi = gray[y:y+h, x:x+w]
cv2.imshow('ROI', roi)
cv2.waitKey(0)
# 显示图片
cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```