python用opencv识别车牌的完整信息并打印出来并导出至txt文本
2条回答 默认 最新
关注 这个例子还挺多的,
比如这个站内的博客,就可以:https://blog.csdn.net/weixin_45182459/article/details/125915894
或者这个:https://aitechtogether.com/python/51899.html···
你也可以参考一下下面的:
# -*- coding: UTF-8 -*- import cv2 import numpy as np # 读取图片 img = cv2.imread('car_plate.jpg') # 车牌定位 gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # 灰度处理 # 自适应阈值二值化 binary = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 7, 5) # 下面两行是用Sobel算子边缘检测 sobel = cv2.Sobel(binary, cv2.CV_8U, 1, 0, ksize = 3) cv2.imwrite('sobel.jpg', sobel) # 寻找车牌位置 contours = cv2.findContours(sobel, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) contours = contours[0] if len(contours) == 2 else contours[1] car_plate = [] for c in contours: # 用最小外接矩形框出车牌 rect = cv2.minAreaRect(c) box = np.int0(cv2.boxPoints(rect)) # 计算最小外接矩形的面积 area = int(rect[1][0] * rect[1][1]) # 筛选与车牌面积接近的外接矩形 if area > 300 and area < 700: car_plate.append(box) cv2.drawContours(img, [box], 0, (0, 255, 0), 3) # 识别车牌号 result = [] for m in car_plate: Xs = [i[0] for i in m] Ys = [i[1] for i in m] x1 = min(Xs) x2 = max(Xs) y1 = min(Ys) y2 = max(Ys) hight = y2 - y1 width = x2 - x1 crop_img = binary[y1:y1 + hight, x1:x1 + width] result_img = cv2.resize(crop_img, (136, 36)) # 将识别的车牌号保存到txt文件中 result.append(result_img) with open('result.txt', 'a') as f: f.write(result_img) f.write('\n') # 显示结果 cv2.imshow('car_plate', img) cv2.waitKey(0) cv2.destroyAllWindows()
解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 HP P2000存储 硬盘损坏两块如何更换
- ¥15 c#的richTextBox控件有更好的替代品吗
- ¥15 ntrip协议发送失败
- ¥15 关于#c语言#的问题:c语言main函数括弧里为什么有时候加void
- ¥15 如何利用R语言对语料库之间数据差异性分析
- ¥20 如何制作支付宝扫码跳转到发红包
- ¥15 STM32F103C8T6使用标准库stm32f10x.h驱动ws2812
- ¥20 我是数控机床电气工程师,主要是做840DSL与one,请问如何自学
- ¥20 显示器休眠后重新唤醒出现蓝屏,蓝屏代码为DRIVER-POWER.STATE-FAILURE
- ¥20 alt+tab怎么恢复到以前的模式