Skip to content

Commit

Permalink
add latest jpg endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Aug 8, 2020
1 parent 69f5249 commit 1f03c8c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions detect_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,28 @@ def mjpeg_feed(camera_name):
mimetype='multipart/x-mixed-replace; boundary=frame')
else:
return "Camera named {} not found".format(camera_name), 404

@app.route('/<camera_name>/latest.jpg')
def latest_frame(camera_name):
if camera_name in CONFIG['cameras']:
# max out at specified FPS
frame = object_processor.get_current_frame(camera_name)
if frame is None:
frame = np.zeros((height,int(height*16/9),3), np.uint8)

height = int(request.args.get('h', str(frame.shape[1])))
width = int(height*frame.shape[1]/frame.shape[0])

frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)

ret, jpg = cv2.imencode('.jpg', frame)
response = make_response(jpg.tobytes())
response.headers['Content-Type'] = 'image/jpg'
return response
else:
return "Camera named {} not found".format(camera_name), 404

def imagestream(camera_name, fps, height):
while True:
# max out at specified FPS
Expand Down

0 comments on commit 1f03c8c

Please sign in to comment.