This repository contains small scripts for camera calibration and for inspecting/editing mocap point files used during extrinsic calibration.
Many scripts assume a “dataset root” folder that contains at least:
<dataset_root>/
├── mocap_points/
│ ├── <name>.txt
│ └── ...
└── extrinsic_images/
├── <name>.jpg (or .png/.jpeg/...)
└── ...
Notes:
- Each
mocap_points/<name>.txtis whitespace-separatedx y zper line. - Image matching is done by filename stem (
<name>).
Script: plot_mocap_points.py
Purpose:
- Live 3D viewer for a mocap
.txtfile (points are labeled with their row index). - Auto-refreshes when the currently viewed file changes on disk.
- Lets you navigate adjacent numbered files and apply in-place transforms.
- Shows a preview of the matching image from
extrinsic_images/.
How to run:
python plot_mocap_points.pyInitial configuration (top of file):
file_path: initial mocap file to open.adjust_sector_size: the “sector size” used by the reverse operation (default8).sort_size:(rows, cols)grid size used for the flip logic (default(6, 8)).
UI controls:
Prev/Next: switches_Nindex in the filename (e.g.,Foo_4.txt→Foo_5.txt).Reverse sectors (...): reverses the order within each sector (everyadjust_sector_sizelines), writing back to the same file.Sort file: sorts points and writes back to the same file.dataset root+Browse: change to another dataset folder containingmocap_points/(+extrinsic_images/for preview).
Sorting controls (right panel):
perspective:auto/left/right/center.autoinfers from folder names (e.g.,left,right,middle,center).x_flip/fb_flip: optional grid flips after sorting.x_flip= reverse each row (left/right inversion).fb_flip= reverse row order (front/back inversion).
rows/cols: grid dimensions used for flips.u-axis/v-axis: optional axis override for sorting (none,x,-x,y,-y,z,-z).- Sorting rule: sort by
vdescending (top→down), then byuascending (left→right).
- Sorting rule: sort by
Important:
Reverse sectorsandSort filemodify the viewed.txtin-place. Keep a copy if you need to preserve the original.Browseusestkinter. If it’s unavailable, paste the dataset path into thedataset rootbox and press Enter.
Script: main_cali_all.py
What it does:
- Intrinsic calibration using chessboard images (OpenCV) and writes
intrinsic.json. - Extrinsic calibration using
solvePnPper image and writesextrinsics.json(also includes reprojection errors andbest_extrinsic).
Before running:
- Edit the constants near the top of
main_cali_all.py:chessboard_rows,chessboard_cols,chessboard_length_mminput_folder(your dataset root)
Expected inputs (per current code):
- Images:
<input_folder>/extrinsic_images/*.jpg - Mocap points:
<input_folder>/mocap_points/sorted/<image_stem>.txt
Run:
python main_cali_all.pyOutputs:
<input_folder>/intrinsic.json<input_folder>/extrinsics.json<input_folder>/ChessboardCorners/(if enabled)<input_folder>/undistorted_images/
Script: cap.py
- Opens webcam index
0, shows a live view. - Press
Qto save a frame intocalibration_images/. - Press
Escto quit.
Script: rotate_images.py
- Rotates all
.jpgimages in a configured folder (in-place). - Edit
folder_pathanddegrees_to_rotatein the script.
Script: map_mocap_points.py
- Demonstration code that:
- parses an OptiTrack CSV,
- maps markers to a Human3.6M-like ordering,
- loads
intrinsic.json+extrinsics.json, - projects 3D points to 2D using OpenCV and overlays them on a video.
It is a demo script: edit the file paths in __main__ to your local data.
Minimum commonly used packages:
pip install numpy pandas matplotlib opencv-pythonOptional (only for rotate_images.py):
pip install pillow