In order to get the mean value of a disparity map I had to write an own method to ignore negative disparity values:
float Utility::calcMeanDisparity(cv::Mat const& matrix)
{
int total = 0;
int numElements = 0;
for(int r = 0; r < matrix.rows; ++r)
{
for(int c = 0; c < matrix.cols; ++c)
{
if(static_cast<float>(matrix.at<short>(r,c)) > 0)
{
total += static_cast<float>(matrix.at<short>(r,c));
++numElements;
}
}
}
float mean = total / abs(numElements);
std::cout << total << " / " << numElements << " = " << mean << std::endl;
return mean;
}
but my code simply crashes after a certain time with the gdb error:
Program received signal SIGFPE, Arithmetic exception.
0x000000000044a992 in Utility::calcMeanDisparity (matrix=...) at src/utility.cpp:250
250 float mean = total / abs(numElements);
But there is no way that I am doing a division by zero. These are three of the last lines my code is trying to calculate:
950149 / 4275 = 222
804412 / 4429 = 181
873770 / 4253 = 205
I also added the abs(foo)
stuff to be completely safe of divisions by zero.
Actually I do not have any idea what to do at the moment.
Maybe one of you guys has an idea for that.