Last active
June 29, 2019 09:44
-
-
Save dgzlopes/2d4a85961510d0a5e06d8d14723390b8 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
int main(int argc, char **argv) { | |
if (argc != 2) { | |
printf("Error: Usage %s image_file_name\n", argv[0]); | |
return EXIT_FAILURE; | |
} | |
//CV_LOAD_IMAGE_COLOR = 1 forces the resultant IplImage to be colour. | |
//CV_LOAD_IMAGE_GRAYSCALE = 0 forces a greyscale IplImage. | |
//CV_LOAD_IMAGE_UNCHANGED = -1 | |
IplImage* ImgOrigen = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR); | |
IplImage* ImgDestino = cvCreateImage(cvSize(ImgOrigen->width, ImgOrigen->height), IPL_DEPTH_8U, 3); | |
// Always check if the program can find the image file | |
if (!ImgDestino) { | |
printf("Error: file %s not found\n", argv[1]); | |
return EXIT_FAILURE; | |
} | |
// a visualization window is created with title: image file name | |
cvNamedWindow(argv[1], CV_WINDOW_AUTOSIZE); | |
// Img is shown in 'image' window | |
cvShowImage(argv[1], ImgOrigen); | |
int fila, columna, pasada, cont; | |
// nos movemos por filas | |
for (pasada = 0; pasada <= 1000; pasada++){ | |
for (fila = 0; fila < ImgDestino->height; fila++) { | |
unsigned char *pLeer = (unsigned char *) ImgOrigen->imageData + fila * ImgOrigen->widthStep; | |
unsigned char *pEscribir = (unsigned char *) ImgDestino->imageData + fila * ImgDestino->widthStep; | |
for (columna = 0; columna < ImgDestino->width; columna++) { | |
if (*pLeer-pasada > 0){ | |
*pEscribir++ = *pLeer-pasada; | |
*pLeer++; | |
} else { | |
*pEscribir++; | |
*pLeer++; | |
} | |
if (*pLeer-pasada > 0){ | |
*pEscribir++ = *pLeer-pasada; | |
pLeer++; | |
} else { | |
*pEscribir++; | |
*pLeer++; | |
} | |
if (*pLeer-pasada > 0){ | |
*pEscribir++ = *pLeer-pasada; | |
pLeer++; | |
} else { | |
*pEscribir++; | |
*pLeer++; | |
} | |
} | |
} | |
cvShowImage("Imagen Recolor", ImgDestino); | |
cvWaitKey(30); | |
} | |
cvWaitKey(0); | |
// memory release for images before exiting the application | |
cvReleaseImage(&ImgOrigen); | |
cvReleaseImage(&ImgDestino); | |
// Self-explanatory | |
cvDestroyWindow(argv[1]); | |
cvDestroyWindow("Imagen Recolor"); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment