mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
optional android notification aspect ratio
This commit is contained in:
parent
5cf38ca4f7
commit
cc0812540c
@ -75,11 +75,11 @@ def event(id):
|
|||||||
|
|
||||||
@bp.route('/events/<id>/snapshot.jpg')
|
@bp.route('/events/<id>/snapshot.jpg')
|
||||||
def event_snapshot(id):
|
def event_snapshot(id):
|
||||||
|
format = request.args.get('format', 'ios')
|
||||||
|
thumbnail_bytes = None
|
||||||
try:
|
try:
|
||||||
event = Event.get(Event.id == id)
|
event = Event.get(Event.id == id)
|
||||||
response = make_response(base64.b64decode(event.thumbnail))
|
thumbnail_bytes = base64.b64decode(event.thumbnail)
|
||||||
response.headers['Content-Type'] = 'image/jpg'
|
|
||||||
return response
|
|
||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
# see if the object is currently being tracked
|
# see if the object is currently being tracked
|
||||||
try:
|
try:
|
||||||
@ -87,13 +87,25 @@ def event_snapshot(id):
|
|||||||
if id in camera_state.tracked_objects:
|
if id in camera_state.tracked_objects:
|
||||||
tracked_obj = camera_state.tracked_objects.get(id)
|
tracked_obj = camera_state.tracked_objects.get(id)
|
||||||
if not tracked_obj is None:
|
if not tracked_obj is None:
|
||||||
response = make_response(tracked_obj.get_jpg_bytes())
|
thumbnail_bytes = tracked_obj.get_jpg_bytes()
|
||||||
response.headers['Content-Type'] = 'image/jpg'
|
|
||||||
return response
|
|
||||||
except:
|
except:
|
||||||
return "Event not found", 404
|
return "Event not found", 404
|
||||||
|
|
||||||
|
if thumbnail_bytes is None:
|
||||||
return "Event not found", 404
|
return "Event not found", 404
|
||||||
|
|
||||||
|
# android notifications prefer a 2:1 ratio
|
||||||
|
if format == 'android':
|
||||||
|
jpg_as_np = np.frombuffer(thumbnail_bytes, dtype=np.uint8)
|
||||||
|
img = cv2.imdecode(jpg_as_np, flags=1)
|
||||||
|
thumbnail = cv2.copyMakeBorder(img, 0, 0, int(img.shape[1]*0.5), int(img.shape[1]*0.5), cv2.BORDER_CONSTANT, (0,0,0))
|
||||||
|
ret, jpg = cv2.imencode('.jpg', thumbnail)
|
||||||
|
thumbnail_bytes = jpg.tobytes()
|
||||||
|
|
||||||
|
response = make_response(thumbnail_bytes)
|
||||||
|
response.headers['Content-Type'] = 'image/jpg'
|
||||||
|
return response
|
||||||
|
|
||||||
@bp.route('/events')
|
@bp.route('/events')
|
||||||
def events():
|
def events():
|
||||||
limit = request.args.get('limit', 100)
|
limit = request.args.get('limit', 100)
|
||||||
|
Loading…
Reference in New Issue
Block a user