Skip to content

Free Motion Capture for Everyone 💀✨

TypeScript

ui displays a dumb 3d grid

jonmatthis0c9d5a61061f
diff --git a/freemocap/api/http/ui/ui.html b/freemocap/api/http/ui/ui.html
index fbdedbc5..035f3c0b 100644
--- a/freemocap/api/http/ui/ui.html
+++ b/freemocap/api/http/ui/ui.html
@@ -24,8 +24,24 @@
font-size: small;
}
+ #threejs-container {
+ width: 40%;
+ height: 400px;
+ }
+
+ #content-container {
+ display: flex;
+ justify-content: space-between;
+ }
+
+ #images-container {
+ width: 55%;
+ }
</style>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
+
<script>
+
let ws;
let isConnected = false;
const websocket_url = 'ws://localhost:8005/websocket/connect';
@@ -61,16 +77,32 @@
// Parse the JSON string to a JavaScript object
const data = JSON.parse(jsonString);
addLogEntry(`Received message with length: ${jsonString.length} from mf_payload# ${data.multi_frame_number}`);
- console.log(`Received message with length: ${jsonString.length} from mf_payload# ${data.multi_frame_number}`);
// Now you can use the data object to update your UI
updateImages(data.jpeg_images);
+ // updateSpheres(data.object_points);
} else {
- console.error("Received data is not a Blob.");
+ console.log("Received data: ", event.data);
}
};
}
+ function updateCharucoSpheres(objectPoints) {
+ // Remove existing spheres
+ while (scene.children.length > 2) { // Keep the axes and grid helpers
+ scene.remove(scene.children[2]);
+ }
+
+ // Add new spheres
+ objectPoints.forEach(point => {
+ const geometry = new THREE.SphereGeometry(0.1, 10, 10);
+ const material = new THREE.MeshBasicMaterial({color: 0xff0000});
+ const sphere = new THREE.Mesh(geometry, material);
+ sphere.position.set(point.x, point.y, point.z);
+ scene.add(sphere);
+ });
+ }
+
function sendMessage(message) {
if (isConnected) {
ws.send(message);
@@ -102,6 +134,11 @@
const logEntry = document.createElement('div');
logEntry.innerText = entry;
logContainer.prepend(logEntry);
+
+ // Limit the number of log entries to 30
+ if (logContainer.children.length > 30) {
+ logContainer.removeChild(logContainer.lastChild);
+ }
}
async function callApi(endpoint, method = 'GET') {
@@ -116,6 +153,34 @@
addLogEntry(`Error: ${endpoint} - ${error.message}`);
}
}
+
+ function initThreeJS() {
+ const container = document.getElementById('threejs-container');
+ const scene = new THREE.Scene();
+ const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
+ const renderer = new THREE.WebGLRenderer();
+ renderer.setSize(container.clientWidth, container.clientHeight);
+ container.appendChild(renderer.domElement);
+
+
+ const axesHelper = new THREE.AxesHelper(5);
+ scene.add(axesHelper);
+
+ const gridHelper = new THREE.GridHelper(10, 10);
+ scene.add(gridHelper);
+
+ camera.position.y = 5;
+ camera.position.z = 15;
+
+ function animate() {
+ requestAnimationFrame(animate);
+ renderer.render(scene, camera);
+ }
+
+ animate();
+ }
+
+ window.onload = initThreeJS;
</script>
</head>
<body>
@@ -131,26 +196,30 @@
<button onclick="callApi('http://localhost:8005/skellycam/cameras/connect/detect')">Connect to Cameras</button>
<div>
- <button onclick="callApi('http://localhost:8005/skellycam/cameras/connect/apply', 'POST')">Connect/Update Cameras</button>
+ <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>
-<!-- &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>-->
+ <!-- &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>-->
-<!-- &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>-->
+ <!-- &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>
+<!-- Content Container -->
+<div id="content-container">
+ <!-- Three.js Viewer Section -->
+ <div id="threejs-container"></div>
+ <!-- Images Section -->
+ <div id="images-container"></div>
</div>
-<!-- Results and Logs Section -->
-<pre id="result"></pre>
-<h2>Images</h2>
-<div id="images-container"></div>
<h3>Loggs</h3>
<div id="log-container"></div>
diff --git a/freemocap/api/websocket/websocket_server.py b/freemocap/api/websocket/websocket_server.py
index b7dff76f..32d07763 100644
--- a/freemocap/api/websocket/websocket_server.py
+++ b/freemocap/api/websocket/websocket_server.py
@@ -13,7 +13,7 @@ from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
from freemocap.freemocap_app.freemocap_app_state import get_freemocap_app_state, FreemocapAppState
from freemocap.pipelines.calibration_pipeline import CalibrationProcessingServer
-from freemocap.pipelines.dummy_pipeline import DummyProcessingServer
+from freemocap.pipelines.calibration_pipeline.calibration_aggregation_node import CalibrationPipelineOutputData
from freemocap.pipelines.pipeline_abcs import ReadTypes, BaseProcessingServer
logger = logging.getLogger(__name__)
@@ -94,7 +94,7 @@ class FreemocapWebsocketServer:
camera_group_uuid = None
latest_mf_number = -1
- processing_server: BaseProcessingServer|None = None #Starts when camera group is detected, should probably be handled differently but this works fn
+ processing_server: BaseProcessingServer | None = None # Starts when camera group is detected, should probably be handled differently but this works fn
try:
while True:
await async_wait_1ms()
@@ -114,7 +114,7 @@ class FreemocapWebsocketServer:
camera_group_uuid = self._freemocap_app_state.skellycam_app_state.camera_group.uuid
if processing_server:
processing_server.shutdown_pipeline()
- processing_server:CalibrationProcessingServer = self._freemocap_app_state.create_processing_server()
+ processing_server: CalibrationProcessingServer = self._freemocap_app_state.create_processing_server()
processing_server.start()
continue
@@ -126,12 +126,11 @@ class FreemocapWebsocketServer:
camera_configs=self._freemocap_app_state.camera_configs,
retrieve_type=ReadTypes.LATEST.value)
-
if processing_server:
processing_server.intake_data(mf_payload)
- mf_payload = processing_server.annotate_images(mf_payload)
+ mf_payload, latest_pipeline_output = processing_server.annotate_images(mf_payload)
- await self._send_frontend_payload(mf_payload)
+ await self._send_frontend_payload(mf_payload, latest_pipeline_output)
latest_mf_number = mf_payload.multi_frame_number
@@ -144,7 +143,9 @@ class FreemocapWebsocketServer:
raise
async def _send_frontend_payload(self,
- mf_payload: MultiFramePayload):
+ mf_payload: MultiFramePayload,
+ latest_pipeline_output: CalibrationPipelineOutputData | None = None
+ ):
frontend_payload = FrontendFramePayload.from_multi_frame_payload(multi_frame_payload=mf_payload)
logger.loop(f"Sending frontend payload through websocket...")
@@ -154,7 +155,7 @@ class FreemocapWebsocketServer:
await self.websocket.send_bytes(frontend_payload.model_dump_json().encode('utf-8'))
+
if not self.websocket.client_state == WebSocketState.CONNECTED:
logger.error("Websocket shut down while sending payload!")
raise RuntimeError("Websocket shut down while sending payload!")
-
diff --git a/freemocap/pipelines/pipeline_abcs.py b/freemocap/pipelines/pipeline_abcs.py
index b80c735b..360a4678 100644
--- a/freemocap/pipelines/pipeline_abcs.py
+++ b/freemocap/pipelines/pipeline_abcs.py
@@ -278,11 +278,11 @@ class BaseProcessingPipeline(ABC):
return self.latest_pipeline_data
- def annotate_images(self, multiframe_payload: MultiFramePayload) -> MultiFramePayload:
+ def annotate_images(self, multiframe_payload: MultiFramePayload) -> tuple[MultiFramePayload, BasePipelineOutputData | None]:
pipeline_output = self.get_output_for_frame(target_frame_number=multiframe_payload.multi_frame_number)
if pipeline_output is None:
- return multiframe_payload
- return self.annotator.annotate_images(multiframe_payload, pipeline_output)
+ return multiframe_payload, None
+ return self.annotator.annotate_images(multiframe_payload, pipeline_output) , pipeline_output
@@ -328,7 +328,7 @@ class BaseProcessingServer(ABC):
def intake_data(self, multiframe_payload: MultiFramePayload):
self.processing_pipeline.intake_data(multiframe_payload)
- def annotate_images(self, multiframe_payload: MultiFramePayload) -> MultiFramePayload:
+ def annotate_images(self, multiframe_payload: MultiFramePayload) -> tuple[MultiFramePayload, BasePipelineOutputData | None]:
return self.processing_pipeline.annotate_images(multiframe_payload)
def shutdown_pipeline(self):
diff --git a/freemocap/system/logging_configuration/log_test_messages.py b/freemocap/system/logging_configuration/log_test_messages.py
index 76736cae..92e679e8 100644
--- a/freemocap/system/logging_configuration/log_test_messages.py
+++ b/freemocap/system/logging_configuration/log_test_messages.py
@@ -18,14 +18,14 @@ def log_test_messages(logger: logging.Logger):
def print_log_level_messages(logger):
- logger.loop("This is a LOOP message, value `4` -> For logs that are printed in a loop")
- logger.trace("This is a TRACE message, value `5` -> Low level logs for deep debugging")
- logger.debug("This is a DEBUG message, value `10` -> Detailed information for devs and curious folk")
- logger.info("This is an INFO message, value `20` -> General information about the program")
- logger.success("This is a SUCCESS message, value `22` -> OMG, something worked :O")
- logger.api("This is an API message, value `25` -> About API calls/responses")
+ logger.loop("This is (an example of) a LOOP message, value `4` -> For logs that are printed in a loop")
+ logger.trace("This is (an example of) a TRACE message, value `5` -> Low level logs for deep debugging")
+ logger.debug("This is (an example of) a DEBUG message, value `10` -> Detailed information for devs and curious folk")
+ logger.info("This is (an example of) an INFO message, value `20` -> General information about the program")
+ logger.success("This is (an example of) a SUCCESS message, value `22` -> OMG, something worked :O")
+ logger.api("This is (an example of) an API message, value `25` -> About API calls/responses")
logger.warning(
- "This is a WARNING message, value `30` -> Something unexpected happened, but it's not necessarily an error"
+ "This is (an example of) a WARNING message, value `30` -> Something unexpected happened, but it's not necessarily an error"
)
- logger.error("This is an ERROR message, value `40` -> Indicates that something went wrong")
+ logger.error("This is (an example of) an ERROR message, value `40` -> Indicates that something went wrong")
print("----------This is a regular ol' print message.------------------")