Hello right now I'm trying to capture an grayscale image from the webcam and access it the value of every pixel of the image. At first I used this code
IplImage* processed_frame = (*custom_cb)(frame);
if(key==13)
{
IplImage *destination = cvCreateImage(cvSize(20,20),processed_frame->depth, processed_frame->nChannels);
cvResize(processed_frame, destination);
cvShowImage("frame resize", destination);
mat=cvCreateMat(destination->height,destination->width,CV_32F );
for(int i=0;i<mat.rows;i++)
{
for(int j=0;j<mat.cols;j++)
{
printf( "(%.f) ",mat.at<float>(i,j) );
}
printf("\n");
}
}
I'm trying to convert the IplImage to mat and access every pixel of the mat but it always return the same value for every pixel then I'm trying to access the IplImage directly
IplImage* processed_frame = (*custom_cb)(frame);
if(key==13)
{
IplImage *destination = cvCreateImage(cvSize(20,20),processed_frame->depth, processed_frame->nChannels);
cvResize(processed_frame, destination);
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++)
{
printf( "(%.f) ",CV_IMAGE_ELEM(destination,float,i,j) );
}
printf("\n");
}
}
it gives me various value for every pixel and every image I try to capture but I'm still not sure if I'm doing it right. What I want to ask is why the first code always returning same value and is the second code the right way to get the pixel value?
Thanks