Reputation: 1639
for (int row = 0; row < curf->rows; row++)
{
for (int col = 0; col < curf->cols; col++)
{
Vec3b pixcur = curf->at<cv::Vec3b>(row, col);
cout<<"Pixel values at current point"<<endl<<pixcur.val[0]<<endl<<pixcur.val[1]<<endl<<pixcur.val[2]<<endl; ###DEBUG STMT ###
Vec3b pixlast = curl->at<cv::Vec3b>(row, col);
if (abs(pixcur.val[0]-pixlast.val[0])>checkval ||
abs(pixcur.val[1]-pixlast.val[1])>checkval ||
abs(pixcur.val[2]-pixlast.val[2])>checkval)
{
numPixelsDiff++;
}
}
}
Here curf and curl are pointers to two Mat objects. I know they point to actual Mats because the value of curf->rows and curf->cols output actual integers.
But the output of the line I have tagged with ### DEBUG STMT ### is always junk. checkval is a variable which is set prior to entering the loops. The values in the vec3b vector is not correct.
I tried this too
for (int row = 0; row < curf->rows; row++)
{
for (int col = 0; col < curf->cols; col++)
{
Vec3b pixcur = curf->at<cv::Vec3b>(row, col);
cout<<"Pixel values at current point"<<endl<<pixcur[0]<<endl<<pixcur[1]<<endl<<pixcur[2]<<endl; ###DEBUG STMT ###
Vec3b pixlast = curl->at<cv::Vec3b>(row, col);
if (abs(pixcur[0] - pixlast[0]) > checkval ||
abs(pixcur[1] - pixlast[1]) > checkval ||
abs(pixcur[2] - pixlast[2]) > checkval)
{
numPixelsDiff++;
}
}
}
It again only outputs junk symbols.
Am I doing something wrong here. Should I check for something else? I'm a complete and total newbie to opencv so I'll appreciate any help.
Upvotes: 1
Views: 876
Reputation: 39796
avoid pointers to cv::Mat
, as sooner or later you will thrash the internal refcount
this way. use references, or dare to copy it (it's a shallow copy anyway).
when printing bytes, use: cout << int(pixcur[0])
. you need the cast, or cout
will see a uchar
, and print ascii. (or just do cout << pixcur;
)
avoid per-pixel loops. in almost any case, there's a builtin function, that is doing the job better, faster, and with less chance for errors. e.g, there's absdiff()
and countNonZero()
.
Upvotes: 3