create a camera object for each camera in the config

This commit is contained in:
blakeblackshear 2019-03-29 21:14:24 -05:00
parent edf0cd36df
commit 5aa3775c77

View File

@ -54,12 +54,9 @@ def main():
# TODO: set length to 1.5x the number of total regions # TODO: set length to 1.5x the number of total regions
prepped_frame_queue = queue.Queue(6) prepped_frame_queue = queue.Queue(6)
cameras = {}
camera = Camera('back', CONFIG['cameras']['back'], prepped_frame_queue, client, MQTT_TOPIC_PREFIX) for name, config in CONFIG['cameras'].items():
cameras[name] = Camera(name, config, prepped_frame_queue, client, MQTT_TOPIC_PREFIX)
cameras = {
'back': camera
}
prepped_queue_processor = PreppedQueueProcessor( prepped_queue_processor = PreppedQueueProcessor(
cameras, cameras,
@ -67,29 +64,33 @@ def main():
) )
prepped_queue_processor.start() prepped_queue_processor.start()
for name, camera in cameras.items():
camera.start() camera.start()
# create a flask app that encodes frames a mjpeg on demand # create a flask app that encodes frames a mjpeg on demand
app = Flask(__name__) app = Flask(__name__)
@app.route('/best_person.jpg') @app.route('/<camera_name>/best_person.jpg')
def best_person(): def best_person(camera_name):
frame = np.zeros((720,1280,3), np.uint8) if camera.get_best_person() is None else camera.get_best_person() best_person_frame = cameras[camera_name].get_best_person()
ret, jpg = cv2.imencode('.jpg', frame) if best_person_frame is None:
best_person_frame = np.zeros((720,1280,3), np.uint8)
ret, jpg = cv2.imencode('.jpg', best_person_frame)
response = make_response(jpg.tobytes()) response = make_response(jpg.tobytes())
response.headers['Content-Type'] = 'image/jpg' response.headers['Content-Type'] = 'image/jpg'
return response return response
@app.route('/') @app.route('/<camera_name>')
def index(): def mjpeg_feed(camera_name):
# return a multipart response # return a multipart response
return Response(imagestream(), return Response(imagestream(camera_name),
mimetype='multipart/x-mixed-replace; boundary=frame') mimetype='multipart/x-mixed-replace; boundary=frame')
def imagestream():
def imagestream(camera_name):
while True: while True:
# max out at 5 FPS # max out at 5 FPS
time.sleep(0.2) time.sleep(0.2)
frame = camera.get_current_frame_with_objects() frame = cameras[camera_name].get_current_frame_with_objects()
# encode the image into a jpg # encode the image into a jpg
ret, jpg = cv2.imencode('.jpg', frame) ret, jpg = cv2.imencode('.jpg', frame)
yield (b'--frame\r\n' yield (b'--frame\r\n'