forked from HQU-gxy/CVTH3PE
feat: Enhance camera module with new data structures and utility functions
- Introduced dataclass structures for CameraParams and Camera to improve type safety and clarity. - Added Detection dataclass to encapsulate detection data, including keypoints and timestamps. - Implemented classify_by_camera function to organize detections by camera. - Added utility functions for converting points to homogeneous coordinates and calculating distances to lines. - Updated dependencies in pyproject.toml to include new libraries for enhanced functionality.
This commit is contained in:
118
play.ipynb
118
play.ipynb
@ -2,10 +2,116 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"from pathlib import Path\n",
|
||||
"import awkward as ak\n",
|
||||
"import numpy as np\n",
|
||||
"from matplotlib import pyplot as plt\n",
|
||||
"import jax\n",
|
||||
"import jax.numpy as jnp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre>{AE_01: {extrinsic: {rvec: [...], ...}, intrinsic: {...}, keypoints: ..., ...},\n",
|
||||
" AE_1A: {extrinsic: {rvec: [...], ...}, intrinsic: {...}, keypoints: ..., ...},\n",
|
||||
" AE_08: {extrinsic: {rvec: [...], ...}, intrinsic: {...}, keypoints: ..., ...}}\n",
|
||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
|
||||
"backend: cpu\n",
|
||||
"nbytes: 5.9 MB\n",
|
||||
"type: {\n",
|
||||
" AE_01: {\n",
|
||||
" extrinsic: {\n",
|
||||
" rvec: var * float64,\n",
|
||||
" tvec: var * float64\n",
|
||||
" },\n",
|
||||
" intrinsic: {\n",
|
||||
" camera_matrix: var * var * float64,\n",
|
||||
" distortion_coefficients: var * float64\n",
|
||||
" },\n",
|
||||
" keypoints: var * var * var * float64,\n",
|
||||
" confidences: var * var * float64,\n",
|
||||
" matrix: var * var * float64,\n",
|
||||
" projection_matrix: var * var * float64\n",
|
||||
" },\n",
|
||||
" AE_1A: {\n",
|
||||
" extrinsic: {\n",
|
||||
" rvec: var * float64,\n",
|
||||
" tvec: var * float64\n",
|
||||
" },\n",
|
||||
" intrinsic: {\n",
|
||||
" camera_matrix: var * var * float64,\n",
|
||||
" distortion_coefficients: var * float64\n",
|
||||
" },\n",
|
||||
" keypoints: var * var * var * float64,\n",
|
||||
" confidences: var * var * float64,\n",
|
||||
" matrix: var * var * float64,\n",
|
||||
" projection_matrix: var * var * float64\n",
|
||||
" },\n",
|
||||
" AE_08: {\n",
|
||||
" extrinsic: {\n",
|
||||
" rvec: var * float64,\n",
|
||||
" tvec: var * float64\n",
|
||||
" },\n",
|
||||
" intrinsic: {\n",
|
||||
" camera_matrix: var * var * float64,\n",
|
||||
" distortion_coefficients: var * float64\n",
|
||||
" },\n",
|
||||
" keypoints: var * var * var * float64,\n",
|
||||
" confidences: var * var * float64,\n",
|
||||
" matrix: var * var * float64,\n",
|
||||
" projection_matrix: var * var * float64\n",
|
||||
" }\n",
|
||||
"}</pre>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<Record {AE_01: {...}, AE_1A: {...}, ...} type='{AE_01: {extrinsic: {rvec: ...'>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"DATASET_PATH = Path(\"samples/camera_dataset.parquet\")\n",
|
||||
"AK_CAMERA_DATASET: ak.Array = ak.from_parquet(DATASET_PATH)[0]\n",
|
||||
"display(AK_CAMERA_DATASET)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from app.camera import Camera, CameraParams\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def preprocess(key:str, record: ak.Record) -> Camera:\n",
|
||||
" K = jnp.array(ak.to_numpy(record[\"intrinsic\"][\"camera_matrix\"])) # type: ignore\n",
|
||||
" Rt = jnp.array(ak.to_numpy(record[\"matrix\"]))\n",
|
||||
" dist_coeffs = jnp.array(ak.to_numpy(record[\"intrinsic\"][\"distortion_coefficients\"])) # type: ignore\n",
|
||||
" size = (2560, 1440)\n",
|
||||
" return Camera(id=key, params=CameraParams(K=K, Rt=Rt, dist_coeffs=dist_coeffs), size=size)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"CAMERA_DATASET = {key: preprocess(key, AK_CAMERA_DATASET[key]) for key in AK_CAMERA_DATASET.fields} # type: ignore"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@ -15,7 +121,15 @@
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.9"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user