Download document (10.35 MB) - Escuela Superior de Informática ...

Download document (10.35 MB) - Escuela Superior de Informática ... Download document (10.35 MB) - Escuela Superior de Informática ...

11.07.2015 Views

162 Capítulo D. Código fuente833 gboolean createAdquisitionVideo(GtkWidget *widget){834835 GdkGLContext *glcontext;836 GdkGLDrawable *gldrawable;837838 if (img != NULL) {839 glcontext = gtk_widget_get_gl_context (widget);840 gldrawable = gtk_widget_get_gl_drawable (widget);841842843 if( !imageAdquisition) {844 imageAdquisition = cvCreateImage( cvSize(img->width,845 img->height),846 IPL_DEPTH_8U, img->nChannels );847 }848849 cvResize(img, imageAdquisition, CV_INTER_LINEAR );850 cvFlip( imageAdquisition, imageAdquisition, 0 );851852 if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)){853 g_print ("*** ERROR: Problem in dibujar\n");854 }855856 glClear( GL_COLOR_BUFFER_BIT );857 glLoadIdentity();858 glTranslatef(0.0f, 0.0f,-1.0f);859860 GLenum format = IsBGR(imageAdquisition->channelSeq)861 ? GL_BGR_EXT : GL_RGBA;862863 if (!init) {864 glGenTextures(1, &imageID1);865 glBindTexture(GL_TEXTURE_2D, imageID1);866 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);867 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);868 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);869 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageAdquisition->width,870 imageAdquisition->height, 0,871 format, GL_UNSIGNED_BYTE, imageAdquisition->imageData);872 init= 1; // init is over873 }874 else {875 glBindTexture(GL_TEXTURE_2D, imageID1);876 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imageAdquisition->width,877 imageAdquisition->height, format, GL_UNSIGNED_BYTE,878 imageAdquisition->imageData);879 }880 glPushMatrix();881 glEnable(GL_TEXTURE_2D);882883 glBegin(GL_QUADS);{884 glTexCoord2f(0, 0); glVertex3f(-1, -1, 0);885 glTexCoord2f(0, 1); glVertex3f(-1, 1, 0);886 glTexCoord2f(1, 1); glVertex3f(1, 1, 0);887 glTexCoord2f(1, 0); glVertex3f(1, -1, 0);888889 }glEnd();890 glPopMatrix();891892 if (gdk_gl_drawable_is_double_buffered (gldrawable)){

D.2. Código fuente de los módulos más relevantes. 163893 gdk_gl_drawable_swap_buffers (gldrawable);894 }895 else{896 glFlush ();897 }898899 gdk_gl_drawable_gl_end (gldrawable);900901 while (g_main_iteration(FALSE));902 }903904 return TRUE;905906 }Funciones más relevantes de openCVFunctions.c1 /************************************************************************2 * Funcion: init_video_process3 * Descripcion: Procesa el fichero AVI, mediante algoritmo de Lucas-Kanade4 * se crean los puntos 2D y 3D y se guardan en un fichero .mf5 * Entradas: fichero --> Puntero al nombre del fichero a abrir.6 * Salidas: Devuelve -1 si hubo algun error. 0 en caso contrario.7 ************************************************************************/8 int init_video_process(gchar *ficheroAux) {910 CvCapture *capture;11 IplImage *frame;12 numFrame = 0;1314 int c;1516 gchar *fichero = g_strdup (ficheroAux);17 free_memory();1819 /* Si el archivo .mf y .gff existe no hacemos nada. */20 if (write_mf_file(fichero) == 021 && write_face_gestures_file(fichero) == 0) {2223 /* memoria necesaria para la captura */24 storage = cvCreateMemStorage(0);2526 capture = cvCaptureFromAVI(fichero);2728 initializeFaceCapture();29 if(!capture){30 return -1;31 }32 for(;;) {3334 if(!cvGrabFrame(capture)){35 break;36 }37 frame = cvRetrieveFrame(capture);38 if(!frame){39 break;40 }41 else {42

D.2. Código fuente <strong>de</strong> los módulos más relevantes. 163893 gdk_gl_drawable_swap_buffers (gldrawable);894 }895 else{896 glFlush ();897 }898899 gdk_gl_drawable_gl_end (gldrawable);900901 while (g_main_iteration(FALSE));902 }903904 return TRUE;905906 }Funciones más relevantes <strong>de</strong> openCVFunctions.c1 /************************************************************************2 * Funcion: init_vi<strong>de</strong>o_process3 * Descripcion: Procesa el fichero AVI, mediante algoritmo <strong>de</strong> Lucas-Kana<strong>de</strong>4 * se crean los puntos 2D y 3D y se guardan en un fichero .mf5 * Entradas: fichero --> Puntero al nombre <strong>de</strong>l fichero a abrir.6 * Salidas: Devuelve -1 si hubo algun error. 0 en caso contrario.7 ************************************************************************/8 int init_vi<strong>de</strong>o_process(gchar *ficheroAux) {910 CvCapture *capture;11 IplImage *frame;12 numFrame = 0;1314 int c;1516 gchar *fichero = g_strdup (ficheroAux);17 free_memory();1819 /* Si el archivo .mf y .gff existe no hacemos nada. */20 if (write_mf_file(fichero) == 021 && write_face_gestures_file(fichero) == 0) {2223 /* memoria necesaria para la captura */24 storage = cvCreateMemStorage(0);2526 capture = cvCaptureFromAVI(fichero);2728 initializeFaceCapture();29 if(!capture){30 return -1;31 }32 for(;;) {3334 if(!cvGrabFrame(capture)){35 break;36 }37 frame = cvRetrieveFrame(capture);38 if(!frame){39 break;40 }41 else {42

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!