Skip to content

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

TypeScript

ok, seems mostly running good?

jonmatthis8f82c5624aed
diff --git a/freemocap/api/http/ui/ui.html b/freemocap/api/http/ui/ui.html
index 04e7db47..ae68bafd 100644
--- a/freemocap/api/http/ui/ui.html
+++ b/freemocap/api/http/ui/ui.html
@@ -46,6 +46,8 @@
let isConnected = false;
const websocket_url = 'ws://localhost:8005/websocket/connect';
const imageElements = {};
+ const spheres = {};
+ let scene; // Declare scene globally
function updateStatus() {
document.getElementById('ws-status').innerText = isConnected ? 'Connected' : 'Disconnected';
@@ -80,37 +82,49 @@
// Now you can use the data object to update your UI
updateImages(data.jpeg_images);
- // updateSpheres(data.object_points);
+ updateSpheres(data.latest_pipeline_output?.aggregation_layer_output?.points3d);
} else {
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]);
+ function updateSpheres(points3d) {
+ if (!points3d) {
+ return; // Exit the function if points3d is undefined or null
}
- // 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);
- });
- }
+ // Mark all spheres as not updated
+ for (const id in spheres) {
+ spheres[id].updated = false;
+ }
- function sendMessage(message) {
- if (isConnected) {
- ws.send(message);
- } else {
- alert('WebSocket is not connected.');
+ for (const [point_id, coords] of Object.entries(points3d)) {
+ if (!spheres[point_id]) {
+ // Create a new sphere
+ const geometry = new THREE.SphereGeometry(1, 10, 10);
+ const material = new THREE.MeshBasicMaterial({color: 0xff0000});
+ const sphere = new THREE.Mesh(geometry, material);
+ scene.add(sphere);
+ spheres[point_id] = {mesh: sphere, updated: true};
+ } else {
+ // Update existing sphere position
+ spheres[point_id].mesh.position.set(coords.x, coords.y, coords.z);
+ spheres[point_id].updated = true;
+ }
+ }
+
+ // Hide spheres not in the current payload
+ for (const id in spheres) {
+ if (!spheres[id].updated) {
+ spheres[id].mesh.visible = false;
+ } else {
+ spheres[id].mesh.visible = true;
+ }
}
}
+
function updateImages(images) {
const container = document.getElementById('images-container');
for (const cameraId in images) {
@@ -156,8 +170,14 @@
function initThreeJS() {
const container = document.getElementById('threejs-container');
- const scene = new THREE.Scene();
+ scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
+ // add light
+ const light = new THREE.DirectionalLight(0xffffff, 1);
+ light.position.set(1, 1, 1).normalize();
+ scene.add(light);
+
+
const renderer = new THREE.WebGLRenderer();
renderer.setSize(container.clientWidth, container.clientHeight);
container.appendChild(renderer.domElement);
@@ -170,7 +190,7 @@
scene.add(gridHelper);
camera.position.y = 5;
- camera.position.z = 15;
+ camera.position.z = 25;
function animate() {
requestAnimationFrame(animate);
@@ -196,9 +216,9 @@
<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/close')">Close Camera Connections</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>-->
diff --git a/freemocap/pipelines/calibration_pipeline/calibration_aggregation_node.py b/freemocap/pipelines/calibration_pipeline/calibration_aggregation_node.py
index 7e582bf6..7e4af309 100644
--- a/freemocap/pipelines/calibration_pipeline/calibration_aggregation_node.py
+++ b/freemocap/pipelines/calibration_pipeline/calibration_aggregation_node.py
@@ -157,15 +157,15 @@ class CalibrationAggregationProcessNode(BaseAggregationNode):
multi_frame_number = frame_numbers.pop()
# Accumulate shared views
incoming_data.append(camera_node_incoming_data)
- shared_view_accumulator.receive_camera_node_output(multi_frame_number=multi_frame_number,
- camera_node_output=camera_node_incoming_data)
- logger.trace(f"Shared view accumulator:\n {json.dumps(shared_view_accumulator.shared_views_per_camera_by_camera, indent=2)}")
+ # shared_view_accumulator.receive_camera_node_output(multi_frame_number=multi_frame_number,
+ # camera_node_output=camera_node_incoming_data)
+ # logger.trace(f"Shared view accumulator:\n {json.dumps(shared_view_accumulator.shared_views_per_camera_by_camera, indent=2)}")
output = CalibrationPipelineOutputData(camera_node_output=camera_node_incoming_data, # type: ignore
aggregation_layer_output=CalibrationAggregationLayerOutputData(
multi_frame_number=multi_frame_number,
points3d={camera_id: (camera_id, np.sin(camera_id)*10, np.cos(camera_id)*10) for
camera_id in input_queues.keys()},
- data=shared_view_accumulator.model_dump()
+ # data=shared_view_accumulator.model_dump()
)
)
diff --git a/freemocap/pipelines/calibration_pipeline/calibration_camera_node.py b/freemocap/pipelines/calibration_pipeline/calibration_camera_node.py
index 10fe2fbb..b3504bed 100644
--- a/freemocap/pipelines/calibration_pipeline/calibration_camera_node.py
+++ b/freemocap/pipelines/calibration_pipeline/calibration_camera_node.py
@@ -14,8 +14,7 @@ from skellytracker.trackers.charuco_tracker.charuco_observation import CharucoOb
from freemocap.pipelines.calibration_pipeline.single_camera_calibrator import SingleCameraCalibrator, \
SingleCameraCalibrationEstimate
-from freemocap.pipelines.pipeline_abcs import BaseCameraNode, BasePipelineStageConfig, BasePipelineData, \
- BaseCameraNodeOutputData
+from freemocap.pipelines.pipeline_abcs import BaseCameraNode, BasePipelineStageConfig, BaseCameraNodeOutputData
logger = logging.getLogger(__name__)
@@ -29,19 +28,13 @@ class CalibrationPipelineCameraNodeConfig(BasePipelineStageConfig):
class CalibrationCameraNodeOutputData(BaseCameraNodeOutputData):
frame_metadata: FrameMetadata
charuco_observation: CharucoObservation
- calibration_estimate: SingleCameraCalibrationEstimate
+ calibration_estimate: SingleCameraCalibrationEstimate | None = None
@property
def can_see_target(self) -> bool:
return not self.charuco_observation.charuco_empty
- def to_serializable_dict(self) -> dict:
- return dict(
- frame_metadata=self.frame_metadata.model_dump(),
- charuco_observation=self.charuco_observation.to_serializable_dict(),
- calibration_estimate=self.calibration_estimate.to_serializable_dict(),
- can_see_target=self.can_see_target,
- )
+
@dataclass
class CalibrationCameraNode(BaseCameraNode):
@classmethod
diff --git a/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py b/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py
index fe68c8b9..3f4f1d17 100644
--- a/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py
+++ b/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py
@@ -20,31 +20,7 @@ class SingleCameraCalibrationEstimate(BaseModel):
distortion_coefficients: NDArray[Shape["5"], np.float64]
mean_reprojection_errors: list[float]
camera_calibration_residuals: list[float]
- charuco_observations: CharucoObservations
- object_points_views: list[NDArray[Shape["*, 3"], np.float32]]
- image_points_views: list[NDArray[Shape["*, 2"], np.float32]]
- rotation_vectors: list[NDArray[Shape["*, 3"], np.float64]]
- translation_vectors: list[NDArray[Shape["*, 3"], np.float64]]
reprojection_error_by_view: list[float]
- #
- # def to_serializable_dict(self ):
- # d = {
- # "camera_matrix": self.camera_matrix.tolist() if self.camera_matrix is not None else None,
- # "distortion_coefficients": self.distortion_coefficients.tolist() if self.distortion_coefficients is not None else None,
- # "mean_reprojection_errors": self.mean_reprojection_errors if self.mean_reprojection_errors else None,
- # "camera_calibration_residuals": self.camera_calibration_residuals if self.camera_calibration_residuals else None,
- # "charuco_observations": [obs.to_serializable_dict() for obs in self.charuco_observations] if self.charuco_observations else None,
- # "object_points_views": [obj.tolist() for obj in self.object_points_views] if self.object_points_views else None,
- # "image_points_views": [img.tolist() for img in self.image_points_views] if self.image_points_views else None,
- # "rotation_vectors": [rot.tolist() for rot in self.rotation_vectors] if self.rotation_vectors else None,
- # "translation_vectors": [trans.tolist() for trans in self.translation_vectors] if self.translation_vectors else None,
- # "reprojection_error_by_view": self.reprojection_error_by_view if self.reprojection_error_by_view else None,
- # }
- # try:
- # json.dumps(d).encode('utf-8')
- # except Exception as e:
- # raise ValueError(f"Failed to serialize SingleCameraCalibrationDTO to JSON: {e}")
-
class SingleCameraCalibrator(BaseModel):
"""
@@ -246,10 +222,11 @@ class SingleCameraCalibrator(BaseModel):
distortion_coefficients=self.distortion_coefficients,
mean_reprojection_errors=self.mean_reprojection_errors,
camera_calibration_residuals=self.camera_calibration_residuals,
- charuco_observations=self.charuco_observations,
- object_points_views=self.object_points_views,
- image_points_views=self.image_points_views,
- rotation_vectors=self.rotation_vectors,
- translation_vectors=self.translation_vectors,
reprojection_error_by_view=self.reprojection_error_by_view,
+ # charuco_observations=self.charuco_observations,
+ # object_points_views=self.object_points_views,
+ # image_points_views=self.image_points_views,
+ # rotation_vectors=self.rotation_vectors,
+ # translation_vectors=self.translation_vectors,
+ #
)