I was browsing over some code in the OpenCV page when it came to accessing Pixel Data
IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3);
CvScalar s;
s=cvGet2D(img,i,j); // get the (i,j) pixel value
printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]);
s.val[0]=111;
s.val[1]=111;
s.val[2]=111;
cvSet2D(img,i,j,s); // set the (i,j) pixel value
I had done something similar, but I used the Template Class provided to access pixel data......anyways Im not sure I understand the part s.val[0]=111....etc?
if s.val[0] contains the B value, what exactly is s.val[0]=111 doing? is it setting it to black?........I dont understand exactly what it's supposed to be?
Im used to CVscalars and such but I dont understand this format? Specifically what 111 means?
thanks
解决方案
The cvSet2D(img, i, j, s) functions to not access the (i,j)th pixel. It accesses the (j,i)th pixel. That is because images are stored as a matrix - you need to specify the row first (the Y coordinate) and then the column (the X coordinate).
Instead of using the cvGet/Set functions, did you try using pointers to access data within an image?