#include #include /* useful function for reading in ppm/pgm headers */ void getline(char *buf,FILE *fp) { //read until end of line from fp char *p=buf; char c; while ((c=fgetc(fp))!='\n') { *p=c; p++; } *p='\0';//terminate as string } /* some useful variables */ CvSize imagesize; int sizeX,sizeY; IplImage *ip; unsigned char *rawptr; char tstring[1000],inchar; FILE *fp; char fname[100]; int radius; CvPoint centre; int colour; int main(int argc,char **argv) { int i; /* read in image */ printf("name of input?\n"); scanf("%s",fname); fp = fopen(fname, "rb"); if (!fp) { fprintf(stderr, "Unable to open file `%s'\n", fname); exit(1); } getline(tstring,fp); fprintf(stderr,"scanned %s\n",tstring); if (! ((tstring[0]=='P') && (tstring[1]=='5')) ) { fprintf(stderr,"can only work with P5 versions of ppm images\n"); exit(-1); } /*Check for comment and swallow whole line */ getline(tstring,fp); while (tstring[0]=='#') getline(tstring,fp); //skip comments if (sscanf(tstring, "%d %d", &sizeX, &sizeY) != 2) { fprintf(stderr, "Error loading image `%s'\n", fname); exit(1); } getline(tstring,fp); while (tstring[0]=='#') getline(tstring,fp); //skip comments // throw away the maxval imagesize.width=sizeX; imagesize.height=sizeY; ip= cvCreateImage(imagesize,IPL_DEPTH_8U,1);// 3 channels RGB //default is 4 bytes align /* read image in one line at a time */ rawptr= (unsigned char *) ip->imageData; for (i=0;iwidthStep; //increment padded line } fclose(fp); printf("successfully read in %d wide %d high image\n",ip->width,ip->height); /* process image */ /* make up white colour */ colour = 255; /* fix centre */ printf("x coord of centre \n"); scanf("%d",¢re.x); /*should check is inside image!! */ printf("y coord of centre \n"); scanf("%d",¢re.y); /*should check is inside image!! */ printf("radius \n"); scanf("%d",&radius); cvCircle(ip,centre,radius,colour,0); //0 for unfilled /* output image */ printf("name of output?\n"); scanf("%s",fname); fp = fopen(fname, "wb"); fprintf(fp,"P5\n%d %d\n255\n",ip->width,ip->height); /* write image in out line at a time */ rawptr= (unsigned char *) ip->imageData; for (i=0;iwidthStep; //increment padded line } fclose(fp); }