This is the code it uses imageData to set all the pixels in FRAME to red... i could use help understand it though so i can get a better view of opencv and c in general Note : need to use the c interface for project im working on
In the code below it seems FRAME->imageData is added to y multiplied by FRAME->WidthsTEP inthe top for loop and then PTR is altered in the bottom for loop ie ' ptr[3*x+2] = 255;' and that changes the image FRAME to all red but imageData is set to PTR not the other way around so how can changing PTR even effect FRAME->imageData. because when i do this
int a=1; int b=a; b=4;
cout << "a = " << endl << " " << a << endl << endl; // A ends up equaling 1
so it doesnt seem this should happen
#include "cv.h"
#include "highgui.h"
using namespace std;
int main (int argc, const char * argv[]) {
IplImage *frame = cvCreateImage(cvSize(41, 41), IPL_DEPTH_8U, 3);
for( int y=0; y<frame->height; y++ ) {
uchar* ptr = (uchar*) ( frame->imageData + y * frame->widthStep );
cout << "M = " << endl << " " << frame->imageData+ frame->widthStep << endl << endl; for( int x=0; x<frame->width; x++ ) { ptr[3*x+2] = 255; //Set red to max (BGR format) } }
cvNamedWindow("window", CV_WINDOW_AUTOSIZE);
cvShowImage("window", frame);
cvWaitKey(0);
cvReleaseImage(&frame);
cvDestroyWindow("window");
return 0;
}