Skip to content

Instantly share code, notes, and snippets.

@dgzlopes
Last active June 29, 2019 09:44
Show Gist options
  • Save dgzlopes/3bfe5941ab30bddccad3686e827a634d to your computer and use it in GitHub Desktop.
Save dgzlopes/3bfe5941ab30bddccad3686e827a634d 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 = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR);
// 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* ImgMitad = cvCreateImage(cvSize(Img->width, Img->height), IPL_DEPTH_8U, 3);
int fila, columna;
int mitad = Img->height / 2;
// nos movemos por filas
for (fila = 0; fila < Img->height/2; fila++) {
// abajo de original - arriba de imagen creada
unsigned char *pLeer1 = (unsigned char *) Img->imageData + (fila+ mitad)* Img->widthStep;
unsigned char *pEscribir1 = (unsigned char *) ImgMitad->imageData + fila * ImgMitad->widthStep;
unsigned char *pLeer2 = (unsigned char *) Img->imageData + fila * Img->widthStep;
unsigned char *pEscribir2 = (unsigned char *) ImgMitad->imageData + (fila + mitad) * ImgMitad->widthStep;
for (columna = 0; columna < Img->width; columna++) {
*pEscribir2++ = *pLeer2++;
*pEscribir2++ = *pLeer2++;
*pEscribir2++ = *pLeer2++;
*pEscribir1++ = *pLeer1++;
*pEscribir1++ = *pLeer1++;
*pEscribir1++ = *pLeer1++;
}
}
// crea y muestras las ventanas con las im genes
cvNamedWindow("Imagen Mitades", CV_WINDOW_AUTOSIZE);
cvShowImage("Imagen Mitades", ImgMitad);
cvWaitKey(0);
// memory release for images before exiting the application
cvReleaseImage(&Img);
cvReleaseImage(&ImgMitad);
// Self-explanatory
cvDestroyWindow(argv[1]);
cvDestroyWindow("Imagen Mitades");
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment