Directory
- Directory
- Description
- Binocular ranging code in previous articles
- Binocular visual code with better results
- Implementation of binocular visual code with better effect
- 1 Calibration Process
- 2 ranging process
- Some problems and how to solve them
- To say.
1 description
I've written an article about the realization of binocular depth of field and distance measurement based on OpenCV completely: http://blog.csdn.net/hysteric314/article/details/50456570
However, the previous article in the binocular Visual code is not perfect, so I would like to find out if there is a better way to achieve.
Then I found a video on YouTube: Https://www.youtube.com/watch?v=PR9tlFay0U8
Youku Handling Address: http://v.youku.com/v_show/id_XMTU2Mzk0NjU3Ng==.html
The original code in the video address: Https://www.dropbox.com/s/hiiq2unwttutbd8/Source%20code.rar
I changed some of the code and ran a bit, the code to achieve the calibration process is very simple, easy to use, ranging function can also be used, and the final range of the effect is very accurate, much better than the previous code.
In this article I will write about the specific implementation of the modified code and some of the problems that occur during the operation.
Binocular ranging code in previous articles 2
Previous code: http://blog.csdn.net/hysteric314/article/details/50456570
The previous code can realize some functions of binocular ranging, but it is not perfect
This code has a few questions:
1, modify the disparity map effect of the parameters can only be modified in the code, not directly and intuitively see the effect of the changes
2, there is no calibration process, only from the external reading calib_paras.xml This parameter file, calibration parameter generation also need other programs, very troublesome
3, the effect of binocular ranging is not very ideal, the distance information obtained is inaccurate
The effect of the implementation:
Operating Environment:
1.windows10
2.OPENCV 2.4.9
3.visual Studio 2013
4. Two PCs Microsoft HD-3000 camera
5.i7, set display, 16g, SATA
3 more effective Binocular vision code
The original code is exactly the same as this article:
Http://scholar.lib.vt.edu/theses/available/etd-12232009-222118/unrestricted/Short_NJ_T_2009.pdf
According to the code in this article changed, at the same time this article detailed introduction of all the binocular vision of things, have to do the students can refer to this article.
I have modified the original code:
One function in the original code is to detect objects, to draw a rectangular frame around the object, and to mark the distance information of the object in this box.
However, this feature is implemented with the Cvblobslib OPENCV extension Library, which I follow in the tutorial (link below) after installation:
Http://dsynflo.blogspot.com/2010/02/cvblobskib-with-opencv-installation.html,
In the vs2013 also various settings, but is not running: source code and cvblobs Some of the code related to various errors, and then block the relevant code, code can be run immediately.
So the code in this article is my modified code, the advantage is that it does not need to install the anti-human expansion of the library, if you opencv2.4.9 configuration, you can run directly, convenient. It can still achieve all the main functions, including the calibration function and the function of measuring depth.
If you want to use cvblobslib this extension library, just want to implement that object frame function, please try the original code yourself.
If your original code configuration is successful, I hope you can comment on your implementation process and the method of configuration in the article, thank you!
Modified Code Implementation effect:
Operating Environment:
1.windows10
2.OPENCV 2.4.9
3.visual Studio 2013
4. Two PCs Microsoft HD-3000 camera
5.i7, set display, 16g, SATA
The code mentioned in this article (the modified Code):
http://download.csdn.net/detail/hysteric314/9514872
4 Effect of better binocular vision Code Implementation 4.1 calibration process
Before the ranging, the first must be the camera calibration, so as to get two cameras before the calibration information, then how to calibrate it?
Method:
1, for the first time the code in the "stdafx.h" file in the code: "#define CALIBRATION 0" to "#define CALIBRATION 1", which means that the calibration process, after calibration, you can be in the project directory under the "Calibfile" The file in the folder where the calibration information is obtained.
2, during the calibration process, the demo video is used 10*7 chess, a total of 40 frames to calculate the various parameters of the camera, if you want to use a different format of the checker, you can modify the "StereoFunctions.cpp" file in the corresponding parameters (such as: int nx=10, ny=7, frame = 0, n_boards =40, N;).
3, take the checkerboard in front of the camera to move, if everything is normal, the effect should be as shown.
4, if the calibration effect is good, you can change the code "#define CALIBRATION" to 0 before the next execution, indicating that there is no need to re-calibration, each run program is directly using the last calibration information.
5, you also need to put the "#define Analysis_mode 1" line of code into the stdafx.h.
Calibration process:
4.2 Ranging process
After the calibration is over, the range can be measured.
1,rectified window: First the left and right cameras need to be corrected according to the calibration information, the rectified window is displayed in the corrective operation after processing the image.
2,disparity window: The parallax map is displayed.
3,stereo Controls window: This window is used to set various parameters of the parallax map, you can get a better parallax map by adjusting the sliders of each parameter in the control window.
4, in order to get the distance information, the first need to set the save dist parameter in the stereo controls is 1, which means to save the current frame depth information, and then use the mouse to click on one of the Parallax map location, then in another CMD window will display the corresponding location of the depth information, the unit is centimeters.
5, in the "Distance" folder under the directory, there is the MATLAB code to calculate the distance information, you can try to run it.
6, I run ranging when the distance between the two cameras is 6cm, if you are other brands of camera, you can adjust the distance between the two cameras, so that the disparity map to achieve the best results.
Equipment for binocular ranging:
5 Some problems and how to solve them
Q Parallax Map effect is not good how to do?
A:
1, it is possible that you left the camera in reverse.
2, the result of calibration is not good, parallax map certainly will not be better, and then re-calibration
3, calibration no problem, but after calibration you two camera position changes
Distance information 3d Point cloud is based on the disparity map, the disparity map is not allowed to get the distance information is certainly not allowed, but I think most of the disparity map is not allowed, the effect is not good situation is because you calibration that step is not ready, so repeatedly calibrated, when parallax map effect is best, you put this calibration information saved , the calibration information has been used in the future.
Q when ranging, click on the disparity map to the right position will error, or "OpenCV Error:assertion failed dims=2&&data&& () I0 error message
A: Do not point to the right side of the position, the reason I do not know, there is a solution to the great God please comment method, thank you!
6 to say.
Recently in the neural network, image recognition related things, and then have time to implement this code on the TK1, will be posted in the blog code.
If there is an error in this article please comment, thank you!
"OpenCV learning" using OPENCV and two cameras to achieve dual target and ranging