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

opencv- python:如何从车牌图像裁剪白色区域?

如何解决opencv- python:如何从车牌图像裁剪白色区域?

嘿,我想从图像中裁剪出白色区域,并在屏幕上显示用白色区域书写的字符。这是我的代码

import cv2
from PyTesseract import PyTesseract
import imutils
# Read input image
img = cv2.imread(r'111.jpg')
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
s = hsv[:,:,2]#saturation
cv2.imshow("HSV Image",hsv)#hsv
cv2.waitKey(0)
cv2.imshow("Saturated Image",s)
cv2.waitKey(0)
ret,thresh = cv2.threshold(s,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) #threshold
cv2.imshow("threshold Image",thresh)
cv2.waitKey(0)
cnts = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)#contors find
cnts = imutils.grab_contours(cnts)
# print(cnts)
c = max(cnts,key=cv2.contourArea)
cv2.drawContours(img,cnts,-1,(255,0),2)
x,y,w,h = cv2.boundingRect(c)
out = img[y:y+h,x:x+w,:].copy()
# print(out) 
cv2.imshow('crop',out)
cv2.imwrite('tryv.jpg',out)
PyTesseract.tesseract_cmd = r'C:\Users\HP\AppData\Local\Tesseract-OCR\tesseract.exe'
from PIL import Image as i
config = ('-l eng --oem 3 --psm 11')
print(PyTesseract.image_to_string('tryv.jpg',config = config))
cv2.waitKey(0)

这是图片 ImageOfNumberPlate

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