cv::Mat matrix= cv::Mat::zeros(3,4,CV_8U); matrix.at<float>(0,0)=1; matrix.at<float>(0,1)=2; matrix.at<float>(0,2)=3; matrix.at<float>(1,0)=4; matrix.at<float>(1,1)=5; matrix.at<float>(1,2)=6; matrix.at<float>(2,0)=7; matrix.at<float>(2,1)=8; matrix.at<float>(2,2)=9; for (int i=0;i<matrix.rows;i++){ for (int j=0;j<matrix.cols;j++){ float temp= matrix.at<float>(i,j); std::cout<<temp; std::cout<<" "; } std::cout<<std::endl; } 

Excpected output:

1230

4560

7890

Current output:

1478

4789

7890

What's wrong?

  • Current output in any case does not correspond to the code in the example, since in the example, a space is displayed after each value. You probably need to rebuild the project, or you are misleading us. - Ariox

1 answer 1

this happens because of memory allocation. float type and CV_8U are not the same. The same format everything works.

For example:

  cv::Mat matrix = cv::Mat_<std::complex<double> >(3, 4); matrix.at<double>(0,0)=1; 

provides same data type