我是 python 新手。我正在编写一个将相机输入转换为二进制形式的程序。它显示有 4 秒的延迟。我正在设计手势识别。所以这个 4 秒的延迟是不可接受的。谁能帮我 ?
import numpy as np
import cv2,cv
from PIL import Image
from scipy.misc import imsave
import numpy
def binarize_image(image, threshold):
"""Binarize an image."""
image = numpy.array(image)
image = binarize_array(image, threshold)
return image
def binarize_array(numpy_array, threshold):
"""Binarize a numpy array."""
for i in range(len(numpy_array)):
for j in range(len(numpy_array[0])):
if numpy_array[i][j] > threshold:
numpy_array[i][j] = 255
else:
numpy_array[i][j] = 0
return numpy_array
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
im_bw=binarize_image(gray, 50)
cv2.imshow('frame',im_bw)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()