Last active
June 29, 2019 09:44
-
-
Save dgzlopes/ca3123c0c95d467d61cddd6364fb9d1b 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> | |
#include <opencv/cv.h> | |
#include <opencv/highgui.h> | |
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* ImgOriginal = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR); | |
IplImage* ImgOut = cvCreateImage(cvSize(ImgOriginal->width, ImgOriginal->height*4), IPL_DEPTH_8U, 3); | |
// Always check if the program can find the image file | |
if (!ImgOut) { | |
printf("Error: file %s not found\n", argv[1]); | |
return EXIT_FAILURE; | |
} | |
int fila, columna; | |
int original = ImgOriginal->height; | |
// nos movemos por filas | |
for (fila = 0; fila < ImgOriginal->height; fila++) { | |
unsigned char *pLeer = (unsigned char *) ImgOriginal->imageData + fila * ImgOriginal->widthStep; | |
unsigned char *pEscribir = (unsigned char *) ImgOut->imageData + fila * ImgOut->widthStep; | |
unsigned char *pEscribir2 = (unsigned char *) ImgOut->imageData + original++ * ImgOut->widthStep; | |
for (columna = 0; columna < ImgOriginal->width; columna++) { | |
*pEscribir++ = *pLeer++; | |
*pEscribir++ = *pLeer++; | |
*pEscribir++ = *pLeer++; | |
*pEscribir2++ = *pLeer++; | |
*pEscribir2++ = *pLeer++; | |
*pEscribir2++ = *pLeer++; | |
} | |
} | |
cvNamedWindow("Imagen Original", CV_WINDOW_AUTOSIZE); | |
cvShowImage("Imagen Original", ImgOriginal); | |
// crea y muestras las ventanas con las im genes | |
cvNamedWindow("Imagen Big", CV_WINDOW_AUTOSIZE); | |
cvShowImage("Imagen Big", ImgOut); | |
cvWaitKey(0); | |
// memory release for images before exiting the application | |
cvReleaseImage(&ImgOut); | |
// 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