Camera calibration (why should the title be 5 words?)

Significance of calibration

Mr. z told us that the contemporary production technology can not make a perfect convex lens, so the image will have certain distortion at the edge of the picture taken by the lens. The significance of our calibration is to calculate a series of parameters with the method of OpenCV and correct this distortion through mathematical calculation

Calibration tool


Yes, that's all. No, there's your brain

Calibration procedure

1. Locate the calibration routine

Enter the OpenCV installation directory and find samples / CPP / tutorial_ code/calib3d/camera_ The calibration directory and copy it to an appropriate location. (because some codes may need to be modified, it is not recommended to use them directly in the original directory.)

2. Modify calibration configuration parameters

Find camera_calibration/in_VID5.xml file, which is the configuration file used by the calibration program. Several parameters need to be set.

① Width and height of dot grid

Because we actually use dot lattice, we need to adjust many parameters

Obviously, here are 7 rows and 7 columns

<!‐‐ Number of inner corners per a item row and column. (square, circle)‐‐>
<BoardSize_Width>7</BoardSize_Width>
<BoardSize_Height>7</BoardSize_Height>

Then there's another place we need to change to CIRCLES_GRID indicates that we use a dot grid

② . width of each grid

The width of each grid should be set to the actual number of millimeters, and the actual use of this parameter remains to be verified. At present, even if the setting is not accurate, it doesn't matter.

<!‐‐ The size of a square in some user defined metric system (pixel, mill
imeter)‐‐>
<Square_Size>20</Square_Size>

③ . select input method

The routine provides three input modes. However, if the camera to be calibrated has been connected to the computer, it is recommended to use the input camera mode. This method only needs to set the video input device number. For notebook computers, usually 0 means the notebook has its own camera and 1 means the external camera.

<!‐‐ The input to use for calibration.
To use an input camera ‐> give the ID of the camera, like "1"
To use an input video ‐> give the path of the input video, like "/tmp/x.
avi"
To use an image list ‐> give the path to the XML or YAML file containing
the list of the images, like "/tmp/circles_list.xml"
‐‐>
<Input>"0"</Input>

3. Compile

Of course, CMakeLists.txt is required for compilation, so we create a new camera_calibration/CMakeLists.txt file, write the following contents.

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 classic opens the terminal in your new folder

mkdir build
cd build
cmake ..
make
./Camera_Calibration

At this time, an error will be reported, which is

Could not open the configuration file: "default.xml"
...((line 10086 is omitted here)

It's because you didn't pass parameters when. / is running

So we re-enter it in the terminal

./Camera_Calibration ../in_VID5.xml

So you can turn on the camera

Note: if it is not turned on, it may be the wrong time to set the camera number in step ③. At this time, you can properly enumerate 0,1,2,3

Then, there will be a "press' g 'to start" at the bottom of the jumped out camera picture. After pointing your camera at the board we need to calibrate, the picture in the camera will become

After pressing g to start, the color of the picture will be reversed (maybe not? It will change anyway). The accounting number is n/25. After we take 25 pictures, this calibration will be completed, and your calibration results will be returned in the terminal. The smaller the value, the better (z teacher said that if it is less than 0.2, the calibration is completed).

At this point, the calibration is completed (the calibration results will be stored in camera_calibration/out_camera_data.xml). Of course, you can calibrate multiple times, but the results of the two calibrations will not affect each other (the better the superscript is, it does not exist, Hello!) until a satisfactory value is returned.

I won't talk about the mathematical principle, and I won't (I can dig a hole all the time). I'll write a blog after understanding it

Tags: OpenCV RoboMaster

Posted on Fri, 01 Oct 2021 17:15:27 -0400 by phoenixx