/****************************************************************** * createXWindow *******************************************************************/ void createXWindow() { XSetWindowAttributes theWindowAttributes; unsigned long theWindowMask; Arg argList[MAX_ARGS]; /* resource list */ XGCValues theGCValues; /* return value from XCreateGC */ outerWindow = XtWindow( topLevel ); cameraWindow = XtWindow( cameraview ); frontWindow = XtWindow( frontview ); topWindow = XtWindow( topview ); sideWindow = XtWindow( sideview ); /* Create graphics contexts */ if ((cameraGC = XCreateGC( theDisplay, cameraWindow, (unsigned long) 0, &theGCValues)) == 0) quitX("initX couldn't get a graphic context"); if ((frontGC = XCreateGC( theDisplay, frontWindow, (unsigned long) 0, &theGCValues)) == 0) quitX("initX couldn't get a graphic context"); if ((topGC = XCreateGC( theDisplay, topWindow, (unsigned long) 0, &theGCValues)) == 0) quitX("initX couldn't get a graphic context"); if ((sideGC = XCreateGC( theDisplay, sideWindow, (unsigned long) 0, &theGCValues)) == 0) quitX("initX couldn't get a graphic context"); XSetForeground(theDisplay, cameraGC, WhitePen); XSetBackground(theDisplay, cameraGC, BlackPen); XSetForeground(theDisplay, frontGC, BlackPen); XSetBackground(theDisplay, frontGC, GrayPen); XSetForeground(theDisplay, topGC, BlackPen); XSetBackground(theDisplay, topGC, GrayPen); XSetForeground(theDisplay, sideGC, BlackPen); XSetBackground(theDisplay, sideGC, GrayPen); }
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; }