Patrizio Bertoni
Patrizio Bertoni

Reputation: 2712

Issue with cv::Mat::zeros initialization

my problem is just astonishing. This is the code

 #define NCHANNEL 3
 #define NFRAME 100
 Mat RR = Mat::zeros(NCHANNEL, NFRAME-1, CV_64FC1);

double *p_0 = RR.ptr<double>(0);
double *p_1 = RR.ptr<double>(1);
double *p_2 = RR.ptr<double>(2); 
cout<< p_0[NFRAME-1] << endl << p_1[NFRAME-1] << endl << p_2[NFRAME-1] << endl;

And the output is: 0 0 -6.27744e+066 .
Where is that awful number come from?
it seems I'm printing a pointer or something rough in memory.
(uh, 0 is the value of all other elements, of course).

Upvotes: 1

Views: 728

Answers (1)

Andrey Kamaev
Andrey Kamaev

Reputation: 30122

You are accessing after the last element of Mat. If you use NFRAME-1 for initialization then the last element has NFRAME-2 index.

Upvotes: 3

Related Questions