Beispiel #1
0
void aplicar_colorizar (int tiempo, int cant_iteraciones, const char *nomb_impl, const char *nomb_arch_entrada, float alpha) {
	IplImage *src = 0;
	IplImage *dst = 0;
	CvSize dst_size;

	// Cargo la imagen
	if( (src = cvLoadImage (nomb_arch_entrada, CV_LOAD_IMAGE_COLOR)) == 0 )
		exit(EXIT_FAILURE);

	dst_size.width = src->width;
	dst_size.height = src->height;


	// Creo una IplImage para cada salida esperada
	if( (dst = cvCreateImage (dst_size, IPL_DEPTH_8U, 3) ) == 0 )
		exit(EXIT_FAILURE);

	typedef void (colorizar_fn_t) (unsigned char*, unsigned char*, int, int, int, int, float);

	colorizar_fn_t *proceso;

	if (strcmp(nomb_impl, "c") == 0) {
		proceso = colorizar_c;
	} else {
		proceso = colorizar_asm;
	}

	if (tiempo) {
		unsigned long long int start, end;

		MEDIR_TIEMPO_START(start);

		for(int i=0; i<cant_iteraciones; i++) {
			proceso((unsigned char*)src->imageData, (unsigned char*)dst->imageData, src->height, src->width, src->widthStep, dst->widthStep, alpha);
		}

		MEDIR_TIEMPO_STOP(end);

		imprimir_tiempos_ejecucion(start, end, cant_iteraciones);
	} else {
		proceso((unsigned char*)src->imageData, (unsigned char*)dst->imageData, src->height, src->width, src->widthStep, dst->widthStep, alpha);
	}

	copiar_bordes_color((unsigned char*)src->imageData, (unsigned char*)dst->imageData, src->height, src->width, src->widthStep);

	// Guardo imagen y libero las imagenes
	char nomb_arch_salida[256];

	memset(nomb_arch_salida, 0, 256);

	sprintf(nomb_arch_salida, "%s.colorizar.alpha-%3.2f.%s.bmp", nomb_arch_entrada, alpha, nomb_impl);

	cvSaveImage(nomb_arch_salida, dst, NULL);

	cvReleaseImage(&src);
	cvReleaseImage(&dst);
}
Beispiel #2
0
void aplicar_sierpinski(configuracion_t *config)
{
	unsigned long a,b;
	a = 0;
	b = 0;
	MEDIR_TIEMPO_START(a);
	sierpinski_fn_t *sierpinski = SWITCH_C_ASM ( config, sierpinski_c, sierpinski_asm ) ;
	buffer_info_t info = config->src;
	MEDIR_TIEMPO_START(a);	
	sierpinski(info.bytes, config->dst.bytes, info.width, info.height, info.width_with_padding, config->dst.width_with_padding);
        MEDIR_TIEMPO_STOP(b);
        fprintf(config->archivo_mediciones, "%lu\n", b-a);
}
Beispiel #3
0
void correr_filtro_imagen( configuracion_t* config, aplicador_fn_t aplicador )
{
  snprintf( config->archivo_salida, sizeof( config->archivo_salida ), "%s/%s.%s.%s%s.bmp",
            config->carpeta_salida, basename( config->archivo_entrada ),
            config->nombre_filtro, C_ASM( config ), config->extra_archivo_salida );
  snprintf( config->archivo_tiempo, sizeof( config->archivo_tiempo ), "%s/%s.%s.%s%s.txt",
            config->carpeta_salida, basename( config->archivo_entrada ),
            config->nombre_filtro, C_ASM( config ), config->extra_archivo_salida );

  if ( config->nombre )
  {
    printf( "%s\n", basename( config->archivo_salida ) );
  }
  else
  {
    opencv_abrir_imagenes( config );

    if ( config->tiempo )
    {
      FILE* t;
      unsigned long start, end;
      t = fopen( config->archivo_tiempo, "w" );

      while ( config->cant_iteraciones-- )
      {
        MEDIR_TIEMPO_START( start );
        aplicador( config );
        MEDIR_TIEMPO_STOP( end );
        fprintf( t, "%lu\n", ( end - start ) );
      }

      fclose( t );
    }
    else
    {
      aplicador( config );
    }

    opencv_liberar_imagenes( config );
  }
}
Beispiel #4
0
void correr_filtro_imagen(configuracion_t *config, aplicador_fn_t aplicador)
{
	snprintf(config->archivo_salida, sizeof(config->archivo_salida), "%s/%s.%s.%s%s.bmp",
                 config->carpeta_salida, basename(config->archivo_entrada),
                 config->nombre_filtro, C_ASM(config), config->extra_archivo_salida );

	if (config->nombre)
	{
		printf("%s\n", basename(config->archivo_salida));
	}
	else
	{
		opencv_abrir_imagenes(config);
		unsigned long start, end;
		MEDIR_TIEMPO_START(start);
		aplicador(config);
		MEDIR_TIEMPO_STOP(end);
		unsigned long delta = end - start;
		printf("%lu \n",delta);
		opencv_liberar_imagenes(config);
	}
}
Beispiel #5
0
int main( int argc, char** argv ) {
	int siguiente_opcion;

	// Opciones
	const char* const op_cortas = "hi:vt:f:";

	const struct option op_largas[] = {
		{ "help", 0, NULL, 'h' },
		{ "implementacion", 1, NULL, 'i' },
		{ "verbose", 0, NULL, 'v' },
		{ "tiempo", 1, NULL, 't' },
		{ "frames", 1, NULL, 'f' },
		{ NULL, 0, NULL, 0 }
	};

	// Parametros
	const char *nombre_implementacion = NULL;
	int cant_iteraciones = 1;

	// Flags de opciones
	bool verbose = false;
	int tiempo = 0;
	bool frames = false;
	const char *carpeta_frames = NULL;

	// Guardar nombre del programa para usarlo en la ayuda
	nombre_programa = argv[0];

	// Si se ejecuta sin parametros ni opciones
	if (argc == 1) {
		imprimir_ayuda ( );

		exit ( EXIT_SUCCESS );
	}

	// Procesar opciones
	while (1) {
		siguiente_opcion = getopt_long ( argc, argv, op_cortas, op_largas, NULL);

		// No hay mas opciones
		if ( siguiente_opcion == -1 )
			break;

		// Procesar opcion
		switch ( siguiente_opcion ) {
			case 'h' : /* -h o --help */
				imprimir_ayuda ( );
				exit ( EXIT_SUCCESS );
				break;
			case 'i' : /* -i o --implementacion */
				nombre_implementacion = optarg;
				break;
			case 't' : /* -t o --tiempo */
				tiempo = 1;
				cant_iteraciones = atoi ( optarg );
				break;
			case 'v' : /* -v o --verbose */
				verbose = true;
				break;
			case 'f' : /* -f o --frames */
			    frames = 1;
			    carpeta_frames = optarg;
			    break;
			case '?' : /* opcion no valida */
				imprimir_ayuda ( );
				exit ( EXIT_SUCCESS );
			default : /* opcion no valida */
				abort ( );
		}
	}

	// Verifico nombre del proceso
	char *nomb_proceso = argv[optind++];

	if (nomb_proceso == NULL ||
		(strcmp(nomb_proceso, "miniature") != 0			&&
		strcmp(nomb_proceso, "decode") != 0			&&
		strcmp(nomb_proceso, "fcolor") != 0			&&
		strcmp(nomb_proceso, "original") != 0)) {
		imprimir_ayuda ( );

		exit ( EXIT_SUCCESS );
	}

	// Verifico nombre de la implementacion
	if (nombre_implementacion == NULL ||
		(strcmp(nombre_implementacion, "c") != 0 &&
		strcmp(nombre_implementacion, "asm") != 0)) {
		imprimir_ayuda ( );

		exit ( EXIT_SUCCESS );
	}

	// Verifico nombre de archivo
	const char *nomb_arch_entrada = argv[optind++];

	if (nomb_arch_entrada == NULL) {
		imprimir_ayuda ( );

		exit ( EXIT_SUCCESS );
	}
	

	if (access( nomb_arch_entrada, F_OK ) == -1) {
		printf("Error al intentar abrir el archivo: %s.\n", nomb_arch_entrada);

		exit ( EXIT_SUCCESS );
	}

	// Verifico carpeta de frames
	if ( frames ) {
        struct stat s;
        int err = stat(carpeta_frames, &s);

        if (err == -1 || !S_ISDIR(s.st_mode)) {
            fprintf(stderr, "Carpeta de Frames invalida: %s.\n", carpeta_frames);
            exit (EXIT_FAILURE) ;
        }
	}

	// Imprimo info
	printf ( "Procesando...\n");
	printf ( "  Filtro             : %s\n", nomb_proceso);
	printf ( "  Implementación     : %s\n", nombre_implementacion);
	printf ( "  Archivo de entrada : %s\n", nomb_arch_entrada);

	// Procesar imagen
//	FILE* f = fopen("Tiempos totales.txt","a");
	int t = 0;
	global = cant_iteraciones;
	while(t<cant_iteraciones){
		if (strcmp(nomb_proceso, "fcolor") == 0) {
			int threshold, gc, rc, bc;
			threshold = atoi(argv[argc - 1]);
			bc = atoi(argv[argc - 2]);
			gc = atoi(argv[argc - 3]);
			rc = atoi(argv[argc - 4]);
			aplicar_filtro_color(nombre_implementacion, nomb_arch_entrada,
								verbose, frames, carpeta_frames,
								rc, gc, bc, threshold);
		} else if (strcmp(nomb_proceso, "decode") == 0) {

			aplicar_decode(nombre_implementacion, nomb_arch_entrada,
							verbose);


		} else if (strcmp(nomb_proceso, "miniature") == 0) {
			int iters;
			float bottomPlane, topPlane;
			iters = atoi(argv[argc - 1]);
			bottomPlane = strtof(argv[argc - 2], NULL);
			topPlane = strtof(argv[argc - 3], NULL);

			int start = 0;
			
			int stop = 0;
			
			long long int tiempo = 0;

			MEDIR_TIEMPO_START(start);
			aplicar_miniature(nombre_implementacion, nomb_arch_entrada,
						verbose, frames, carpeta_frames,
						topPlane, bottomPlane, iters);
			MEDIR_TIEMPO_STOP(stop);
			
			tiempo = start - stop;
			
			//fprintf(f,"%d %lld \n", t, tiempo);
		} else if (strcmp(nomb_proceso, "original") == 0) {
			aplicar_original(nomb_arch_entrada, verbose, frames,
							 carpeta_frames);
		}
		t++;
	}
    FILE* h = fopen(PROMEDIO, "a");
	fprintf(h,"%ld \n", promedio);
	
	fclose(h);
	return 0;
}
Beispiel #6
0
void aplicar_decode   (const char *implementacion,
                       const char *archivo_entrada,
                       bool verbose)
{
    const int long_texto=10000;
    unsigned char mensaje_salida[long_texto];

    IplImage *src = 0;
	IplImage *dst = 0;

	// Cargo la imagen
	if( (src = cvLoadImage (archivo_entrada, CV_LOAD_IMAGE_COLOR)) == 0 )
		exit(EXIT_FAILURE);

	// Creo una IplImage para cada salida esperada
	if( (dst = cvCreateImage (cvGetSize (src), IPL_DEPTH_8U, 1) ) == 0 )
		exit(EXIT_FAILURE);

	typedef void (decode_t) (unsigned char*, unsigned char*, int, int, int);

	decode_t *proceso;

	if (strcmp(implementacion, "c") == 0) {
		proceso = decode_c;
	} else {
		proceso = decode_asm;
	}

    FILE* f = fopen(DECODE_TIEMPOS, "a");
    int iteraciones = 1;
    long int total = 0;

    for (int r = 0; r <= 99; r++){

    int tiempo = 0;
    int start = 0;
    int stop = 0;

    MEDIR_TIEMPO_START(start);

    proceso((unsigned char*)src->imageData, (unsigned char*)mensaje_salida, long_texto, src->width, src->height);

    MEDIR_TIEMPO_STOP(stop);

    tiempo = stop - start;
    total = total + tiempo;

    fprintf(f, "%d %d %ld\n", iteraciones, tiempo, total);

    iteraciones ++;

    }
	FILE* g = fopen(DECODE_TOTALES, "a");
	fprintf(g,"%ld\n", total);
    fclose(g);
    
    fclose(f);
   	promedio = promedio + (total / global);

	// Guardo imagen y libero las imagenes
    char filename[255];

    sprintf(filename,"%s.mensaje.%s.txt",archivo_entrada,implementacion);
    FILE* decoded_txt = fopen(filename,"w");
    mensaje_salida[long_texto-1]='\0';
    fprintf(decoded_txt,"%s",mensaje_salida);
    fclose(decoded_txt);
//	printf ( "  Salida en          : %s\n", filename);
	cvReleaseImage(&src);
	cvReleaseImage(&dst);
}
Beispiel #7
0
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);
}
Beispiel #8
0
void aplicar_waves (int tiempo, int cant_iteraciones, const char *nomb_impl, const char *nomb_arch_entrada, float x_scale, float y_scale, float g_scale) {
	IplImage *src = 0;
	IplImage *dst = 0;
	CvSize dst_size;

	// Cargo la imagen
	if( (src = cvLoadImage (nomb_arch_entrada, CV_LOAD_IMAGE_GRAYSCALE)) == 0 )
		exit(EXIT_FAILURE);

	dst_size.width = src->width;
	dst_size.height = src->height;

	// Creo una IplImage para cada salida esperada
	if( (dst = cvCreateImage (dst_size, IPL_DEPTH_8U, 1) ) == 0 )
		exit(EXIT_FAILURE);

	// Chequeo de parametros
	if (!(x_scale <=  32.0 && x_scale >= 0.0 &&
		  y_scale <=  32.0 && y_scale >= 0.0 &&
		  g_scale <= 255.0 && g_scale >= 0.0)) {
		imprimir_ayuda();

		cvReleaseImage(&src);
		cvReleaseImage(&dst);

		exit ( EXIT_SUCCESS );
	}

	typedef void (waves_fn_t) (unsigned char*, unsigned char*, int, int, int, float, float, float);

	waves_fn_t *proceso;

	if (strcmp(nomb_impl, "c") == 0) {
		proceso = waves_c;
	} else {
		proceso = waves_asm;
	}

	if (tiempo) {
		unsigned long long int start, end;

		MEDIR_TIEMPO_START(start);

		for(int i=0; i<cant_iteraciones; i++) {
			proceso((unsigned char*)src->imageData, (unsigned char*)dst->imageData, src->height, src->width, src->widthStep, x_scale, y_scale, g_scale);
		}

		MEDIR_TIEMPO_STOP(end);

		imprimir_tiempos_ejecucion(start, end, cant_iteraciones);
	} else {
		proceso((unsigned char*)src->imageData, (unsigned char*)dst->imageData, src->height, src->width, src->widthStep, x_scale, y_scale, g_scale);
	}

	// Guardo imagen y libero las imagenes
	char nomb_arch_salida[256];

	memset(nomb_arch_salida, 0, 256);

	sprintf(nomb_arch_salida, "%s.waves.x_scale-%3.2f.y_scale-%3.2f.g_scale-%3.2f.%s.bmp", nomb_arch_entrada, x_scale, y_scale, g_scale, nomb_impl);

	cvSaveImage(nomb_arch_salida, dst, NULL);

	cvReleaseImage(&src);
	cvReleaseImage(&dst);
}
Beispiel #9
0
void aplicar_umbralizar (int tiempo, int cant_iteraciones, const char *nomb_impl, const char *nomb_arch_entrada, unsigned char min, unsigned char max, unsigned char q) {
	IplImage *src = 0;
	IplImage *dst = 0;
	CvSize dst_size;

	// Cargo la imagen
	if( (src = cvLoadImage (nomb_arch_entrada, CV_LOAD_IMAGE_GRAYSCALE)) == 0 )
		exit(EXIT_FAILURE);

	dst_size.width = src->width;
	dst_size.height = src->height;

	// Creo una IplImage para cada salida esperada
	if( (dst = cvCreateImage (dst_size, IPL_DEPTH_8U, 1) ) == 0 )
		exit(EXIT_FAILURE);

	// Chequeo de parametros
	if (!(min <= max && min >= 0 && max <= 255 && q >= 0 && q <= 255)) {
		imprimir_ayuda();

		cvReleaseImage(&src);
		cvReleaseImage(&dst);

		exit ( EXIT_SUCCESS );
	}

	typedef void (umbralizar_fn_t) (unsigned char*, unsigned char*, int, int, int, unsigned char, unsigned char, unsigned char);

	umbralizar_fn_t *proceso;

	if (strcmp(nomb_impl, "c") == 0) {
		proceso = umbralizar_c;
	} else {
		proceso = umbralizar_asm;
	}

	if (tiempo) {
		unsigned long long int start, end;

		MEDIR_TIEMPO_START(start);

		for(int i=0; i<cant_iteraciones; i++) {
			proceso((unsigned char*)src->imageData, (unsigned char*)dst->imageData, src->height, src->width, src->widthStep, min, max, q);
		}

		MEDIR_TIEMPO_STOP(end);

		imprimir_tiempos_ejecucion(start, end, cant_iteraciones);
	} else {
		proceso((unsigned char*)src->imageData, (unsigned char*)dst->imageData, src->height, src->width, src->widthStep, min, max, q);
	}

	// Guardo imagen y libero las imagenes
	char nomb_arch_salida[256];

	memset(nomb_arch_salida, 0, 256);

	sprintf(nomb_arch_salida, "%s.umbralizar.min-%d.max-%d.q-%d.%s.bmp", nomb_arch_entrada, min, max, q, nomb_impl);

	cvSaveImage(nomb_arch_salida, dst, NULL);

	cvReleaseImage(&src);
	cvReleaseImage(&dst);
}