mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
add back flask endpoints
This commit is contained in:
parent
0279121d77
commit
edf0cd36df
@ -68,61 +68,36 @@ def main():
|
|||||||
prepped_queue_processor.start()
|
prepped_queue_processor.start()
|
||||||
|
|
||||||
camera.start()
|
camera.start()
|
||||||
camera.join()
|
|
||||||
|
|
||||||
# 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('/best_person.jpg')
|
||||||
# def best_person():
|
def best_person():
|
||||||
# frame = np.zeros(frame_shape, np.uint8) if camera.get_best_person() is None else camera.get_best_person()
|
frame = np.zeros((720,1280,3), np.uint8) if camera.get_best_person() is None else camera.get_best_person()
|
||||||
# ret, jpg = cv2.imencode('.jpg', frame)
|
ret, jpg = cv2.imencode('.jpg', 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('/')
|
||||||
# def index():
|
def index():
|
||||||
# # return a multipart response
|
# return a multipart response
|
||||||
# return Response(imagestream(),
|
return Response(imagestream(),
|
||||||
# mimetype='multipart/x-mixed-replace; boundary=frame')
|
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||||
# def imagestream():
|
def imagestream():
|
||||||
# while True:
|
while True:
|
||||||
# # max out at 5 FPS
|
# max out at 5 FPS
|
||||||
# time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
# # make a copy of the current detected objects
|
frame = camera.get_current_frame_with_objects()
|
||||||
# detected_objects = DETECTED_OBJECTS.copy()
|
# encode the image into a jpg
|
||||||
# # lock and make a copy of the current frame
|
ret, jpg = cv2.imencode('.jpg', frame)
|
||||||
# with frame_lock:
|
yield (b'--frame\r\n'
|
||||||
# frame = frame_arr.copy()
|
b'Content-Type: image/jpeg\r\n\r\n' + jpg.tobytes() + b'\r\n\r\n')
|
||||||
# # convert to RGB for drawing
|
|
||||||
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
||||||
# # draw the bounding boxes on the screen
|
|
||||||
# for obj in detected_objects:
|
|
||||||
# vis_util.draw_bounding_box_on_image_array(frame,
|
|
||||||
# obj['ymin'],
|
|
||||||
# obj['xmin'],
|
|
||||||
# obj['ymax'],
|
|
||||||
# obj['xmax'],
|
|
||||||
# color='red',
|
|
||||||
# thickness=2,
|
|
||||||
# display_str_list=["{}: {}%".format(obj['name'],int(obj['score']*100))],
|
|
||||||
# use_normalized_coordinates=False)
|
|
||||||
|
|
||||||
# for region in regions:
|
app.run(host='0.0.0.0', port=WEB_PORT, debug=False)
|
||||||
# color = (255,255,255)
|
|
||||||
# cv2.rectangle(frame, (region['x_offset'], region['y_offset']),
|
|
||||||
# (region['x_offset']+region['size'], region['y_offset']+region['size']),
|
|
||||||
# color, 2)
|
|
||||||
|
|
||||||
# # convert back to BGR
|
camera.join()
|
||||||
# frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
|
||||||
# # encode the image into a jpg
|
|
||||||
# ret, jpg = cv2.imencode('.jpg', frame)
|
|
||||||
# yield (b'--frame\r\n'
|
|
||||||
# b'Content-Type: image/jpeg\r\n\r\n' + jpg.tobytes() + b'\r\n\r\n')
|
|
||||||
|
|
||||||
# app.run(host='0.0.0.0', port=WEB_PORT, debug=False)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
@ -41,7 +41,7 @@ class PreppedQueueProcessor(threading.Thread):
|
|||||||
objects = self.engine.DetectWithInputTensor(frame['frame'], threshold=0.5, top_k=3)
|
objects = self.engine.DetectWithInputTensor(frame['frame'], threshold=0.5, top_k=3)
|
||||||
# time.sleep(0.1)
|
# time.sleep(0.1)
|
||||||
# objects = []
|
# objects = []
|
||||||
print(self.engine.get_inference_time())
|
# print(self.engine.get_inference_time())
|
||||||
# put detected objects in the queue
|
# put detected objects in the queue
|
||||||
parsed_objects = []
|
parsed_objects = []
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
|
@ -5,6 +5,7 @@ import cv2
|
|||||||
import threading
|
import threading
|
||||||
import ctypes
|
import ctypes
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
|
from object_detection.utils import visualization_utils as vis_util
|
||||||
from . util import tonumpyarray
|
from . util import tonumpyarray
|
||||||
from . object_detection import FramePrepper
|
from . object_detection import FramePrepper
|
||||||
from . objects import ObjectCleaner, ObjectParser, BestPersonFrame
|
from . objects import ObjectCleaner, ObjectParser, BestPersonFrame
|
||||||
@ -215,6 +216,38 @@ class Camera:
|
|||||||
def get_best_person(self):
|
def get_best_person(self):
|
||||||
return self.best_person_frame.best_frame
|
return self.best_person_frame.best_frame
|
||||||
|
|
||||||
|
def get_current_frame_with_objects(self):
|
||||||
|
# make a copy of the current detected objects
|
||||||
|
detected_objects = self.detected_objects.copy()
|
||||||
|
# lock and make a copy of the current frame
|
||||||
|
with self.frame_lock:
|
||||||
|
frame = self.shared_frame_np.copy()
|
||||||
|
|
||||||
|
# convert to RGB for drawing
|
||||||
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||||
|
# draw the bounding boxes on the screen
|
||||||
|
for obj in detected_objects:
|
||||||
|
vis_util.draw_bounding_box_on_image_array(frame,
|
||||||
|
obj['ymin'],
|
||||||
|
obj['xmin'],
|
||||||
|
obj['ymax'],
|
||||||
|
obj['xmax'],
|
||||||
|
color='red',
|
||||||
|
thickness=2,
|
||||||
|
display_str_list=["{}: {}%".format(obj['name'],int(obj['score']*100))],
|
||||||
|
use_normalized_coordinates=False)
|
||||||
|
|
||||||
|
for region in self.regions:
|
||||||
|
color = (255,255,255)
|
||||||
|
cv2.rectangle(frame, (region['x_offset'], region['y_offset']),
|
||||||
|
(region['x_offset']+region['size'], region['y_offset']+region['size']),
|
||||||
|
color, 2)
|
||||||
|
|
||||||
|
# convert back to BGR
|
||||||
|
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
||||||
|
|
||||||
|
return frame
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user