{"id":24576124,"url":"https://github.com/edouardrolland/camera_calibration","last_synced_at":"2026-04-18T04:01:54.348Z","repository":{"id":271553932,"uuid":"913826006","full_name":"edouardrolland/camera_calibration","owner":"edouardrolland","description":"This repository is for performing camera calibration with OpenCV.","archived":false,"fork":false,"pushed_at":"2025-09-09T19:01:17.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-09T23:00:18.393Z","etag":null,"topics":["camera-calibration","opencv"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edouardrolland.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-08T12:30:31.000Z","updated_at":"2025-09-09T19:01:20.000Z","dependencies_parsed_at":"2025-01-08T13:49:41.370Z","dependency_job_id":null,"html_url":"https://github.com/edouardrolland/camera_calibration","commit_stats":null,"previous_names":["edouardrolland/camera_calibration"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/edouardrolland/camera_calibration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edouardrolland%2Fcamera_calibration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edouardrolland%2Fcamera_calibration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edouardrolland%2Fcamera_calibration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edouardrolland%2Fcamera_calibration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edouardrolland","download_url":"https://codeload.github.com/edouardrolland/camera_calibration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edouardrolland%2Fcamera_calibration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31955919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camera-calibration","opencv"],"created_at":"2025-01-23T22:21:37.857Z","updated_at":"2026-04-18T04:01:54.327Z","avatar_url":"https://github.com/edouardrolland.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Camera Calibration\n\nThis repository contains a script that performs **camera calibration** using a video file containing a chessboard pattern. The script automatically detects the chessboard corners in each video frame, collects both the 3D real-world coordinates and their corresponding 2D image coordinates, and then computes the camera calibration parameters (camera matrix and distortion coefficients).\n\n---\n\n## How It Works\n\n1. **Chessboard Detection**  \n   The script reads each frame from the provided video file and uses OpenCV’s `cv.findChessboardCornersSB` function to detect the chessboard corners.\n   \n2. **Automatic Frame Collection**  \n   Whenever the chessboard is detected in a frame, the 3D coordinates (`objp`) and the detected 2D corners (`corners`) are automatically saved in two lists: \n   - `objpoints`: A list of arrays containing the 3D real-world points for each detected chessboard.  \n   - `imgpoints`: A list of arrays containing the 2D image coordinates for each detected chessboard.\n\n3. **Calibration Computation**  \n   Once the entire video has been processed (or the user quits by pressing **q**), if at least one valid detection was recorded, OpenCV’s `cv.calibrateCamera` function is called to compute the camera matrix and distortion coefficients.\n\n4. **Results**  \n   The script prints:\n   - **RMS Reprojection Error**: A measure of how well the detected points fit the computed camera model.  \n   - **Camera Matrix**: Intrinsic parameters of the camera, including focal lengths and principal point.  \n   - **Distortion Coefficients**: Radial and tangential distortion coefficients.\n\n---\n\n## Requirements\n\n- **Python 3**  \n- **OpenCV 4.x** (including the `cv2` Python module)  \n- **NumPy**\n\nUse the following command to install the required packages if needed:\n```bash\npip install opencv-python numpy\n```\n\n---\n\n## Script Overview\n\n- **Global Parameters**  \n  - `IS_CAP_STREAM (bool)`: Toggle between using a video file or a live camera feed (not used in the default script flow).  \n  - `SHOW_FRAMES (bool)`: Whether to display frames in a window during processing.  \n  - `GRID_SHAPE (tuple)`: The number of *inner* corners (rows, columns) on the chessboard.  \n  - `SQUARE_SIZE (float)`: The physical size of each chessboard square, in meters.  \n  - `CALLIB_VIDEO (str)`: Path to the video file for calibration.\n\n- **Variables**  \n  - `objp (ndarray)`: A single array of 3D points for the chessboard corners.  \n  - `objpoints (list)`: Accumulated 3D points for all valid frames.  \n  - `imgpoints (list)`: Accumulated 2D image points for all valid frames.  \n\n- **Main Functions**  \n  - `cv.findChessboardCornersSB`: Detects chessboard corners in a grayscale image.  \n  - `cv.drawChessboardCorners`: Visualizes the detected corners.  \n  - `cv.calibrateCamera`: Computes the final calibration (camera matrix \u0026 distortion coefficients).  \n\n---\n\n## Usage\n\n1. **Place Your Video**  \n   Edit `CALLIB_VIDEO` in the script or place your video file in the correct path so that `CALLIB_VIDEO` points to it:\n   ```python\n   CALLIB_VIDEO = \"path/to/your_chessboard_video.mp4\"\n   ```\n\n2. **Run the Script**  \n   From your terminal or command prompt:\n   ```bash\n   python file_video.py\n   ```\n   - The script will open a display window (if `SHOW_FRAMES` is `True`) and start reading the video.  \n   - Each time a valid chessboard is detected, a message is printed (`Frame added! ...`).\n\n3. **Quit**  \n   - Press **q** to stop the script at any time.\n\n4. **Calibration Results**  \n   - At the end of the video (or when you press **q**), the script will compute the calibration if it has at least one valid detection.  \n   - It prints the **RMS Reprojection Error**, **Camera Matrix**, and **Distortion Coefficients**.\n\n---\n\n## Notes \u0026 Tips\n\n1. **Chessboard Requirements**  \n   - Ensure that the chessboard used has the same number of *inner* corners as specified by `GRID_SHAPE`.  \n   - For `GRID_SHAPE = (9, 14)`, the actual chessboard has 10 x 15 squares, but 9 x 14 inner corners.\n\n2. **Video Quality**  \n   - Proper lighting and minimal motion blur will improve corner detection reliability.  \n   - If the chessboard is partially out of the frame or the image is too blurry, OpenCV may fail to detect the corners.\n\n3. **Adjustments**  \n   - If you want to tune calibration flags (e.g., fix different camera parameters or refine extrinsics), modify the `flags` parameter in `cv.calibrateCamera`.\n   - If you want to see frames during processing but in a smaller or bigger window, edit the lines:\n     ```python\n     cv.namedWindow('img', cv.WND_PROP_FULLSCREEN)\n     cv.resizeWindow(\"img\", 1280, 720)\n     ```\n   - You can also set `SHOW_FRAMES` to `False` to disable the display.\n\n4. **Resources**  \n   - [OpenCV Camera Calibration Documentation](https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html)\n\n---\n\n## Example Output\n\nAn example of final output might look like:\n```\nFrame added! Total number of frames: 1\n...\nFrame added! Total number of frames: 7\nRMS reprojection error: 0.323123\nCamera matrix:\n[[1.06017536e+03 0.00000000e+00 9.53719306e+02]\n [0.00000000e+00 1.05893628e+03 5.40939057e+02]\n [0.00000000e+00 0.00000000e+00 1.00000000e+00]]\nDistortion coefficients:\n[[-0.28340811  0.07395907  0.00019359  0.00001714  0.00000000]]\n```\nIn this example, the **RMS reprojection error** is around 0.32, which is acceptable for many applications, and you can see the resulting **camera matrix** and **distortion coefficients**.\n\n---\n\n## License\n\nThis project is distributed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n**Authors**:  \n- Edouard G. A. Rolland  \n- Kilian Meier  \n\nFor more information, consult the [OpenCV camera calibration documentation](https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedouardrolland%2Fcamera_calibration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedouardrolland%2Fcamera_calibration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedouardrolland%2Fcamera_calibration/lists"}