int main() { gun_net = (struct neuronet *)malloc(sizeof(struct neuronet)); notgun_net = (struct neuronet *)malloc(sizeof(struct neuronet)); if (netfromfile(gun_net, GUN_NEURO_PATH) == -1) { fprintf(stderr, "Can not open file %s: %s\n", strerror(errno), GUN_NEURO_PATH); return -1; } if (netfromfile(notgun_net, NOTGUN_NEURO_PATH) == -1) { fprintf(stderr, "Can not open file %s: %s\n", strerror(errno), NOTGUN_NEURO_PATH); return -1; } struct IplImage *frame; struct IplDev *dev1; FILE *fo; int f, i; char name[256]; f = 0; if ((dev1 = ipl_opendev(0, IPL_RGB_MODE)) == NULL) printf("error while creating device 0\n"); if (ipl_setparams(dev1, 320, 240, IPL_FORCE_SCALE_OFF) < 0) { fprintf(stderr, "error on changing cam params\n"); free(dev1); } while (1) { f++; if ((frame = ipl_getframe(dev1)) == NULL) { printf("error capturing curr1\n"); } ipl_scaleimg(&frame, 640, 480); if(neurowork(frame)) fprintf(stderr, "error in neurowork\n"); bzero(name, 256); sprintf(name, "/home/user/frame%d.ppm", f); fo = fopen(name, "w+"); fprintf(fo, "P3\n"); fprintf(fo, "%d %d\n", frame->width, frame->height); fprintf(fo, "255\n"); for (i = 0; i < frame->width * frame->height * frame->nchans; i++) fprintf(fo, "%u\n", frame->data[i]); fclose(fo); ipl_freeimg(&frame); } return 0; }
int main(int argc, char **argv) { int x, y; Window win1; GC gc1; XEvent event; XImage *ximg1; int flag; struct IplImage *prev1, *curr1, *motion; struct IplDev *dev1; time_t start, end; int f; f = 0; start = 0; end = 0; x = 0; y = 0; initX(); getXinfo(); win1 = openWindow(500, 500, 640, 480, 0, &gc1); XNextEvent(theDisplay, &event); ximg1 = XGetImage(theDisplay, win1, x, y, 640, 480, AllPlanes, ZPixmap); if(XInitImage(ximg1) == 0) { fprintf(stderr,"error: XInitImage\n"); return 1; } printf("first xgetimage done\n"); if ((dev1 = ipl_opendev(0, IPL_RGB_MODE)) == NULL) { printf("error while creating device 0\n"); return 1; } if (ipl_setparams(dev1, 320, 240, IPL_FORCE_SCALE_ON) < 0) { fprintf(stderr, "error on changing cam params\n"); free(dev1); return 1; } if ((prev1 = ipl_getframe(dev1)) == NULL) { printf("error capturing prev1\n"); return 1; } flag = 1; start = time(NULL); while (flag) { f++; end = time(NULL); if (end - start >= 1.0) { printf("fps = %i\n", f); f = 0; start = end; } if ((curr1 = ipl_getframe(dev1)) == NULL) { printf("error capturing curr1\n"); return 1; } motion = framescompare(curr1, prev1); ipl_scaleimg(&motion, 640, 480); camera_shoot(motion, ximg1, gc1, win1, x, y); ipl_freeimg(&prev1); prev1 = curr1; ipl_freeimg(&motion); XCheckTypedWindowEvent(theDisplay, win1, ButtonPress, &event); if (event.xbutton.button == 1) flag = 0; } ipl_freeimg(&curr1); XDestroyImage(ximg1); XDestroyWindow(theDisplay, win1); quitX(); return 0; }
int main() { int i, j, k, x, y, count; int wstep, hstep; struct IplDev *dev; struct IplImage *img, *tmp; FILE *fo; char name [256]; struct neuronet net; double *data; gun_net = (struct neuronet *)malloc(sizeof(struct neuronet)); notgun_net = (struct neuronet *)malloc(sizeof(struct neuronet)); if (netfromfile(gun_net, GUN_NEURO_PATH) == -1) { fprintf(stderr, "Can not open file %s: %s\n", strerror(errno), GUN_NEURO_PATH); return -1; } if (netfromfile(notgun_net, NOTGUN_NEURO_PATH) == -1) { fprintf(stderr, "Can not open file %s: %s\n", strerror(errno), NOTGUN_NEURO_PATH); return -1; } if ((dev = ipl_opendev(1, IPL_RGB_MODE)) == NULL) { printf("error while creating device\n"); return 1; } if ((img = ipl_readimg("/home/vadim/putin.png", IPL_RGB_MODE)) == NULL) { printf("error capturing frame\n"); return 1; } bzero(name, 256); sprintf(name, "/home/vadim/test_cam/test.ppm"); fo = fopen(name, "w+"); fprintf(fo, "P3\n"); fprintf(fo, "%d %d\n", img->width, img->height); fprintf(fo, "255\n"); /* for (y = 0; y < imgs[i]->width; y++) for (x = 0; x < imgs[i]->height; x++) fprintf(fo, "%u\n", imgs[i]->data[(y * imgs[i]->width + x)]);*/ for (i = 0; i < img->width * img->height * img->nchans; i++) fprintf(fo, "%u\n", img->data[i]); fclose(fo); count = 0; tmp = ipl_scaleimg(img, 320, 240); ipl_freeimg(&img); img = tmp; wstep = (int)((double)img->width / 20.0); hstep = (int)((double)img->height / 20.0); //first output for face, second for nonface; while (img->width >= 50 && img->height >= 50) { printf("w=%d h=%d\n", img->width, img->height); for (y = 0; y < img->height - 50; y += 50) { for (x = 0; x < img->width - 50; x += 50) { double **out; data = getdata(img, x, y, 50, 50); out = netfpass(&net, data); bzero(name, 256); if (out[net.nl - 1][0] > 0.9) { printf("face %lf %lf\n", out[net.nl - 1][0], out[net.nl - 1][1]); sprintf(name, "%s/%d.ppm", FACE_PATH, count); fo = fopen(name, "w+"); fprintf(fo, "P3\n"); fprintf(fo, "50 50\n"); fprintf(fo, "255\n"); for (i = y; i < y + 50; i++) for (j = x; j < x + 50; j++) for (k = 0; k < img->nchans; k++) fprintf(fo, "%u\n", img->data[img->nchans * (i * img->width + j) + k]); fclose(fo); count++; } for (i = 0; i < net.nl; i++) free(out[i]); free(out); free(data); } // printf("height=%d y=%d\n", img->height, y); } tmp = ipl_scaleimg(img, img->width - wstep, img->height - hstep); ipl_freeimg(&img); img = tmp; } return 0; }