Created
January 31, 2019 09:11
-
-
Save dgzlopes/918a2e3312ff09d14cfefe83d25761d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
// incluimos la librería opencv | |
#include <opencv/cv.h> | |
#include <opencv/highgui.h> | |
// argc: int numero de argumentos | |
// argv: char ** argv[0] = 'mi.exe' / argv[1] = 'fruits.jpg' | |
int main(int argc, char** argv) { | |
// el programa ha de tener más de un argumento. Si sólo tenemos uno, | |
// es el nombre del programa | |
if (argc != 2) { | |
printf("Usage: %s image_file_name\n", argv[0]); | |
return EXIT_FAILURE; | |
} | |
//CV_LOAD_IMAGE_COLOR = 1 forces the resultant IplImage to be colour. Esté | |
// como esté en disco duro, en memoria tendrá tres canales | |
//CV_LOAD_IMAGE_GRAYSCALE = 0 forces a greyscale IplImage. Sea como sea en | |
// disco duro, en memoria tendrá un canal. | |
//CV_LOAD_IMAGE_UNCHANGED = -1 -> mismos canales en disco duro que en memoria | |
// carga un fichero de imagen como argumento más una opción respecto al | |
// fichero. IplImage es un Struct. | |
IplImage* Img1 = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED); | |
// Always check if the program can find a file. SI no hay datos, significa | |
// que no fue capaz de abrir el fichero | |
if (!Img1) { | |
printf("Error: fichero %s no valido\n", argv[1]); | |
return EXIT_FAILURE; | |
} | |
// a visualization window is created with title 'image' y una política de | |
// escalado | |
cvNamedWindow(argv[1], CV_WINDOW_NORMAL); | |
// img is shown in 'image' window. Usamos el título de la ventana como | |
// identificador (primer param), que en este caso es el nombre de la imagen | |
cvShowImage(argv[1], Img1); | |
// paramos la ejecución del programa hasta que pulsemos una tecla. En caso | |
// de poner un numerito es el tiempo en milisegundos que ha de estar parao | |
cvWaitKey(0); | |
// memory release for img before exiting the application | |
cvReleaseImage(&Img1); | |
// Self-explanatory | |
cvDestroyWindow(argv[1]); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment