Ask Your Question
0

Error accesing pixel intensity values...

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

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;

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

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

berak gravatar image

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

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

Question Tools

1 follower

Stats

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

Seen: 219 times

Last updated: Sep 20 '15