This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from dkanukov/feature/streaming
test streaming
- Loading branch information
Showing
18 changed files
with
97 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import CustomedApi from '../generated/customed-api' | ||
|
||
export const getStream = async (cameraId: string) => { | ||
const response = await CustomedApi.stream.streamDetail(cameraId) | ||
console.log(response.data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.root { | ||
padding: 20px; | ||
} | ||
|
||
.video { | ||
max-width: calc(100vw - 40px); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
'use client' | ||
import { Typography } from 'antd' | ||
import { useSearchParams } from 'next/navigation' | ||
|
||
import styles from './camera.module.css' | ||
|
||
const { Title } = Typography | ||
|
||
export default function Camera() { | ||
const searchParams = useSearchParams() | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<Title>Просмотр камеры</Title> | ||
<img | ||
className={styles.video} | ||
src={`http://localhost:8081/stream/${searchParams.get('cameraId')}`} | ||
/> | ||
{/*<video>*/} | ||
{/* <source src={`http://localhost:8081/stream/${searchParams.get('cameraId')}`}/>*/} | ||
{/*</video>*/} | ||
</div> | ||
) | ||
} | ||
|
5 changes: 3 additions & 2 deletions
5
frontend/components/backend-summary-body/BackendSummaryBody.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
.dropdown { | ||
padding: 8px; | ||
} | ||
|
||
.nameCell { | ||
display: flex; | ||
gap: 6px; | ||
align-items: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { useDevicesList } from './use-devices-list' | ||
export { useCamera } from './use-camera' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { streamService } from '@api' | ||
|
||
export const useCamera = (cameraId: string) => { | ||
const fetchStream = async () => { | ||
await streamService.getStream(cameraId) | ||
} | ||
|
||
return { | ||
fetchStream, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
import time | ||
|
||
from flask import Flask, Response, request | ||
from generate_frame import VideoCamera | ||
import requests | ||
|
||
|
||
app = Flask("stream") | ||
|
||
camera_instance = None # Maintain a single instance of VideoCamera | ||
|
||
|
||
def gen(camera : VideoCamera): | ||
def gen(camera): | ||
while True: | ||
frame = camera.get_frame() | ||
yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') | ||
if frame is not None: | ||
yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') | ||
else: | ||
del camera | ||
break # Stops the stream if no frame is available | ||
|
||
|
||
@app.route("/", methods=['GET']) | ||
def stream(): | ||
args = request.args | ||
return Response(gen(VideoCamera(args.get("url"))), mimetype='multipart/x-mixed-replace; boundary=frame') | ||
camera = VideoCamera(args.get("url")) | ||
return Response(gen(camera), mimetype='multipart/x-mixed-replace; boundary=frame') | ||
|
||
|
||
@app.route("/isLowLight/", methods=["GET"]) | ||
def is_low_lighted(): | ||
args = request.args | ||
frame = VideoCamera(args.get("url")).get_frame() | ||
camera = VideoCamera(args.get("url")) | ||
frame = camera.get_frame() | ||
if frame is None: | ||
return Response(status=404) | ||
files = { | ||
'file': frame | ||
} | ||
resp = requests.post("http://imaging-service:8088/", files=files) | ||
print(resp.text) | ||
return Response(resp.text, mimetype="application/json") | ||
return Response("No frame available", status=404) | ||
files = {'file': ('frame.jpg', frame, 'image/jpeg')} | ||
del camera | ||
try: | ||
resp = requests.post("http://imaging-service:8088/", files=files) | ||
return Response(resp.text, mimetype="application/json") | ||
except requests.RequestException as e: | ||
return Response(str(e), status=500) | ||
|
||
|
||
if __name__=="__main__": | ||
# http_server = WSGIServer(('', 8181), app) | ||
# http_server.serve_forever() | ||
|
||
app.run(host="0.0.0.0", port=8181) | ||
|
||
|
||
|
||
# @app.route('/video_feed') | ||
# def video_feed(): | ||
# return Response(gen(VideoCamera()), mimetype='multipart/x-mixed-replace; boundary=frame') | ||
app.run(host="0.0.0.0", port=8181, threaded=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import cv2, time | ||
import cv2 | ||
|
||
|
||
class VideoCamera(object): | ||
def __init__(self, video_source : str): | ||
def __init__(self, video_source: str): | ||
self.video = cv2.VideoCapture(video_source) | ||
|
||
def __del__(self): | ||
self.video.release() | ||
|
||
def get_frame(self): | ||
_, image = self.video.read() | ||
_, jpeg = cv2.imencode('.jpg', image) | ||
return jpeg.tobytes() | ||
ok, image = self.video.read() | ||
if not ok: | ||
return None | ||
ok, jpeg = cv2.imencode('.jpg', image) | ||
if not ok: | ||
return None | ||
return jpeg.tobytes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters