Ask Your Question

Error accesing pixel intensity values...

asked 2015-09-20 01:22:25 -0500

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;*/
for(long int i=0;i<img.rows;i++)
     for(long int j=0;j<img.cols;j++)

 return 0;


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-09-20 01:27:52 -0500

berak gravatar image

updated 2015-09-20 02:36:14 -0500

  •<uchar>(i,j) // please, row,col.
  • imread("MyPic.JPG", IMREAD_GRAYSCALE) // same numerical value, but different meaning
  • tutorials
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-09-20 01:22:25 -0500

Seen: 128 times

Last updated: Sep 20 '15