Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

iterate through a matrice, int to uchar problem

I'm trying to modify in a for a loop a Mat. I'm following this article. However the following code does not work :

cv::Mat tmp(20, 20, CV_32F, cv::Scalar(0,0,0));

cv::MatIterator_<uchar> new_mat= tmp.begin<uchar>();
for( int i = 0; i< (tmp.size().width) ;i++){
    for(int j= 0;j< tmp.size().height;j++){

    (*new_mat) = 1;
    std::cout << (float) (*new_mat) << ", ";
    new_mat++;
    }
std::cout <<std::endl;
}
std::cout << std::endl << std::endl;

std::cout << tmp << std::endl;

std::string win = "Local Maxima";
cv::imshow(win, tmp);

Printing (float) (*new_mat) give a Matrix of 1 as explected but tmp if full of 1.4012985e-45 values and I can't seem to understand why. My guess is that it as to do with the way I'm assigning the value but I can't grasp the real problem here.

Any help is appreciated.