多线程人脸识别python
我正在尝试使用python中的两个线程来解决人脸识别任务。第一个线程用于捕获帧并将其附加到deque中,第二个线程用于从deque中读取帧以解决人脸识别任务,deque是一个全局变量。当我启动两个线程时,结果如下所示。 . 在第二个线程中,进程函数不执行 这是我的密码。如何在第一个线程中将一个新帧附加到deque中,第二个线程检测并识别新帧中的人脸多线程人脸识别python,python,multithreading,opencv,Python,Multithreading,Opencv,我正在尝试使用python中的两个线程来解决人脸识别任务。第一个线程用于捕获帧并将其附加到deque中,第二个线程用于从deque中读取帧以解决人脸识别任务,deque是一个全局变量。当我启动两个线程时,结果如下所示。 . 在第二个线程中,进程函数不执行 这是我的密码。如何在第一个线程中将一个新帧附加到deque中,第二个线程检测并识别新帧中的人脸 import face_recognition import cv2 from threading import Thread from colle
import face_recognition
import cv2
from threading import Thread
from collections import deque
import pickle
svm = pickle.load(open('svm.pkl','rb'))
deque = deque()
def open_camera(url):
print('start camera')
#capture = cv2.VideoCapture('rtsp://'+str(url))
capture = cv2.VideoCapture(0)
while capture.isOpened():
_,frame = capture.read()
frame_resize = cv2.resize(frame,(640,480))
cv2.imshow('Video',frame_resize)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
# cvtColor
frame_resize = frame_resize[:, :, ::-1]
deque.append(frame_resize)
capture.release()
cv2.destroyAllWindows()
def spin(seconds):
time.sleep(seconds)
def process_camera():
print("start process")
global deque
if deque:
time.sleep(0.1)
print(deque[-1])
for i in deque:
process(frame=i)
else:
for i in deque:
process(frame=i)
def process(frame):
print('process')
frame = cv2.imread(frame)
face_locations = face_recognition.face_locations(frame)
face_encodings = face_recognition.face_encodings(frame,face_locations)
face_names = []
for face_encoding in face_encodings:
name = svm.predict(face_encoding.reshape(1, -1))
face_names.append(name)
print(face_names)
thread1= Thread(target=open_camera, args=(0,))
thread2 = Thread(target=process_camera, args=())
thread1.start()
thread2.start()
print('\texit main')
非常感谢你