CV_64F ConvertTo CV_8U Problem with cast
Hi everyone, I try to cast a CV_64F Mat into a CV_8U Mat for thresholding (See code below). Unfortunately this doesn't work the way i want it to. If you uncomment the cout-command you will see that the whole mat contains ones. What am i doing wrong? Thank you for your help!
Mat testMat = Mat(10, 10, CV_64F);
double above = 0.9111;
double below = 0.6665;
double minDbl = 0.9;
// Fill Mat:
for (int rows=0; rows<testMat.rows; rows++)
{
for (int cols=0; cols<testMat.cols; cols++)
{
if (rows < 5)
testMat.at<double>(rows, cols) = above;
else
testMat.at<double>(rows, cols) = below;
}
}
//cout << testMat;
Mat convertedMat;
testMat.convertTo(convertedMat, CV_8U);
//cout << convertedMat;
//What i actually want:
cv::threshold(convertedMat, convertedMat, minDbl, 1., CV_THRESH_TOZERO);
//cout << convertedMat;
you can also avoid both the conversion and the threshold function, and do a direct comparison:
something is missing convertedMat.setTo(0,~mask) ?