void aplicar_original (const char *archivo_entrada, bool verbose, bool frames, const char *carpeta_frames){ static size_t bufsize = 1024; char namebuff[bufsize + 1]; const char *filename = basename(archivo_entrada); CvCapture *srcVid = abrir_video(archivo_entrada); CvSize dst_size; dst_size.width = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FRAME_WIDTH); dst_size.height = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FRAME_HEIGHT); double fps = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FPS); typedef struct CvVideoWriter CvVideoWriter; snprintf(namebuff, bufsize, "%s.original.avi", archivo_entrada); printf("\n\n%s\n\n",namebuff); CvVideoWriter* dstVid = abrir_writer(namebuff, fps, dst_size); if (verbose) { cvNamedWindow("procesanding", CV_WINDOW_AUTOSIZE); } unsigned int framenum = 0; while(1) { /* Capturo un frame */ IplImage *frame = cvQueryFrame(srcVid); framenum ++; if(framenum==100)break; cvWriteFrame(dstVid, frame); if (frames) { /* Escribo el frame */ snprintf(namebuff, bufsize, "%s/%s.original.%d.bmp", carpeta_frames, filename, framenum); cvSaveImage(namebuff, frame, NULL); } if (verbose) { cvShowImage("procesanding", frame); cvWaitKey(1); } } if (verbose) { cvDestroyWindow("procesanding"); } cvReleaseVideoWriter(&dstVid); cvReleaseCapture(&srcVid); }
void aplicar_filtro_color (const char *implementacion, const char *archivo_entrada, bool verbose, bool frames, const char *carpeta_frames, int rc, int gc, int bc, int threshold) { static size_t bufsize = 1024; char namebuff[bufsize + 1]; const char *filename = basename(archivo_entrada); CvCapture *srcVid = abrir_video(archivo_entrada); CvSize dst_size; dst_size.width = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FRAME_WIDTH); dst_size.height = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FRAME_HEIGHT); double fps = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FPS); int nchannels = 3; typedef struct CvVideoWriter CvVideoWriter; CvVideoWriter* dstVid = NULL; if (!frames) { snprintf(namebuff, bufsize, "%s.fcolor.avi", archivo_entrada); dstVid = abrir_writer(namebuff, fps, dst_size); } /* Armo la imagen destino. */ IplImage *dst = NULL; dst = cvCreateImage (dst_size, IPL_DEPTH_8U, nchannels); if (dst == NULL) { fprintf(stderr, "Error armando la imagen destino\n"); exit(EXIT_FAILURE); } if (verbose) { cvNamedWindow("procesanding", CV_WINDOW_AUTOSIZE); } unsigned int framenum = 0; FILE* f = fopen(COLOR_TIEMPOS, "a"); int iteraciones = 1; long int total = 0; while(1) { /* Capturo un frame */ IplImage *frame = cvQueryFrame(srcVid); framenum ++; if (frame == NULL) { break; } /* Aplico el filtro */ typedef void (fcolor_fn_t) (unsigned char*, unsigned char*, unsigned char, unsigned char, unsigned char, int, int, int); fcolor_fn_t *proceso; if (strcmp(implementacion, "c") == 0) { proceso = color_filter_c; } else { proceso = color_filter_asm; } int stop = 0; int start = 0; int tiempo = 0; MEDIR_TIEMPO_START(start); proceso((unsigned char *) frame->imageData, (unsigned char *) dst->imageData, rc, gc, bc, threshold, frame->height, frame->width); MEDIR_TIEMPO_STOP(stop); tiempo = stop - start; total = tiempo + total; fprintf(f, "%d %d %ld\n", iteraciones, tiempo, total); iteraciones ++; if (frames) { /* Escribo el frame */ snprintf(namebuff, bufsize, "%s/%s.fcolor.%d.bmp", carpeta_frames, filename, framenum); cvSaveImage(namebuff, dst, NULL); } else { cvWriteFrame(dstVid, dst); } if (verbose) { cvShowImage("procesanding", dst); cvWaitKey(1); } } FILE* g = fopen(COLOR_TOTALES, "a"); fprintf(g,"%ld\n", total); fclose(g); promedio = promedio + (total / global); fclose(f); if (verbose) { cvDestroyWindow("procesanding"); } cvReleaseImage(&dst); if (!frames) { cvReleaseVideoWriter(&dstVid); } cvReleaseCapture(&srcVid); }
void VideoToFile (const char *archivo_salida, Video& video_output, const string carpeta_frames, const bool saveFrames, uint frame_drop) { uint nchannels = 3; CvSize dst_size; dst_size.width = video_output.frame_width; #ifdef COLOR_PROCESSING dst_size.width = video_output.frame_width/nchannels; #else dst_size.width = video_output.frame_width; #endif dst_size.height = video_output.frame_height; typedef struct CvVideoWriter CvVideoWriter; CvVideoWriter* dstVid = NULL; dstVid = abrir_writer(archivo_salida, video_output.frame_rate, dst_size); /* Armo la imagen destino. */ IplImage *dst = cvCreateImage (dst_size, IPL_DEPTH_8U, nchannels); if (dst == NULL) { fprintf(stderr, "Error armando la imagen destino\n"); exit(EXIT_FAILURE); } unsigned char *dst_ptr = (unsigned char *) dst->imageData; for (uint cur_frame = 0; cur_frame < video_output.frame_count; cur_frame+= (frame_drop+1) ) { // cout << "Escribiendo frame " << cur_frame << endl; uint idx_dst=0; for (uint i = 0; i < video_output.frame_height; i++) { for (uint j = 0; j < video_output.frame_width; j++) { #ifdef COLOR_PROCESSING dst_ptr[idx_dst++] = video_output.frames[cur_frame][i][j]; #else dst_ptr[idx_dst++] = video_output.frames[cur_frame][i][j]; dst_ptr[idx_dst++] = video_output.frames[cur_frame][i][j]; dst_ptr[idx_dst++] = video_output.frames[cur_frame][i][j]; #endif } } // Save frame bmp to carpeta_frames folder. if(saveFrames) { string str_frame = carpeta_frames; str_frame+= "/"; str_frame+= "frame_"; str_frame+= to_string(cur_frame+1); str_frame+= ".bmp"; cvSaveImage(str_frame.c_str(), dst, NULL); } // Write frame to video. cvWriteFrame(dstVid, dst); } cvReleaseImage(&dst); cvReleaseVideoWriter(&dstVid); }