问题描述
嘿,我想从图像中裁剪出白色区域,并在屏幕上显示用白色区域书写的字符。这是我的代码
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)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)