Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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?

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;

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?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;