1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- from importlib import import_module
- import os
- from flask import Flask, render_template, Response, request, send_file
- import cv2
- import subprocess
- import time
- import sys
- import pdb
- if os.environ.get('CAMERA'):
- Camera = import_module('camera_' + os.environ['CAMERA']).Camera
- else:
- from camera import Camera
- app = Flask(__name__)
- class Model():
- def __init__(self, device='cuda'):
- tstamp = time.time()
- self.device = device
- self.net =
- def get_stream_video():
-
- cam = cv2.VideoCapture('rtsp://astrodom:hdci12@192.168.170.73:554/stream1')
-
- while True:
-
- success, frame = cam.read()
-
-
- if not success:
- break
- else:
- ret, buffer = cv2.imencode('.jpeg', frame)
-
-
- print(type(buffer))
- frame = buffer.tobytes()
- print(type(frame))
- pdb.set_trace()
- yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + bytearray(frame) + b'\r\n')
- @app.route('/')
- def index():
- return render_template('index.html')
- @app.get("/video")
- def video():
-
-
- return Response(get_stream_video(), mimetype="multipart/x-mixed-replace; boundary=frame")
- @app.route("/stream", methods=['GET'])
- def stream():
- print("here")
- subprocess.run(['python3', '/root/helmet_det/yolov7-main/detect.py', '--source', 'rtsp://astrodom:hdci12@192.168.170.73:554/stream1', '--weights', 'best.pt'])
- return "done"
- if __name__ == '__main__':
- app.run(host='0.0.0.0', debug=True)
|