-1
저는 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()
. 이 같은 상황에 도달 할 수있는 첫 번째 도구 중 하나 여야합니다. – Carcigenicate
이미지의 크기가 얼마나 큽니까? 내 생각에 binarize_arry 함수는 매우 비효율적이다. 왜냐하면 일반 Python 중첩 루프에서 numpy 배열의 모든 값을 개별적으로 처리하기 때문이다. numpy를 다룰 때 그것은 no-no입니다. 한번에 전체 배열을 조작하는 numpy 특정 연산을 연구하십시오. –
1280 * 720 –