Free Motion Capture for Everyone πβ¨
TypeScript
clean up, and get ready for imshow stuff
Endurance Idehen566087132370
diff --git a/freemocap-ui/package.json b/freemocap-ui/package.jsonindex ec3a25fc..98130cc2 100644--- a/freemocap-ui/package.json+++ b/freemocap-ui/package.json@@ -24,8 +24,10 @@"react-router": "^6.2.1","react-router-dom": "^6.2.1","react-scripts": "5.0.0",+ "react-step-wizard": "^5.3.11","react-use": "^17.3.2","react-use-websocket": "^2.9.1",+ "react-use-wizard": "^2.2.0","react-webcam": "^6.0.0","reflect-metadata": "^0.1.13","three.js": "^0.77.1",diff --git a/freemocap-ui/src/layout/Header.tsx b/freemocap-ui/src/layout/Header.tsxindex 5658d558..862689ae 100644--- a/freemocap-ui/src/layout/Header.tsx+++ b/freemocap-ui/src/layout/Header.tsx@@ -1,13 +1,9 @@import * as React from 'react';import AppBar from '@mui/material/AppBar';-import Button from '@mui/material/Button';import Grid from '@mui/material/Grid';-import HelpIcon from '@mui/icons-material/Help';import IconButton from '@mui/material/IconButton';-import Link from '@mui/material/Link';import MenuIcon from '@mui/icons-material/Menu';import Toolbar from '@mui/material/Toolbar';-import Tooltip from '@mui/material/Tooltip';import Typography from '@mui/material/Typography';const lightColor = 'rgba(255, 255, 255, 0.7)';@@ -17,15 +13,15 @@ interface HeaderProps {title: string;}-export const Header = function(props: HeaderProps) {- const { onDrawerToggle } = props;+export const Header = function (props: HeaderProps) {+ const {onDrawerToggle} = props;return (<React.Fragment><AppBar color="primary" position="sticky" elevation={0}><Toolbar><Grid container spacing={1} alignItems="center">- <Grid sx={{ display: { sm: 'none', xs: 'block' } }} item>+ <Grid sx={{display: {sm: 'none', xs: 'block'}}} item><IconButtoncolor="inherit"aria-label="open drawer"@@ -37,21 +33,6 @@ export const Header = function(props: HeaderProps) {</Grid><Grid item xs /><Grid item>- {/*<Link*/}- {/* href="/"*/}- {/* variant="body2"*/}- {/* sx={{*/}- {/* textDecoration: 'none',*/}- {/* color: lightColor,*/}- {/* '&:hover': {*/}- {/* color: 'common.white',*/}- {/* },*/}- {/* }}*/}- {/* rel="noopener noreferrer"*/}- {/* target="_blank"*/}- {/*>*/}- {/* Go to docs*/}- {/*</Link>*/}</Grid></Grid></Toolbar>@@ -61,7 +42,7 @@ export const Header = function(props: HeaderProps) {color="primary"position="static"elevation={0}- sx={{ zIndex: 0 }}+ sx={{zIndex: 0}}><Toolbar><Grid container alignItems="center" spacing={1}>diff --git a/freemocap-ui/src/layout/Navigator.tsx b/freemocap-ui/src/layout/Navigator.tsxindex b462d209..3ef255b4 100644--- a/freemocap-ui/src/layout/Navigator.tsx+++ b/freemocap-ui/src/layout/Navigator.tsx@@ -12,8 +12,12 @@ import {useNavigate} from "react-router";const categories = [{- id: 'Build',+ id: 'Interact',children: [+ {+ id: 'Session',+ route: "/session"+ },{id: 'Setup and Preview',route: "/setup_and_preview"@@ -22,14 +26,6 @@ const categories = [id: 'Show Cameras',route: "/show_cameras"},- {- id: "Board Detection",- route: "/charuco_board_detection"- },- {- id: "Skeleton Detection",- route: "/skeleton_detection"- }],},];@@ -56,7 +52,7 @@ export const Navigator = function (props: DrawerProps) {<Drawer variant="permanent" {...other}><List disablePadding><ListItem sx={{...item, ...itemCategory, fontSize: 22, color: '#fff'}}>- FreeMoCap+ freemocap</ListItem><ListItem sx={{...item, ...itemCategory}}><ListItemIcon>diff --git a/freemocap-ui/src/layout/routing/router.tsx b/freemocap-ui/src/layout/routing/router.tsxindex e372bc74..5df6b723 100644--- a/freemocap-ui/src/layout/routing/router.tsx+++ b/freemocap-ui/src/layout/routing/router.tsx@@ -2,23 +2,18 @@ import React from 'react';import {Route, Routes} from "react-router-dom";import {WebcamStreamCapture} from "../../views/Capture";import {ConfigView} from "../../views/Config";-import {WebcamJonTest} from "../../views/WebcamJonTest";-import {PythonToJsTest} from "../../views/PythonToJsTest";-import {BoardDetection} from "../../views/BoardDetection";-import {SkeletonDetection} from "../../views/SkeletonDetection";import {SetupAndPreviewView} from "../../views/prod/SetupAndPreviewView";+import {SessionWorkflow} from "../../views/SessionWorkflow";+export const Router = () => {return (<Routes><Route path={'/'} element={<React.Fragment />} />- <Route path={'/setup_and_preview'} element={<SetupAndPreviewView />} />+ <Route path={'/session'} element={<SessionWorkflow />} />+ <Route path={'/session/setup_and_preview/:sessionId'} element={<SetupAndPreviewView />} /><Route path={'/show_cameras'} element={<WebcamStreamCapture />} /><Route path={'/config'} element={<ConfigView />} />- <Route path={'/jontestplayground'} element={<WebcamJonTest />} />- <Route path={'/pythonToJs'} element={<PythonToJsTest />} />- <Route path={'/charuco_board_detection'} element={<BoardDetection />} />- <Route path={'/skeleton_detection'} element={<SkeletonDetection />} /></Routes>)}\ No newline at end of filediff --git a/freemocap-ui/src/views/BoardDetection.tsx b/freemocap-ui/src/views/BoardDetection.tsxdeleted file mode 100644index 92d0c625..00000000--- a/freemocap-ui/src/views/BoardDetection.tsx+++ /dev/null@@ -1,17 +0,0 @@-import React from "react";-import {Box} from "@mui/material";-import {CaptureType} from "../services/frame-capture";-import {useFrameCapture} from "../hooks/use-frame-capture";--export const BoardDetection = () => {- const [frameCapture, data] = useFrameCapture("0", CaptureType.BoardDetection);- if (!data) {- return null;- }-- return (- <Box>- {!frameCapture.isConnectionClosed && <img src={frameCapture.current_data_url} alt={"video capture"}/>}- </Box>- )-}\ No newline at end of filediff --git a/freemocap-ui/src/views/PythonToJsTest.tsx b/freemocap-ui/src/views/PythonToJsTest.tsxdeleted file mode 100644index 34dae6b6..00000000--- a/freemocap-ui/src/views/PythonToJsTest.tsx+++ /dev/null@@ -1,46 +0,0 @@-import React from "react";-import {Box} from "@mui/material";-import {useAsync} from "react-use";-import axios from "axios";--export const PythonToJsTest = () => {- const [data, setData] = React.useState<object>({});-- useAsync(async () => {- const response = await axios.get('http://localhost:8080/camera/detect');- const port_numbers = response.data.cams_to_use.map(x => x.port_number);- const sockets: WebSocket[] = port_numbers.map(port => new WebSocket(`ws://localhost:8080/ws/${port}`));- sockets.forEach((socket, index) => {- window.onbeforeunload = function() {- socket.onclose = function () {}; // disable onclose handler first- socket.close();- };- socket.onmessage = async (ev: MessageEvent<Blob>) => {- const byteData = await ev.data.text();- setData(prev => {- return {- ...prev,- [index]: byteData- }- });- }- })- }, []);-- if (!data) {- return null;- }-- const keys = Object.keys(data);- return (- <Box>- {- keys.map(k => {- return (- <img src={`data:image/png;base64,${data[k]}`} alt={"video capture"}/>- )- })- }- </Box>- )-}\ No newline at end of filediff --git a/freemocap-ui/src/views/SessionWorkflow.tsx b/freemocap-ui/src/views/SessionWorkflow.tsxnew file mode 100644index 00000000..3425ce9d--- /dev/null+++ b/freemocap-ui/src/views/SessionWorkflow.tsx@@ -0,0 +1,41 @@+import React from 'react';+import {IconButton} from "@mui/material";+import {Box} from "@mui/system";+import AddRoundedIcon from '@mui/icons-material/AddRounded';+import {useNavigate} from "react-router";+import axios from "axios";++interface SessionResponse {+ session_id: string+ session_path: string+}++export const SessionWorkflow = () => {+ const navigate = useNavigate();+ const [IconButtonContainer] = [Box];++ const createSession = async () => {+ const response = await axios.post('http://localhost:8080/session/create/', {})+ const sessionResponse = response.data as SessionResponse;+ return sessionResponse;+ }+ return (+ <Box>+ <IconButtonContainer+ sx={{+ cursor: 'pointer'+ }}+ display={'flex'} flexDirection={'row'} alignItems={'center'} onClick={async () => {+ const sessionResponse = await createSession();+ const sessionId = sessionResponse.session_id;+ navigate(`/session/setup_and_preview/${sessionId}`)+ }}>+ <IconButton>+ <AddRoundedIcon />+ </IconButton>+ Create New Session+ </IconButtonContainer>++ </Box>+ )+}\ No newline at end of filediff --git a/freemocap-ui/src/views/SkeletonDetection.tsx b/freemocap-ui/src/views/SkeletonDetection.tsxdeleted file mode 100644index d4d33891..00000000--- a/freemocap-ui/src/views/SkeletonDetection.tsx+++ /dev/null@@ -1,16 +0,0 @@-import React from "react";-import {Box} from "@mui/material";-import {CaptureType} from "../services/frame-capture";-import {useFrameCapture} from "../hooks/use-frame-capture";--export const SkeletonDetection = () => {- const [frameCapture, data] = useFrameCapture("0", CaptureType.SkeletonDetection);- if (!data) {- return null;- }- return (- <Box>- {!frameCapture.isConnectionClosed && <img src={frameCapture.current_data_url} alt={"video capture"}/>}- </Box>- );-}diff --git a/freemocap-ui/src/views/WebcamJonTest.tsx b/freemocap-ui/src/views/WebcamJonTest.tsxdeleted file mode 100644index e90acd03..00000000--- a/freemocap-ui/src/views/WebcamJonTest.tsx+++ /dev/null@@ -1,39 +0,0 @@-import Webcam from "react-webcam";-import {BrowserCam} from "../services/cam";-import {useAsync, useMount} from "react-use";-import React from "react";-import { Box } from "@mui/material";--const cams = new BrowserCam().findAllCameras();--export const WebcamJonTest = () => {- useAsync(async () => {- const cams = await new BrowserCam().findAllCameras();- console.log(cams);- }, []);- const cst = navigator.mediaDevices.getSupportedConstraints()-- const constraints: MediaStreamConstraints = {- video: {- // Jon, you can change stuff here-- // You can select a specific video device by putting a device Id here.- // Check your browser console to take a device you'd like.- // deviceId: "",-- exposureMode: "manual",- exposureCompensation: "-3"- } as any- }---- return (- <Box>- <Webcam videoConstraints={constraints.video}/>- <Box>-- </Box>- </Box>- )-}\ No newline at end of filediff --git a/freemocap-ui/src/views/prod/ConfigForm.tsx b/freemocap-ui/src/views/prod/ConfigForm.tsxindex 536db4d2..23e25785 100644--- a/freemocap-ui/src/views/prod/ConfigForm.tsx+++ b/freemocap-ui/src/views/prod/ConfigForm.tsx@@ -9,7 +9,12 @@ const ExposureNumberField = () => {);}-export const ConfigForm = () => {+interface Props {+ onSubmit: () => void+}++export const ConfigForm = (props: Props) => {+ const { onSubmit } = props;return (<Box>@@ -31,7 +36,7 @@ export const ConfigForm = () => {<NumberFormat customInput={TextField} /></Box>- <Button>Save Camera Settings</Button>+ <Button onClick={onSubmit}>Save Camera Settings</Button></Box>)}\ No newline at end of filediff --git a/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx b/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsxindex 210ad238..c3f3d517 100644--- a/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx+++ b/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx@@ -4,23 +4,14 @@ import {Box, Button} from "@mui/material";import React from "react";import {ConfigForm} from "./ConfigForm";-// 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).-interface Props {- camId: string+ webcamId: string;+ onSubmit: () => void;}export const SetupAndPreviewCamera = (props: Props) => {- const { camId } = props;- const [frameCapture, data] = useFrameCapture(camId, CaptureType.Preview);+ const { webcamId, onSubmit } = props;+ const [frameCapture, data] = useFrameCapture(webcamId, CaptureType.Preview);if (!data) {return null;}@@ -31,7 +22,7 @@ export const SetupAndPreviewCamera = (props: Props) => {<Button>Preview in CV2</Button>{!frameCapture.isConnectionClosed && <img src={frameCapture.current_data_url} alt={"video capture"} />}</Box>- <ConfigForm />+ <ConfigForm onSubmit={onSubmit}/></Box>)}\ No newline at end of filediff --git a/freemocap-ui/src/views/prod/SetupAndPreviewView.tsx b/freemocap-ui/src/views/prod/SetupAndPreviewView.tsxindex a0f05956..bca5804a 100644--- a/freemocap-ui/src/views/prod/SetupAndPreviewView.tsx+++ b/freemocap-ui/src/views/prod/SetupAndPreviewView.tsx@@ -1,37 +1,26 @@import {Box} from "@mui/material";-import React from "react";+import React, {useState} 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).-+import {SessionWizard} from "../sessionWizard/SessionWizard";export const SetupAndPreviewView = () => {- const response = useAsync(async () => {+ const [webcamIds, setWebcamIds] = useState();++ 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);- return <SetupAndPreviewCamera camId={port_numbers[0]} />- // return port_numbers.map(x => {- // return <SetupAndPreviewCamera camId={x} />- // })- }, []);+ const webcamIds = response.data.cameras_found_list.map(x => x.webcam_id);+ setWebcamIds(webcamIds)+ }, [])- if (response.loading) {+ if (!webcamIds) {+ // Small loading indicatorreturn null;}- const r = response.value;+return (<Box>- {r}+ <SessionWizard webcamIds={webcamIds} /></Box>)}\ No newline at end of filediff --git a/freemocap-ui/src/views/sessionWizard/SessionWizard.tsx b/freemocap-ui/src/views/sessionWizard/SessionWizard.tsxnew file mode 100644index 00000000..32d78314--- /dev/null+++ b/freemocap-ui/src/views/sessionWizard/SessionWizard.tsx@@ -0,0 +1,59 @@+import {SetupAndPreviewCamera} from "../prod/SetupAndPreviewCamera";+import {Button, Typography} from "@mui/material";+import {Box} from "@mui/system";+import {useWizard, Wizard} from "react-use-wizard";+import axios from "axios";++interface Props {+ webcamIds: string[];+}++export const SessionWizard = (props: Props) => {+ // generate steps within the step wizard+ const {webcamIds} = props++ return (+ <Wizard>+ {webcamIds.map(webcamId => {+ return <CamStep webcamId={webcamId} />+ })}+ {/*<IMShowPreviewCamera />*/}+ </Wizard>+ )+}++interface CamStepProps {+ webcamId: string+}++export const CamStep = (props: CamStepProps) => {+ const {webcamId} = props+ const {handleStep, previousStep, nextStep, stepCount, isLastStep} = useWizard();++ return (+ <Box>+ <Typography>Step {stepCount}</Typography>+ <Typography>Camera {webcamId}</Typography>+ <SetupAndPreviewCamera webcamId={webcamId} onSubmit={nextStep} />+ </Box>+ )+}+//+// interface PreviewCamera {}+// export const IMShowPreviewCamera = () => {+// const {handleStep, previousStep, nextStep, stepCount, isLastStep} = useWizard();+// useAsync(async () => {+// await axios.post('http://localhost:8080/camera/cv2_imshow_one_camera', {+// session_id+// });+// }, []);+// return (+// <Box>+// <Typography>External Windows should pop up showing the images from your webcams all together.</Typography>+// <Typography>If you are ready to record, and the configuration seems correct, please continue.</Typography>+// <Typography>If not, please go to the previous steps and change the configuration</Typography>+// <Button onClick={previousStep}>No, I want to go back</Button>+// <Button onClick={nextStep}>Yes, Im ready to record</Button>+// </Box>+// )+// }diff --git a/src/api/routes/session/session_router.py b/src/api/routes/session/session_router.pyindex dd08e1cf..715d1ec8 100644--- a/src/api/routes/session/session_router.py+++ b/src/api/routes/session/session_router.py@@ -1,5 +1,6 @@import loggingfrom pathlib import Path+from typing import Optionalfrom fastapi import APIRouterfrom pydantic import BaseModel@@ -14,7 +15,7 @@ BASE_FOLDER_NAME = "freemocap_data"class SessionCreateModel(BaseModel):- user_session_str: str+ user_session_str: Optional[str]class SessionResponse(BaseModel):