代码实现
import cv2 as cv
s = 'ssdfsdf!@#$%^&*()_+96[[]sa:/.?['
l = len(s)
# video = cv.VideoCapture('test.mp4') # 摄像头
video = cv.VideoCapture(0) # 摄像头
# frame = cv.imread('1234.jpg')
# print(frame.shape)
# 灰度处理
while 1:
ret, frame = video.read()
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
cv.imshow('gray',gray)
gray = cv.resize(gray,(100,40))
text = ''
for hang in gray:
for lie in hang:
index = int((lie/256) * l)
text += s[index]
text += '\n'
import os
os.system('cls')
print(text)
# for hang in frame:
# for lie in hang:
# print(lie)
# cv.imshow('source',frame)
key = cv.waitKey(10) # 关闭等待时间
if key == 27: # esc
break
cv.destroyAllWindows() # 关掉所有窗口