Ask Your Question

Revision history [back]

Error accesing pixel intensity values...

Hey, I am simply accessing the pixel intensity values of a greyscale image and printing it out on the console, I get some values then there is this error: OpenCV Error: Assertion failed (dims<=2 && (unsigned)i0 .....and so on) It's my first time using opencv or even accessing a pixel value.... please help..

Mat img = imread("MyPic.JPG",CV_8U);

 if (img.empty())
 {
        cout << "Image cannot be loaded..!!" << endl;
          return -1;
 }
 /*long int PixelIntensitySum=0;
 long int count=0;
 long int AverageIntensity;
 Scalar Intensity;*/
 cout<<img.rows<<endl<<img.cols<<endl;
for(long int i=0;i<img.rows;i++)
 {
     for(long int j=0;j<img.cols;j++)
     {
     cout<<int(img.at<uchar>(j,i))<<endl;
     }
 }


 return 0;

}