Hi everyone, I want to reverse the whole procsess of projecting a disparity value to 3D word space in order to get the exact disparity value belonging to a specific distance.
This is the code I use to calculate a 3d-coordinate:
cv::Mat_<float> coordinate(1,4);
dValue /= 16.0;
if(dValue > 0) {
coordinate(0)=x;
coordinate(1)=y;
coordinate(2)=dValue;
coordinate(3)=1;
coordinate = cv::Mat(coordinate);
coordinate = Q * coordinate.t();
coordinate /= coordinate(3);
return coordinate;
} else {
coordinate(0) = 0;
coordinate(1) = 0;
coordinate(2) = 1000000;
coordinate(3) = 0;
return coordinate;
}
Now I thought about writing the inverse calculation in Order to get the disparity value for a specific distance:
// coordinate in the world origin with a distance of 1.0 meter.
cv::Mat_<float> coordinate(1,4);
coordinate(0) = 0.0f;
coordinate(1) = 0.0f;
coordinate(2) = 1.0f;
coordinate(3) = 1.0f;
cv::Mat Q_inv = Q.inv(cv::DECOMP_SVD);
Q_inv.convertTo(Q_inv, CV_32FC1);
cv::Mat_<float> back = Q_inv * coordinate.t();
// just makes the value bigger and does not result in a correct value
// back(2) */ 16;
To my mind the calculation is mathematically correct. But the returned values do not match anything related to the disparity values:
disparityValue: 688 distance: 0.901838
calculated coordinate:
[1.5896965;
1.3923311;
119.25928;
0.0015376776]
Does somebody know where the problem could be?