OpenCV Error trying print every Mat element [closed]
for (int k = 0; k < faceROI.rows; k++)
{
for (int j = 0; j < faceROI.cols; j++)
{
cout<<"["<<k<<","<<j<<"]"<<" element: "<< faceROI.at<Vec3b>(j,k)<<endl;
}
`at this place i am getting :
OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si ze.p[0] && (unsigned)(i1DataType<_Tp>::channels) < (unsigned)(size.p[1]channel s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3 ) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file c:\opencv\build\include\op encv2\core\mat.hpp, line 537
its a simple program and i can't print out all elements of image. p.s. i will gona use each and every element.
Add your initialization of the faceROI matrix please. It seems you are accessing it with a wrong type which defines the step to take from element to element in the .at<>() function!
Mat faceROI = frame_gray( faces[i] );
cout <<"depth: "<<faceROI.depth()<<" chanels: "<<faceROI.channels() depth: 0 chanels: 1;
I need to know the type of frame gray... is it CV_8UC1?
code runs for a while and stops at the end, lets say i have image 100x100 and i get error at the end like [30][98]
faceROI.type()
its says 0
so yes its CV_8UC1
then change the type between the <Vec3b> to <uchar> like mentioned here
now program runs through all matrix but results are : ↨↑↑↓↓↑↑↓↓↑↨§▬↨↨↑↨↨↨↨ how could i get int type ?
You cannot jump with an integer iterator through a 8bit unsigned 1 channel image. That output seems like random values generated by not initializing your matrix properly?
well thats strange, with <Vec3b> i got sets of RGB collor codes, and with <uchar> i get random values, btw after trying to cout all values i use imshow( "ROI", faceROI ); and i get clear good image...