Commit f7667438 authored by klorydryk's avatar klorydryk
Browse files

multiple camera working

parent e126d1b0
......@@ -75,8 +75,10 @@ def list_available_cameras():
class facetracker:
def __init__(self, camera_nb):
self.camera_number = camera_nb
# def __init__(self, camera_nb, videoName):
# self.camera_number = camera_nb
# self.videoName = videoName
# cv2.namedWindow(self.videoName)
#We are not doing really face recognition
def doRecognizePerson(self, faceNames, fid):
......@@ -623,31 +625,57 @@ class facetracker:
return color
def test_display_cam(self):
video_capture = cv2.VideoCapture(self.camera_number)
videoName = "cam" + str(self.camera_number)
def __init__(self, src, videoName):
self.videoName = videoName
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
self.capture = cv2.VideoCapture(src)
# Start the thread to read frames from the video stream
self.thread_capture = Thread(target=self.update, args=())
self.thread_capture.daemon = True
self.thread_capture.start()
if (ret):
# Display the resulting frame
cv2.imshow(videoName, frame)
# self.thread_show = Thread(target=self.show_frame, args=())
# self.thread_show.daemon = True
# self.thread_show.start()
if cv2.waitKey(1) & 0xFF == ord('q'):
break
def update(self):
# Read the next frame from the stream in a different thread
while True:
if self.capture.isOpened():
(self.status, self.frame) = self.capture.read()
time.sleep(.01)
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
def show_frame(self):
if self.frame is not None:
# Display frames in main program
cv2.imshow(self.videoName, self.frame)
key = cv2.waitKey(1)
if key == ord('q'):
self.capture.release()
cv2.destroyAllWindows()
exit(1)
if __name__ == '__main__':
cameraList = []
for camera_id in list_available_cameras():
camera = facetracker(camera_id)
thread = Thread(target=camera.test_display_cam)
thread.start()
videoName = "cam" + str(camera_id)
cameraList.append(facetracker(camera_id, videoName))
while True:
try:
for camera in cameraList:
camera.show_frame()
except AttributeError:
pass
# thread = Thread(target=camera.test_display_cam, args=(cam_disp))
# cam_threads.append(thread)
# thread.deamon = True
# thread.start()
# thread = Thread( target=camera.detectAndTrackMultipleFaces, args={
# # False: Names are directly printed on screen, no new thread
# 'start_thread' : False,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment