Skip to content

Free Motion Capture for Everyone 💀✨

TypeScript

move ws from skellycam to freemocap

jonmatthisb24e8706421e
diff --git a/freemocap-ui/src/App.tsx b/freemocap-ui/src/App.tsx
index a4738248..042124e3 100644
--- a/freemocap-ui/src/App.tsx
+++ b/freemocap-ui/src/App.tsx
@@ -5,7 +5,7 @@ import {WebSocketProvider} from "@/context/WebSocketContext";
function App() {
const _port = 8005;
- const wsUrl = `ws://localhost:${_port}/skellycam/websocket/connect`;
+ const wsUrl = `ws://localhost:${_port}/websocket/connect`;
return (
<WebSocketProvider url={wsUrl}>
<React.Fragment>
diff --git a/freemocap-ui/src/views/PythonCamerasView.tsx b/freemocap-ui/src/views/PythonCamerasView.tsx
index 0c64f3e7..173c32e1 100644
--- a/freemocap-ui/src/views/PythonCamerasView.tsx
+++ b/freemocap-ui/src/views/PythonCamerasView.tsx
@@ -6,7 +6,7 @@ export const PythonCamerasView = () => {
const { latestFrontendPayload } = useWebSocketContext();
return (
- <Box sx={{ display: "flex", flexDirection: "column", height: "100vh" }}>
+ <Box sx={{ display: "flex", flexDirection: "column", height: "70vh" }}>
<ConnectToCamerasButton />
{latestFrontendPayload && latestFrontendPayload.jpeg_images && (
<Box
@@ -28,8 +28,8 @@ export const PythonCamerasView = () => {
display: "flex",
justifyContent: "center",
alignItems: "center",
- flexBasis: "calc(50% - 20px)",
- margin: "10px",
+ flexBasis: "calc(50% - 5px)",
+ margin: "1px",
boxSizing: "border-box"
}}
>
diff --git a/freemocap/api/http/ui/ui.html b/freemocap/api/http/ui/ui.html
index 7f32fa73..2e082f82 100644
--- a/freemocap/api/http/ui/ui.html
+++ b/freemocap/api/http/ui/ui.html
@@ -28,7 +28,7 @@
<script>
let ws;
let isConnected = false;
- const websocket_url = 'ws://localhost:8005/skellycam/websocket/connect';
+ const websocket_url = 'ws://localhost:8005/websocket/connect';
const imageElements = {};
function updateStatus() {
@@ -120,7 +120,7 @@
</head>
<body>
<!-- Header Section -->
-<h1>SkellyCam API Tester with WebSocket</h1>
+<h1>FreeMoCap API Tester with WebSocket</h1>
<p> WebSocket status: <span id="ws-status">Disconnected</span></p>
<!-- WebSocket Section -->
@@ -134,18 +134,18 @@
<button onclick="callApi('http://localhost:8005/skellycam/cameras/connect/apply', 'POST')">Connect/Update Cameras</button>
<button onclick="callApi('http://localhost:8005/skellycam/cameras/close')">Close Camera Connections</button>
- <!-- Root and App API Calls -->
- <button onclick="sendMessage('Hello from the client')">Send WS Message</button>
- <button onclick="callApi('http://localhost:8005/')">Read Root</button>
- <button onclick="callApi('http://localhost:8005/skellycam/app/state')">App State</button>
- <button onclick="callApi('http://localhost:8005/skellycam/app/healthcheck')">Hello👋</button>
- <button onclick="callApi('http://localhost:8005/skellycam/app_state/shutdown')">goodbye👋</button>
+<!-- &lt;!&ndash; Root and App API Calls &ndash;&gt;-->
+<!-- <button onclick="sendMessage('Hello from the client')">Send WS Message</button>-->
+<!-- <button onclick="callApi('http://localhost:8005/')">Read Root</button>-->
+<!-- <button onclick="callApi('http://localhost:8005/skellycam/app/state')">App State</button>-->
+<!-- <button onclick="callApi('http://localhost:8005/skellycam/app/healthcheck')">Hello👋</button>-->
+<!-- <button onclick="callApi('http://localhost:8005/skellycam/app_state/shutdown')">goodbye👋</button>-->
- <!-- Camera Operation API Calls -->
- <button onclick="callApi('http://localhost:8005/skellycam/cameras/detect')">Detect Cameras</button>
- <button onclick="callApi('http://localhost:8005/skellycam/cameras/record/start')">Start Recording</button>
- <button onclick="callApi('http://localhost:8005/skellycam/cameras/record/stop')">Stop Recording</button>
+<!-- &lt;!&ndash; Camera Operation API Calls &ndash;&gt;-->
+<!-- <button onclick="callApi('http://localhost:8005/skellycam/cameras/detect')">Detect Cameras</button>-->
+<!-- <button onclick="callApi('http://localhost:8005/skellycam/cameras/record/start')">Start Recording</button>-->
+<!-- <button onclick="callApi('http://localhost:8005/skellycam/cameras/record/stop')">Stop Recording</button>-->
</div>
<!-- Results and Logs Section -->
<pre id="result"></pre>
diff --git a/freemocap/api/routers.py b/freemocap/api/routers.py
index 93e077d5..acc3f564 100644
--- a/freemocap/api/routers.py
+++ b/freemocap/api/routers.py
@@ -1,9 +1,10 @@
-from skellycam import SKELLYCAM_ROUTERS
-
from freemocap.api.http.app.health import health_router
from freemocap.api.http.app.shutdown import app_shutdown_router
from freemocap.api.http.app.state import state_router
from freemocap.api.http.ui.ui_router import ui_router
+from freemocap.api.websocket.websocket_connect import websocket_router
+from skellycam import SKELLYCAM_ROUTERS
+
FREEMOCAP_ROUTERS = {
"/ui": {
@@ -14,5 +15,9 @@ FREEMOCAP_ROUTERS = {
"state": state_router,
"shutdown": app_shutdown_router
},
+ "/websocket": {
+ "connect": websocket_router
+ },
+
**SKELLYCAM_ROUTERS
}
diff --git a/freemocap/api/websocket/websocket_server.py b/freemocap/api/websocket/websocket_server.py
index c7d76fe4..fc4d851c 100644
--- a/freemocap/api/websocket/websocket_server.py
+++ b/freemocap/api/websocket/websocket_server.py
@@ -10,7 +10,6 @@ from skellycam.app.app_state import AppStateDTO, AppState
from skellycam.core.frames.payloads.frontend_image_payload import FrontendFramePayload
from skellycam.core.frames.payloads.multi_frame_payload import MultiFramePayload
from skellycam.core.recorders.timestamps.framerate_tracker import CurrentFrameRate
-from skellycam.core.recorders.videos.video_recorder_manager import RecordingInfo
from skellycam.utilities.wait_functions import async_wait_1ms
logger = logging.getLogger(__name__)
diff --git a/freemocap/freemocap_app/freemocap_app_state.py b/freemocap/freemocap_app/freemocap_app_state.py
index 9b076b62..f37339d9 100644
--- a/freemocap/freemocap_app/freemocap_app_state.py
+++ b/freemocap/freemocap_app/freemocap_app_state.py
@@ -1,115 +1,25 @@
import logging
import multiprocessing
from dataclasses import dataclass
-from datetime import datetime
from typing import Optional
-from uuid import uuid4
-
-from pydantic import BaseModel
+from skellycam.core.camera_group.shmorchestrator.shared_memory.multi_frame_escape_ring_buffer import \
+ MultiFrameEscapeSharedMemoryRingBuffer
+from skellycam.skellycam_app.skellycam_app_state import SkellycamAppState
logger = logging.getLogger(__name__)
@dataclass
class FreemocapAppState:
+ global_kill_flag: multiprocessing.Value
+ skellycam_app_state: Optional[SkellycamAppState] = None
@classmethod
def create(cls, global_kill_flag: multiprocessing.Value):
- return cls(ipc_flags=IPCFlags(global_kill_flag=global_kill_flag),
- ipc_queue=multiprocessing.Queue(),
- config_update_queue=multiprocessing.Queue())
-
+ return cls(global_kill_flag=global_kill_flag,
+ skellycam_app_state=SkellycamAppState.create(global_kill_flag=global_kill_flag))
@property
def frame_escape_shm(self) -> MultiFrameEscapeSharedMemoryRingBuffer:
- return self.shmorchestrator.multi_frame_escape_ring_shm
-
- @property
- def camera_group_configs(self) -> Optional[CameraConfigs]:
- if self.camera_group is None:
- if self.available_devices is None:
- raise ValueError("Cannot get CameraConfigs without available devices!")
- return available_devices_to_default_camera_configs(self.available_devices)
- return self.camera_group.camera_configs
-
- def set_available_devices(self, value: AvailableDevices):
- self.available_devices = value
- self.ipc_queue.put(self.state_dto())
-
- def create_camera_group(self, camera_configs: CameraConfigs):
- if camera_configs is None:
- raise ValueError("Cannot create CameraGroup without camera_configs!")
- # if self.available_devices is None:
- # raise ValueError("Cannot get CameraConfigs without available devices!")
- self.camera_group_dto = CameraGroupDTO(camera_configs=camera_configs,
- ipc_queue=self.ipc_queue,
- ipc_flags=self.ipc_flags,
- config_update_queue=self.config_update_queue,
- group_uuid=str(uuid4())
- )
- self.shmorchestrator = CameraGroupSharedMemoryOrchestrator.create(camera_group_dto=self.camera_group_dto,
- ipc_flags=self.ipc_flags,
- read_only=True)
- self.camera_group = CameraGroup.create(camera_group_dto=self.camera_group_dto,
- shmorc_dto=self.shmorchestrator.to_dto()
- )
-
- logger.info(f"Camera group created successfully for cameras: {self.camera_group.camera_ids}")
-
- def update_camera_group(self,
- camera_configs: CameraConfigs,
- update_instructions: UpdateInstructions):
- if self.camera_group is None:
- raise ValueError("Cannot update CameraGroup if it does not exist!")
- self.camera_group.update_camera_configs(camera_configs=camera_configs,
- update_instructions=update_instructions)
-
- def close_camera_group(self):
- if self.camera_group is None:
- logger.warning("Camera group does not exist, so it cannot be closed!")
- return
- logger.debug("Closing existing camera group...")
- self.camera_group.close()
- self.shmorchestrator.close_and_unlink()
- self._reset()
- logger.success("Camera group closed successfully")
-
- def start_recording(self):
- self.ipc_flags.record_frames_flag.value = True
- self.ipc_queue.put(self.state_dto())
-
- def stop_recording(self):
- self.ipc_flags.record_frames_flag.value = False
- self.ipc_queue.put(self.state_dto())
-
- def state_dto(self):
- return AppStateDTO.from_state(self)
-
- def _reset(self):
- self.camera_group = None
- self.shmorchestrator = None
- self.current_framerate = None
- self.ipc_flags = IPCFlags(global_kill_flag=self.ipc_flags.global_kill_flag)
-
-
-class AppStateDTO(BaseModel):
- """
- Serializable Data Transfer Object for the AppState
- """
- type: str = "AppStateDTO"
- state_timestamp: str = datetime.now().isoformat()
-
- camera_configs: Optional[CameraConfigs]
- available_devices: Optional[AvailableDevices]
- current_framerate: Optional[CurrentFrameRate]
- record_frames_flag_status: bool
-
- @classmethod
- def from_state(cls, state: FreemocapAppState):
- return cls(
- camera_configs=state.camera_group_configs,
- available_devices=state.available_devices,
- current_framerate=state.current_framerate,
- record_frames_flag_status=state.ipc_flags.record_frames_flag.value,
- )
+ return self.skellycam_app_state.shmorchestrator.multi_frame_escape_ring_shm
diff --git a/freemocap/pipelines/__init__.py b/freemocap/pipelines/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/freemocap/pipelines/images_to_skeletons_pipeline.py b/freemocap/pipelines/images_to_skeletons_pipeline.py
new file mode 100644
index 00000000..95056ace
--- /dev/null
+++ b/freemocap/pipelines/images_to_skeletons_pipeline.py
@@ -0,0 +1,24 @@
+from typing import Dict
+
+from freemocap.pipelines.pipeline_abcs import PipelineStageConfig, PipelineConfig, PipelineData, PipelineStage, \
+ PipelineModel
+
+
+class SkellyTrackerConfig(PipelineStageConfig):
+ model_complexity: int = 1
+
+class SkellyForgeConfig(PipelineStageConfig):
+ confidence_threshold: float = 0.5
+
+
+class ImagesToSkeletonPipelineConfig(PipelineConfig):
+ stage_configs: Dict[str, PipelineStageConfig] = {
+ "skellytracker": SkellyTrackerConfig(),
+ "skellyforge" : SkellyForgeConfig()
+ }
+
+class ImagesToSkeletonPipeline(PipelineModel):
+ config: ImagesToSkeletonPipelineConfig = ImagesToSkeletonPipelineConfig()
+
+ def process_data(self, data: PipelineData) -> PipelineData:
+ return super().process_data(data)
diff --git a/freemocap/pipelines/pipeline_abcs.py b/freemocap/pipelines/pipeline_abcs.py
new file mode 100644
index 00000000..417b5ac6
--- /dev/null
+++ b/freemocap/pipelines/pipeline_abcs.py
@@ -0,0 +1,80 @@
+import logging
+from abc import ABC, abstractmethod
+from multiprocessing import Process, Queue
+from typing import Dict, OrderedDict
+
+from pydantic import BaseModel, Field
+from skellycam.core import CameraId
+
+logger = logging.getLogger(__name__)
+
+
+class PipelineStageConfig(BaseModel, ABC):
+ pass
+
+
+class PipelineConfig(BaseModel, ABC):
+ stage_configs: Dict[str, PipelineStageConfig]
+
+
+class PipelineData(BaseModel, ABC):
+ data: object
+ metadata: dict[object, object] = Field(default_factory=dict)
+
+
+class PipelineStage(BaseModel, ABC):
+ config: PipelineConfig
+
+ @abstractmethod
+ def get_output(self, input_data: PipelineData) -> PipelineData:
+ pass
+
+
+class PipelineModel(BaseModel, ABC):
+ config: PipelineConfig
+ stages: OrderedDict[str, PipelineStage]
+
+ def process_data(self, data: PipelineData) -> PipelineData:
+ logger.loop("Running pipeline")
+ latest_data = data
+ for stage in self.stages.values():
+ logger.info(f"Running stage {stage}")
+ latest_data = stage.process_input(latest_data)
+ return latest_data
+
+
+class CameraProcessingNode(BaseModel, ABC):
+ camera_id: CameraId
+ process: Process
+ input_queue: Queue
+ output_queue: Queue
+
+ @classmethod
+ def create(cls,
+ config: PipelineConfig,
+ camera_id: CameraId,
+ input_queue: Queue,
+ output_queue: Queue):
+ pass
+
+ def start(self):
+ self.process.start()
+
+ def stop(self):
+ self.process.terminate()
+
+ def join(self):
+ self.process.join()
+
+class ProcessTree(ABC):
+ camera_processes: Dict[CameraId, CameraProcessingNode]
+ aggregation_process: Process
+ queues_by_camera_id: Dict[CameraId, Queue]
+ output_queue: Queue
+
+
+class ProcessingServer(BaseModel, ABC):
+ process_tree: ProcessTree
+
+ def process_data(self, data: PipelineData) -> PipelineData:
+ return self.pipeline.process_data(data)
diff --git a/pyproject.toml b/pyproject.toml
index dec83b3b..f653a689 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -6,8 +6,8 @@ readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"aniposelib>=0.7.0",
-# "freemocap-blender-addon",
- "ajc27_freemocap_blender_addon",
+ # "freemocap-blender-addon",
+ "ajc27_freemocap_blender_addon==v2024.12.1032",
"libsass>=0.23.0",
"opencv-contrib-python>=4.8.1.78",
"pyinstaller>=6.11.0",
@@ -17,6 +17,8 @@ dependencies = [
"skellycam",
"skellyforge",
"skellytracker",
+ "pydantic>=2.10.4",
+ # "ltrt"
]
[tool.uv.sources]
@@ -26,6 +28,7 @@ skellyforge = { git = "https://github.com/freemocap/skellyforge" }
skelly-viewer = { git = "https://github.com/freemocap/skellyviewer" }
#freemocap-blender-addon = { git = "https://github.com/freemocap/freemocap_blender_addon"}#, branch = "jon/development" }
skelly-synchronize = { git = "https://github.com/freemocap/skelly_synchronize" }
+#ltrt = { git = "https://github.com/freemocap/LTRT" }
[project.scripts]
freemocap = "freemocap.__main__:main"
diff --git a/uv.lock b/uv.lock
index a9bc3378..b47c36b3 100644
--- a/uv.lock
+++ b/uv.lock
@@ -23,11 +23,11 @@ wheels = [
[[package]]
name = "ajc27-freemocap-blender-addon"
-version = "2024.12.1033"
+version = "2024.12.1032"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/30/fa/e0d919f79062058907c70ea6ceb6194d34715886dc12338e76fb82cf29a5/ajc27_freemocap_blender_addon-2024.12.1033.tar.gz", hash = "sha256:f05d28dcfdd1650ba68be277555a2e5b5d384d23dad076e8de918320d76e361d", size = 1654194 }
+sdist = { url = "https://files.pythonhosted.org/packages/04/e6/0077aa5a43e54b321456633a900ccbb13ee1582cffc599f9b6b2e6ab4d23/ajc27_freemocap_blender_addon-2024.12.1032.tar.gz", hash = "sha256:cc1d01fbdb7b5ed373e8bf1c4eef876bf3688292f9fced36edabb6456d1c8086", size = 1654203 }
wheels = [
- { url = "https://files.pythonhosted.org/packages/f7/6b/bac1c5d976ad2654d4c95e2cab9e8162b05c99e247b4658e78cb9531af0f/ajc27_freemocap_blender_addon-2024.12.1033-py3-none-any.whl", hash = "sha256:65b01abc89005c34c646669d60195148b3279599cb475fee05d80c681533562b", size = 1897867 },
+ { url = "https://files.pythonhosted.org/packages/48/d9/9d87e245b8c58a6dc648e65497a923dfada3156f9a2f3b09e56bfc971683/ajc27_freemocap_blender_addon-2024.12.1032-py3-none-any.whl", hash = "sha256:3b129f3dd7b78ce4f9b03af3fc682c2213f725cbc77805ddfda4e96ff30f8cfe", size = 1897863 },
]
[[package]]
@@ -430,6 +430,7 @@ dependencies = [
{ name = "aniposelib" },
{ name = "libsass" },
{ name = "opencv-contrib-python" },
+ { name = "pydantic" },
{ name = "pyinstaller" },
{ name = "requests" },
{ name = "skelly-synchronize" },
@@ -441,10 +442,11 @@ dependencies = [
[package.metadata]
requires-dist = [
- { name = "ajc27-freemocap-blender-addon" },
+ { name = "ajc27-freemocap-blender-addon", specifier = "==2024.12.1032" },
{ name = "aniposelib", specifier = ">=0.7.0" },
{ name = "libsass", specifier = ">=0.23.0" },
{ name = "opencv-contrib-python", specifier = ">=4.8.1.78" },
+ { name = "pydantic", specifier = ">=2.10.4" },
{ name = "pyinstaller", specifier = ">=6.11.0" },
{ name = "requests", specifier = ">=2.32.3" },
{ name = "skelly-synchronize", git = "https://github.com/freemocap/skelly_synchronize" },
@@ -1529,7 +1531,7 @@ dependencies = [
[[package]]
name = "skellycam"
version = "2023.9.1086"
-source = { git = "https://github.com/freemocap/skellycam?branch=jon%2Fdevelopment#9cca1656fccca7b5e2087401471f2d80864b9778" }
+source = { git = "https://github.com/freemocap/skellycam?branch=jon%2Fdevelopment#af16d58bca84477a604a04d9daa540cafeabf59f" }
dependencies = [
{ name = "fastapi" },
{ name = "httpx" },