Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
SecurityCam - cvUtils.cpp

cvUtils.cpp

Caricato da: Carlduke
Scarica il programma completo

  1. #include "cvUtils.h"
  2.  
  3. void cvShowManyImages(const char* title, int nArgs, ...)
  4. {
  5.  
  6.     // img - Used for getting the arguments
  7.     IplImage *img;
  8.  
  9.     // DispImage - the image in which input images are to be copied
  10.     IplImage *DispImage;
  11.  
  12.     int size;
  13.     int i;
  14.     int m, n;
  15.     int x, y;
  16.  
  17.     // w - Maximum number of images in a row
  18.     // h - Maximum number of images in a column
  19.     int w, h;
  20.  
  21.     // scale - How much we have to resize the image
  22.     float scale;
  23.     int max;
  24.  
  25.     // If the number of arguments is lesser than 0 or greater than 12
  26.     // return without displaying
  27.     if(nArgs <= 0) {
  28.         printf("Number of arguments too small....\n");
  29.         return;
  30.     }
  31.     else if(nArgs > 12) {
  32.         printf("Number of arguments too large....\n");
  33.         return;
  34.     }
  35.    
  36.     else if (nArgs == 1) {
  37.         w = h = 1;
  38.         size = 300;
  39.     }
  40.     else if (nArgs == 2) {
  41.         w = 2; h = 1;
  42.         size = 300;
  43.     }
  44.     else if (nArgs == 3 || nArgs == 4) {
  45.         w = 2; h = 2;
  46.         size = 300;
  47.     }
  48.     else if (nArgs == 5 || nArgs == 6) {
  49.         w = 3; h = 2;
  50.         size = 200;
  51.     }
  52.     else if (nArgs == 7 || nArgs == 8) {
  53.         w = 4; h = 2;
  54.         size = 200;
  55.     }
  56.     else {
  57.         w = 4; h = 3;
  58.         size = 150;
  59.     }
  60.  
  61.     // Create a new 3 channel image
  62.     DispImage = cvCreateImage( cvSize(100 + size*w, 60 + size*h), 8, 3 );
  63.  
  64.     // Used to get the arguments passed
  65.     va_list args;
  66.     va_start(args, nArgs);
  67.  
  68.     // Loop for nArgs number of arguments
  69.     for (i = 0, m = 20, n = 20; i < nArgs; i++, m += (20 + size)) {
  70.  
  71.         // Get the Pointer to the IplImage
  72.         img = va_arg(args, IplImage*);
  73.  
  74.         // Check whether it is NULL or not
  75.         // If it is NULL, release the image, and return
  76.         if(img == 0)
  77.                 {
  78.             printf("Invalid arguments\n");
  79.             cvReleaseImage(&DispImage);
  80.             return;
  81.         }
  82.  
  83.         // Find the width and height of the image
  84.         x = img->width;
  85.         y = img->height;
  86.  
  87.         // Find whether height or width is greater in order to resize the image
  88.         max = (x > y)? x: y;
  89.  
  90.         // Find the scaling factor to resize the image
  91.         scale = (float) ( (float) max / size );
  92.  
  93.         // Used to Align the images
  94.         if( i % w == 0 && m!= 20) {
  95.             m = 20;
  96.             n+= 20 + size;
  97.         }
  98.  
  99.         // Set the image ROI to display the current image
  100.         cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));
  101.  
  102.         // Resize the input image and copy the it to the Single Big Image
  103.         cvResize(img, DispImage);
  104.  
  105.         // Reset the ROI in order to display the next image
  106.         cvResetImageROI(DispImage);
  107.     }
  108.    
  109.     cvShowImage( title, DispImage);
  110.  
  111.     va_end(args);
  112.  
  113.     cvReleaseImage(&DispImage);
  114. }