1. Brief description
Through the study of the master's thesis, I understand the various algorithms of stereo matching. Now matlab is used to achieve binocular stereo matching.
Thesis study link: Zynq FPGA binocular vision graduation design (6) Master thesis study summary
2. Source code
Currently, epipolar search is used, that is, the search is performed only in the horizontal direction, and the error is relatively large. In order to reduce the difficulty of implementation on FPGA, we do not plan to adopt multi-path aggregation, so you have to implement multi-path by yourself.
This source code is only the matching part, just add this part of the algorithm to my previous shared source code and make a connection.
Portal: Zynq FPGA's binocular vision graduation design (5) realization of matlab polar line correction algorithm
%Census
[B, A, C] = size(new_image_L)
windowsize = 9;
win = (windowsize -1)/2;
D_min = 0;
D_max = 50;
for b = win+1 : B-win
for a = win+1 : (A-win-D_max)
%左图census变换
var_r = zeros(1,windowsize^2);
parallax = D_min; hamm_data =10000; hamm=0;
for m = -win : 1 : win
for n = -win : 1: win
if(new_image_R(b+m,a+n) <= new_image_R(b,a))
var_r(1,9*n+m+41) = 1;
else
var_r(1,9*n+m+41) = 0;
end
end
end
%对右图进行变换
for d = D_min : 1 : D_max
var_l = zeros(1,windowsize^2);
hamm_value = 0;
for m = -win : 1 : win
for n = -win : 1: win
if(new_image_L(b+m,d+a+n) <= new_image_L(b,d+a))
var_l(1,9*n+m+41) = 1;
else
var_l(1,9*n+m+41) = 0;
end
end
end
%汉明距离计算
hamm = xor(var_l,var_r);
hamm_value = sum(hamm(:) == 1);
if(hamm_data > hamm_value)
hamm_data = hamm_value;
parallax = d;%得到视差值
end
end
parallax_image(b-win,a-win)= parallax;
end
end
dispMap = mat2gray(parallax_image);
B=medfilt2(dispMap,[5 5]);%中值滤波,滤波器窗口[9 9]
3. Effect
The effect is not very good, the main reason is that only the horizontal direction is used to search for matching, and the error is large. Secondly, it can be seen from the polar line correction effect diagram that the correction is not very good, which is related to the calibration board problem and matlab calibration problem. This will be adjusted later. There is also the calibration chart used, which cannot highlight the distance of the object. When the new board arrives, collect some pictures to test.
Note: The sobel operator extracts the edge features of the picture to reduce pixel information and also reduces some errors. You can also directly match the corrected pictures in stereo without sobel.