documentation:vision:camera_calibration

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
documentation:vision:camera_calibration [2023/01/22 21:24] – [Computing the Instrinsic Parameters] pontusrdocumentation:vision:camera_calibration [2023/01/25 05:49] (current) marcusn
Line 5: Line 5:
 ===== OpenCV ===== ===== OpenCV =====
  
-This approach is based on the opencv documentation for camera calibration in the following [[https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html | link]]. The repository in the following [[https://git.cs.lth.se/robotlab/camera_calibration | link]] implements camera calibration with as well as picture taking with realsense cameras. This repository was written by Pontus Rosqvist, Josefin Gustafsson, Markus Nagy and Martin Lyrå.+This approach is based on the opencv documentation for camera calibration in the following [[https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html | link]]. The repository in the following [[https://git.cs.lth.se/robotlab/camera_calibration | link]] implements camera calibration with as well as picture taking with realsense cameras. This repository was written by Pontus Rosqvist, Josefin Gustafsson, Marcus Nagy and Martin Lyrå.
  
 The code for camera calibration expects images of checkerboards taken with the camera for which we need to compute the instrinsic camera parameters. The size of the checkerboard needs to be supplied since the opencv function [[https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#ga93efa9b0aa890de240ca32b11253dd4a | findChessboardCorners]] needs to know how many points it is looking for and the entire chessboard needs to be visible in every image. The height and width of the chessboard which needs to be specified is not the height and width of the chessboard in squares but rather the heigth and width of the inner corners (points between squares). For example a normal chessboard is 8 by 8 if you count the squares but if we count the inner corners it is 7 by 7 so we would supply 7 by 7 to the function. The code for camera calibration expects images of checkerboards taken with the camera for which we need to compute the instrinsic camera parameters. The size of the checkerboard needs to be supplied since the opencv function [[https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#ga93efa9b0aa890de240ca32b11253dd4a | findChessboardCorners]] needs to know how many points it is looking for and the entire chessboard needs to be visible in every image. The height and width of the chessboard which needs to be specified is not the height and width of the chessboard in squares but rather the heigth and width of the inner corners (points between squares). For example a normal chessboard is 8 by 8 if you count the squares but if we count the inner corners it is 7 by 7 so we would supply 7 by 7 to the function.
Line 19: Line 19:
 <code>RuntimeError: Frame didn't arrive within 5000</code> <code>RuntimeError: Frame didn't arrive within 5000</code>
  
-In which case one should check that the camera works and sends frames to the compute with realsense-viewer.+In which case one should check that the camera works and sends frames to the computer with realsense-viewer.
  
-It is very important to check if the camera is recognized as a USB2 device or USB3 device since USB2 supports a smaller sets of resolution than USB3. If a resolution that is not possible is requested (for example if the camera is detected as a USB2 device but the expected resolution is too big) the pipeline throws the following error:+It is very important to check if the camera is recognized as a USB2 device or USB3 device since USB2 supports a smaller sets of resolution than USB3. If a resolution that is not possible is requested (for example if the camera is detected as a USB2 device and the expected resolution is too big) the pipeline throws the following error:
  
 <code>Runtime error: Couldn't resolve requests</code> <code>Runtime error: Couldn't resolve requests</code>
Line 33: Line 33:
 The intrinsic camera parameters for a specific camera can be computed from a set of images of checkerboards taken by that camera, this is implemented in [[https://git.cs.lth.se/robotlab/camera_calibration/-/blob/main/calibrate.py | calibrate.py]]. This script takes the following command line arguments: The intrinsic camera parameters for a specific camera can be computed from a set of images of checkerboards taken by that camera, this is implemented in [[https://git.cs.lth.se/robotlab/camera_calibration/-/blob/main/calibrate.py | calibrate.py]]. This script takes the following command line arguments:
  
-^ Argument Name  ^ Description                                                                                                                                         +^ Argument Name  ^ Description                                                                                                                                        
-| -height        | Height of rectangle in checkerboard (the amount of intersection corners per row in the y-axis).                                     +| -height        | Height of rectangle in checkerboard (the amount of intersection corners per row in the y-axis).                                                    
-| -width         | Width of rectangle in checkerboard (the amount of intersection corners per row in the x-axis).                                      +| -width         | Width of rectangle in checkerboard (the amount of intersection corners per row in the x-axis).                                                     
-| -size          | Length of checkerboard squares in millimeters.                                                                                      +| -size          | Length of checkerboard squares in millimeters.                                                                                                     
-| -f             | name of folder where images are stored. Camera parameters are also saved in this folder. True or False.                             +| -f             | name of folder where images are stored. Camera parameters are also saved in this folder. True or False.                                            
-| -pause         | Show each detected checkerboard and display for visual inspection. Press c to continue to the next picture and q to stop execution. |+| -pause         | Show each detected checkerboard and display for visual inspection. Press c to continue to the next picture and q to stop execution. True or False. |
  
 The script prints the result for each image wether it was able to detect a checkerboard or not, if the wrong height and width are supplied the checkerboard might still be detected in 1 in 10 images depending on how incorrect the values are. If the values are correct, however, the checkerboard should be detected in all but the blurriest pictures as long as the whole checkerboard is in the image. The script prints the result for each image wether it was able to detect a checkerboard or not, if the wrong height and width are supplied the checkerboard might still be detected in 1 in 10 images depending on how incorrect the values are. If the values are correct, however, the checkerboard should be detected in all but the blurriest pictures as long as the whole checkerboard is in the image.
Line 44: Line 44:
 The camera parameters are saved in a text file called 'params' in the same folder as the images. A function which parses this text file is also implemented in [[https://git.cs.lth.se/robotlab/camera_calibration/-/blob/main/calibrate.py | calibrate.py]], the function is called parse_camera_parameters and takes the path to the file where the camera parameters are saved as its only argument. The parsing function returns two tuples The camera parameters are saved in a text file called 'params' in the same folder as the images. A function which parses this text file is also implemented in [[https://git.cs.lth.se/robotlab/camera_calibration/-/blob/main/calibrate.py | calibrate.py]], the function is called parse_camera_parameters and takes the path to the file where the camera parameters are saved as its only argument. The parsing function returns two tuples
  
-^ Output ^ Name ^ Contains +^ Output ^ Name    ^ Contains                          ^ 
-| 1      | calib   | f_x, f_y, c_x, c_y      +| 1      | calib   $f_x$$f_y$$c_x$$c_y$        
-| 2      | distort | k_1, k_2, p_1, p_2, k_3 |+| 2      | distort | $k_1$$k_2$$p_1$$p_2$$k_3$ | 
 + 
 +The first tuple, calib, contains the intrinstic camera matrix where $f_x$ and $f_y$ are the focal lengths in the $x$- and $y$-direction and ($c_x$, $c_y$) is the location of the pixel center. The distortion parameters $k_1$, $k_2$, $p_1$, $p_2$ and $k_3$ are parameters which estimate how much straight lines captured by the camera are bent. This bending effect can be removed with the help of opencv's function [[https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#ga69f2545a8b62a6b0fc2ee060dc30559d undistort]].
  
 ===== SkiROS ===== ===== SkiROS =====
  • documentation/vision/camera_calibration.1674422691.txt.gz
  • Last modified: 2023/01/22 21:24
  • by pontusr