forked from HQU-gxy/CVTH3PE
- 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.
139 lines
5.5 KiB
Plaintext
139 lines
5.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"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": {
|
|
"kernelspec": {
|
|
"display_name": ".venv",
|
|
"language": "python",
|
|
"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"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|