Camera calibration-OpenCV

The benefits of using opencv calibration: an .xml file is automatically generated for easy use (That is, you only need to change this file when changing different cameras, without changing the code)

Operating system: Ubuntu16.04
OpenCV version: 3.4.6
Camera: computer comes with camera

Calibration step
1. Find the calibration routine.
Enter the OpenCV installation directory, find the samples / cpp / tutorial_code / calib3d / camera_calibration directory, and copy it to a suitable location. (Because some code needs to be modified, it is recommended not to use it directly in the original directory.)

2. Modify the calibration configuration parameters
Find the camera_calibration / in_VID5.xml file, which is the configuration file used by the calibration program, and you need to set several parameters in it.
Insert picture description here
This is the height and width of the checkerboard! ! Note: The width and height here are the internal intersections of the checkerboard, not the traditional width and height.

For example, the following is
Insert picture description here
the width of each grid of 9 and 2 is the following parameter, the unit is mm
Insert picture description here
is the most important, if this parameter is not correct, the identified camera is wrong, and even the error will not be recognized! !

and so!

We come to Kangkang! that's it! ! !
Insert picture description here
Select input method The
routine provides three input methods. If the camera can be recognized, it is recommended to use the input camera method. This method only needs to set the video input device number. For notebook computers, usually 0 means that the notebook comes with a camera, and 1 means an external camera.

I haven't tried it yet.

3. Compile

Need a CMakeLists file, excerpt online here

project(Camera_Calibration)
set(CMAKE_CXX_STANDARD 11)

find_package(OpenCV 3.0 QUIET)
if(NOT OpenCV_FOUND)    
    find_package(OpenCV 2.4.3 QUIET)
    if(NOT OpenCV_FOUND)
        message(FATAL_ERROR "OpenCV > 2.4.3 not found.")
    endif()
endif()

include_directories(${OpenCV_INCLUDE_DIR})
add_executable(Camera_Calibration camera_calibration.cpp)
target_link_libraries(Camera_Calibration ${OpenCV_LIBS})

Then it is familiar

mkdir build
cd build
cmake ..
make

4. Run the
terminal and run
./Camera_Calibration… / in_VID5.xml
(because the parameters need to be passed in, so pass in the configuration file)

If the camera view appears on the computer, it is more than half of the success, just follow the instructions.

To emphasize one point: make the camera shoot the checkerboard from different directions to ensure that the program accurately calculates the image distortion.

Published 29 original articles · praised 0 · visits 497

Guess you like

Origin blog.csdn.net/qq_43771959/article/details/104309380