Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

preview webcam works

Endurance Idehend7fee05863a0
diff --git a/bin/linux/run_uvicorn_server.sh b/bin/linux/run_uvicorn_server.sh
index 38df6ab4..d99c1b9b 100755
--- a/bin/linux/run_uvicorn_server.sh
+++ b/bin/linux/run_uvicorn_server.sh
@@ -3,5 +3,5 @@
# Start the webserver
-uvicorn --factory src.api.app_factory:create_app --port 8080 --host 0.0.0.0 --workers 4 --ws websockets
+uvicorn --factory src.api.app_factory:create_app --port 8080 --host 0.0.0.0 --workers 8 --ws websockets
diff --git a/freemocap-ui/src/layout/routing/router.tsx b/freemocap-ui/src/layout/routing/router.tsx
index 88f46a0f..e372bc74 100644
--- a/freemocap-ui/src/layout/routing/router.tsx
+++ b/freemocap-ui/src/layout/routing/router.tsx
@@ -6,13 +6,13 @@ import {WebcamJonTest} from "../../views/WebcamJonTest";
import {PythonToJsTest} from "../../views/PythonToJsTest";
import {BoardDetection} from "../../views/BoardDetection";
import {SkeletonDetection} from "../../views/SkeletonDetection";
-import {SetupAndPreview} from "../../views/prod/SetupAndPreviewCamera";
+import {SetupAndPreviewView} from "../../views/prod/SetupAndPreviewView";
export const Router = () => {
return (
<Routes>
<Route path={'/'} element={<React.Fragment />} />
- <Route path={'/setup_and_preview'} element={<SetupAndPreview />} />
+ <Route path={'/setup_and_preview'} element={<SetupAndPreviewView />} />
<Route path={'/show_cameras'} element={<WebcamStreamCapture />} />
<Route path={'/config'} element={<ConfigView />} />
<Route path={'/jontestplayground'} element={<WebcamJonTest />} />
diff --git a/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx b/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx
index 09c59420..4cf730ab 100644
--- a/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx
+++ b/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx
@@ -2,6 +2,8 @@ import {useFrameCapture} from "../../hooks/use-frame-capture";
import {CaptureType} from "../../services/frame-capture";
import {Box} from "@mui/material";
import React from "react";
+import axios from "axios";
+import {useAsync} from "react-use";
// So what do we need?
@@ -18,6 +20,7 @@ interface Props {
}
export const SetupAndPreviewCamera = (props: Props) => {
+ const { camId } = props;
const [frameCapture, data] = useFrameCapture(camId, CaptureType.Preview);
if (!data) {
return null;
diff --git a/freemocap-ui/src/views/prod/SetupAndPreviewView.tsx b/freemocap-ui/src/views/prod/SetupAndPreviewView.tsx
new file mode 100644
index 00000000..b028771e
--- /dev/null
+++ b/freemocap-ui/src/views/prod/SetupAndPreviewView.tsx
@@ -0,0 +1,40 @@
+import {useFrameCapture} from "../../hooks/use-frame-capture";
+import {CaptureType} from "../../services/frame-capture";
+import {Box} from "@mui/material";
+import React from "react";
+import {useAsync} from "react-use";
+import axios from "axios";
+import {SetupAndPreviewCamera} from "./SetupAndPreviewCamera";
+
+// So what do we need?
+
+// We need to know what all the cameras are ahead of time, so that we can tell the UI
+// what is possible to connect to.
+
+// SetupAndPreview View will run through that list of available cameras, and display it to the user.
+
+// Finally, We'll include form inputs so that users can select configuration on screen, and submit their results
+// for freemocap (api) to save (prolly to disk).
+
+
+export const SetupAndPreviewView = () => {
+ const response = useAsync(async () => {
+ const response = await axios.get('http://localhost:8080/camera/detect');
+ const port_numbers = response.data.cameras_found_list.map(x => x.webcam_id);
+ console.log(response.data)
+ return port_numbers.map(x => {
+ return <SetupAndPreviewCamera camId={x} />
+ })
+ }, []);
+
+ if (response.loading) {
+ return null;
+ }
+ const r = response.value;
+ console.log(r)
+ return (
+ <Box>
+ {r}
+ </Box>
+ )
+}
\ No newline at end of file
diff --git a/src/api/routes/camera/cam_data_ws.py b/src/api/routes/camera/cam_data_ws.py
index 69991cd0..e59d652c 100644
--- a/src/api/routes/camera/cam_data_ws.py
+++ b/src/api/routes/camera/cam_data_ws.py
@@ -29,7 +29,9 @@ async def preview_webcam(web_socket: WebSocket, webcam_id: str):
cv_cam = OpenCVCamera(
WebcamConfig(webcam_id=webcam_id),
)
- cv_cam.connect()
+ connected = cv_cam.connect()
+ if not connected:
+ return
cv_cam.start_frame_capture_thread()
# TODO: Allow connections to drop, allow signals to get through so we can cancel
@@ -40,5 +42,8 @@ async def preview_webcam(web_socket: WebSocket, webcam_id: str):
logger.error("Websocket ended")
traceback.print_exc()
return
+ finally:
+ await web_socket.close()
+