Skip to content

Instantly share code, notes, and snippets.

@dgzlopes
Last active June 29, 2019 09:44
Show Gist options
  • Save dgzlopes/54891e39535e9e94c8323bfaaf8dbd3c to your computer and use it in GitHub Desktop.
Save dgzlopes/54891e39535e9e94c8323bfaaf8dbd3c to your computer and use it in GitHub Desktop.
#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* Img = cvCreateImage(cvSize(256, 256), IPL_DEPTH_8U, 3);
// Always check if the program can find the image file
if (!Img) {
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], Img);
// Crea la imagen para la componete azul
IplImage* ImgMix = cvCreateImage(cvSize(Img->width, Img->height), IPL_DEPTH_8U, 3);
int fila, columna;
// nos movemos por filas
for (fila = 0; fila < Img->height; fila++) {
unsigned char *pEscribir = (unsigned char *) ImgMix->imageData + fila * ImgMix->widthStep;
for (columna = 0; columna < Img->width; columna++) {
*pEscribir++ = fila;
*pEscribir++ = fila;
*pEscribir++ = fila;
}
}
// crea y muestras las ventanas con las im genes
cvNamedWindow("Imagen Recolor", CV_WINDOW_AUTOSIZE);
cvShowImage("Imagen Recolor", ImgMix);
cvWaitKey(0);
// memory release for images before exiting the application
cvReleaseImage(&Img);
cvReleaseImage(&ImgMix);
// 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