type error of function integral in imgproc.cpp when compiling in x64 architecture (Bug #3861)
Description
I wrote a program using function integral in imgproc.cpp in x64 architecture (in Windows 8.1 with VS 2012). And the result of integral was
obviously truncated, namely, the result appeared to be computed as 64bit float but stored in 32bit float. So the when I printed the result matrix
in text file, it looked ridiculous. If I change the storage to CV_64FC1, the problem disappears (Please look at the following code).
Here is the code ( note that the problem occurs in x64 architecture ):
@
// init storage
Mat binsImage = Mat(angleMat.size(), CV_32FC1, Scalar(0));
// Here I initialize a 32-bit float image and the probem occurs.
// If I change it to CV_64FC1, the problem disappears.
Mat integralImage = Mat(angleMat.rows+1,angleMat.cols+1,CV_32FC1, Scalar(0));
// this function fill some data in binsImage, which are checked to be right (by printing each pixel and view it).
calcBinsImages(angleMat,flowmagMat,nBins,binsImage);
// call opencv function integral
integral(binsImage, integralImage);
// this self-defined function save an image as a text file so I can view it pixel by pixel.
saveImageAsText(binsImage, "binsImages.txt");
saveImageAsText(integralImage, "integral.txt");
@
Here is the self-defined function that saves the image as a text file.
bool saveImageAsText(const Mat& img, const char* textFile) {
FILE* fout = NULL;
fopen_s(&fout, textFile, "w");
if (fout == NULL) {
return false;
}
fprintf(fout, "%d %d %d\n", img.rows, img.cols, img.channels());
for(int i = 0; i < img.rows; ++i) {
for(int j = 0; j < img.cols; ++j) {
int k = 0;
if (img.channels() == 1) {
fprintf(fout, "%.0f " , img.at<float>(i, j));
}
else {
for(; k < img.channels() - 1; ++k)
fprintf(fout, "%.0f," , img.at<Vec6f>(i, j)[k]);
fprintf(fout, "%.0f " , img.at<Vec6f>(i, j)[k]);
}
}
fprintf(fout, "\n");
}
fclose(fout);
return true;
}
Associated revisions
Merge pull request #3861 from wangyan42164:cascade_optimizing
History
Updated by Alexander Alekhin over 10 years ago
- Assignee deleted (
Alexander Alekhin)
Updated by Malintha Fernando about 10 years ago
I would like to work on this. Can you assign me in?
Updated by Vadim Pisarevsky almost 10 years ago
use integral(binsImage, integralImage, CV_64F) instead.
- Status changed from New to Cancelled