Giter VIP home page Giter VIP logo

camera-calibration-with-picamera2-opencv's Introduction

Camera Calibration with PiCamera2 and/or OpenCV

combined

The new camera stack of the systems Bullseye 32-bit and 64-bit does not work with OpenCV for video applications, for this you have to activate the old camera stack, but with mismatch of the function of the new library PiCamera2.

In principle, it is possible to configure the camera for the PiCamera2 library using a tuning_file (https://www.raspberrypi.com/documentation/computers/camera_software.html#more-about-libcamera). These files are .json files which allow to adjust the adjustable parameters for the specific camera model. The parameters have been determined specifically for each camera sensor, so that a manual calibration (chapter 6 https://datasheets.raspberrypi.com/camera/raspberry-pi-camera-guide.pdf) is normally not necessary. If you do, you can consult the documentation of the parameters and experiment with them yourself.

The adjustment of the camera used with this tuning_file offers a lot of adjustment, but you cannot fix lens distortion like radial/tangential distortion with it. For this purpose, however, the special camera calibration using Camera Calibration can be used.

Thus it is theoretically possible to use the tuning parameters with PiCamera2 as well as the non-distortion of OpenCV for the camera recording.

Current options to use a camera with different API's

PiCamera2 OpenCV PiCamera2&OpenCV
- use the .json tuning_file with a lot of algorithms (12) for RPi cameras - Enable the old camera-stack for RPi and use the camera calibration for undistortion with the OpenCV provided algorithms (16) (more than PiCamera2) - works, but the stream is very slow (suggestions for improvement welcome github_calibtest.py ir_cut_picamera2_array.py)

Howto: camera calibration

If you intend to calibrate your camera independently of PiCamera2 due to strong distortion, I provide the following scripts. The first script is used for capturing with a 5 second timer, which is basically used for creating the images for the camera calibration.

Take and save pictures with self-triggered timer:

ir_cut_picamera2_timer.py: 

This second script loads the calibration images of the default folder "calib_images" you have taken with the ir_cut_picamera2_timer.pyscript. Further you must give the folder, where the undistorted images after calibration get saved. The last argument is the board dimension, which must be given correctly, because many people make a mistake here, which causes that the algorithms can't find all corners and return False for some calibration images.

python3 calibrate_camera.py --imgdir=calib_imabes --savedir=undistorted_images --board=9x6

The script needs the destination, where the calibration images for OpenCV Camera Calibration get saved. Additionally you can adjust the time before a picture is taken, to position the chessboard before taking the image. To achieve a sufficient accuracy it's recommended to take between 10-20 (or more) images of the chessboard.

sudo python3 ir_cut_picamera2_timer.py --imgdir=calibration_images --res=1920x1080 --time=5

Note: Further information here Camera Calibration.

camera-calibration-with-picamera2-opencv's People

Contributors

petros626 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.