OpenCV Error trying print every Mat element [closed]

asked 2014-03-26 07:28:23 -0500

Darius gravatar image

updated 2014-03-26 07:43:58 -0500

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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2014-03-27 03:51:04.190429

Comments

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!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 08:16:13 -0500 )edit

Mat faceROI = frame_gray( faces[i] );

cout <<"depth: "<<faceROI.depth()<<" chanels: "<<faceROI.channels() depth: 0 chanels: 1;

Darius gravatar imageDarius ( 2014-03-26 09:05:36 -0500 )edit

I need to know the type of frame gray... is it CV_8UC1?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 09:06:36 -0500 )edit

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]

Darius gravatar imageDarius ( 2014-03-26 09:08:58 -0500 )edit

faceROI.type()

its says 0

Darius gravatar imageDarius ( 2014-03-26 09:11:35 -0500 )edit

so yes its CV_8UC1

Darius gravatar imageDarius ( 2014-03-26 09:15:01 -0500 )edit
1

then change the type between the <Vec3b> to <uchar> like mentioned here

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 09:21:40 -0500 )edit

now program runs through all matrix but results are : ↨↑↑↓↓↑↑↓↓↑↨§▬↨↨↑↨↨↨↨ how could i get int type ?

Darius gravatar imageDarius ( 2014-03-26 09:41:27 -0500 )edit

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?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 10:00:30 -0500 )edit

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...

Darius gravatar imageDarius ( 2014-03-26 10:20:10 -0500 )edit