当实时摄像机检测到一些文本时,将通过函数(在我的代码中为img_process)进行处理
但是时间太长(滞后),相机似乎停止了。
我想让相机假装连续工作(保持拍摄并显示图像)
代码如下
from PIL import Image #pip install pillow
from pytesseract import * #pip install pytesseract
import pytesseract
import configparser
import os
import cv2
import numpy as np
import pandas as pd
from imutils.video import VideoStream
from imutils.video import FPS
import argparse
import imutils
import time
from concurrent.futures import ThreadPoolExecutor
config = configparser.ConfigParser()
config.read(os.path.dirname(os.path.realpath(__file__)) + os.sep + 'envs' + os.sep + 'property.ini')
if __name__ == "__main__":
data = pd.read_csv('./test6.txt', sep='\t', engine='python')
print("Part N/O Scan...")
vs = VideoStream(src=1).start()
time.sleep(2.0)
fps = FPS().start()
while True:
frame = vs.read()
frame = imutils.resize(frame, width=500)
(h, w) = frame.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)),
0.007843, (300, 300), 127.5)
#problem(delay) happen in this line
img_process(frame)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
fps.update()
fps.stop()
print("[INFO] elapsed time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
cv2.destroyAllWindows()
vs.stop()
在那种情况下,我通常要做的是从输入中跳过几帧。在while循环中添加类似的内容
while True:
for i in range(5): # you can adjust this number
frame = vs.read()
frame = imutils.resize(frame, width=500)
如果您想实时输出视频,这很好。