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
- # import camera driver
- # from object_detection import VideoStreaming
- if os.environ.get('CAMERA'):
- Camera = import_module('camera_' + os.environ['CAMERA']).Camera
- else:
- from camera import Camera
- app = Flask(__name__)
- # def gen(camera):
- # while True:
- # frame = VideoStreaming.get_frame()
- # # cv2.imencode('.jpg', frame)
- # yield (b'--frame\r\n'
- # b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
- class Model():
- def __init__(self, device='cuda'):
- tstamp = time.time()
- self.device = device
- self.net =
- def get_stream_video():
- # camera 정의
- cam = cv2.VideoCapture('rtsp://astrodom:hdci12@192.168.170.73:554/stream1')
-
- while True:
- # 카메라 값 불러오기
- success, frame = cam.read()
- # print(frame)
- # print(type(frame))
- if not success:
- break
- else:
- ret, buffer = cv2.imencode('.jpeg', frame)
- # frame을 byte로 변경 후 특정 식??으로 변환 후에
- # yield로 하나씩 넘겨준다.
- 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')
- # 스트리밍 경로를 /video 경로로 설정.
- @app.get("/video")
- def video():
- # StringResponse함수를 return하고,
- # 인자로 OpenCV에서 가져온 "바이트"이미지와 type을 명시
- return Response(get_stream_video(), mimetype="multipart/x-mixed-replace; boundary=frame")
- # ipcam 열기
- @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"
- # rtsp://astrodom:hdci12@192.168.170.73:554/stream1
- if __name__ == '__main__':
- app.run(host='0.0.0.0', debug=True)
|