1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
IplImage* img = 0;
int height,width,step,channels;
// uchar *data;
int i,j;
float **mat;
CvScalar s;
if(argc<2){
printf("Usage: main <image-file-name>\n\7");
exit(0);
}
// load an image
img=cvLoadImage(argv[1],0);
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 %d widthStep\n",height,width,channels,width);
mat=malloc(height * sizeof(float*));
for(i=0;i<height;i++)
{
mat[i]=malloc(width * sizeof(float));
}
// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
// show the image
cvShowImage("mainWin", img );
// wait for a key
cvWaitKey(0);
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
s=cvGet2D(img,i,j); // get the (i,j) pixel value
mat[i][j]=s.val[0];
//printf("intensity=%f\n",s.val[0]);
}
}
// release the image
cvReleaseImage(&img );
return 0;
}
|