Originally Posted by
vkoo
anybody?
Let me google "openvc bmp" for you
Let me google "IplImage" for you
Code:
IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
CvScalar s;
s=cvGet2D(img,i,j); // get the (i,j) pixel value
printf("intensity=%f\n",s.val[0]);
s.val[0]=111;
cvSet2D(img,i,j,s); // set the (i,j) pixel value
Code:
int nl= image->height; // number of lines
int nc= image->width * image->nChannels; // total number of element per line
int step= image->widthStep; // effective width
// get the pointer to the image buffer
unsigned char *data= reinterpret_cast<unsigned char *>(image->imageData);
for (int i=1; i<nl; i++) {
for (int j=0; j<nc; j+= image->nChannels) {
// process each pixel ---------------------
data[j]= data[j]/div * div + div/2;
data[j+1]= data[j+1]/div * div + div/2;
data[j+2]= data[j+2]/div * div + div/2;
// end of pixel processing ----------------
} // end of line
data+= step; // next line
}
Code:
// load an image
img=cvLoadImage(argv[1]);
if(!img){
printf("Could not load image file: %s\n",argv[1]);
exit(0);
}
// get the image data
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);
// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
// invert the image
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
data[i*step+j*channels+k]=255-data[i*step+j*channels+k];
// show the image
cvShowImage("mainWin", img );