OpenCV一个窗口显示多张图片

来源:互联网 发布:魔笛手的软件 编辑:程序博客网 时间:2024/05/01 20:44
  1. 原文地址
  2. http://blog.csdn.net/augusdi/article/details/9019473
  3. void cvShowManyImages(chartitle, 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.     // Maximum number of images in row   
  18.     // Maximum number of images in 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 or greater than 12  
  26.     // return without displaying   
  27.     if(nArgs <= 0)  
  28.      
  29.         printf("Number of arguments too small....n");  
  30.         return 
  31.      
  32.     else if(nArgs 12)  
  33.      
  34.         printf("Number of arguments too large....n");  
  35.         return 
  36.      
  37.     // Determine the size of the image, and the number of rows/cols  from number of arguments   
  38.     else if (nArgs == 1)  
  39.      
  40.         1;  
  41.         size 300;  
  42.      
  43.     else if (nArgs == 2)  
  44.      
  45.         2; 1;  
  46.         size 300;  
  47.      
  48.     else if (nArgs == || nArgs == 4)  
  49.      
  50.         2; 2;  
  51.         size 300;  
  52.      
  53.     else if (nArgs == || nArgs == 6)  
  54.         3; 2;  
  55.         size 200;  
  56.      
  57.     else if (nArgs == || nArgs == 8)  
  58.      
  59.         4; 2;  
  60.         size 200;  
  61.      
  62.     else  
  63.      
  64.         4; 3;  
  65.         size 150;  
  66.      
  67.   
  68.     // Create new channel image0  
  69.     DispImage cvCreateImage( cvSize( 100+ size*w, 60 size*h), 8, );  
  70.   
  71.     // Used to get the arguments passed  
  72.     va_list args;  
  73.     va_start(args, nArgs);  
  74.   
  75.     // Loop for nArgs number of arguments  
  76.     for (i 0, 20, 20; nArgs; i++, += (20 size))   
  77.      
  78.         // Get the Pointer to the IplImage  
  79.         img va_arg(args, IplImage*);  
  80.   
  81.         // Check whether it is NULL or not  
  82.         // If it is NULL, release the image, and return  
  83.         if(img == 0)  
  84.          
  85.             printf("Invalid arguments");  
  86.             cvReleaseImage(&DispImage);  
  87.             return 
  88.          
  89.   
  90.         // Find the width and height of the image  
  91.         img->width;  
  92.         img->height;  
  93.   
  94.         // Find whether height or width is greater in order to resize the image  
  95.         max (x y)? x: y;  
  96.   
  97.         // Find the scaling factor to resize the image  
  98.         scale (float(floatmax size );  
  99.   
  100.         // Used to Align the images  
  101.         if== && m!= 20)  
  102.          
  103.             20;  
  104.             n+= size;  
  105.          
  106.   
  107.         // Set the image ROI to display the current image  
  108.         //cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));  
  109.         cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));  
  110.         //      cout<<"x="<<m<<"y="<<n<<endl;  
  111.   
  112.         // Resize the input image and copy the it to the Single Big Image  
  113.         cvResize(img, DispImage);  
  114.   
  115.         // Reset the ROI in order to display the next image  
  116.         cvResetImageROI(DispImage);  
  117.      
  118.   
  119.     // Create new window, and show the Single Big Image  
  120.     //cvNamedWindow( title, );  
  121.     cvShowImage( title, DispImage);  
  122.   
  123.       
  124.     //cvDestroyWindow(title);  
  125.   
  126.     // End the number of arguments  
  127.     va_end(args);  
  128.   
  129.     // Release the Image Memory  
  130.     cvReleaseImage(&DispImage);  
  131.  
  132. int main(int argc,char **argv)   
  133.  
  134.       
  135.     int i=0;  
  136.   
  137.     IplImage *frame=cvLoadImage(".\test.png");  
  138.     cvNamedWindow("video",1);  
  139.     cvResizeWindow("video",700,660);  
  140.   
  141.   
  142.     IplImage *frame_not=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);  
  143.     cvNot(frame,frame_not);  
  144.   
  145.     IplImage *frame_gray=cvCreateImage(cvGetSize(frame),frame->depth,1);  
  146.     IplImage *frame1=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);  
  147.     IplImage *frame_canny=cvCreateImage(cvGetSize(frame),frame->depth,1);  
  148.     IplImage *frame2=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);  
  149.     cvCvtColor(frame,frame_gray,CV_RGB2GRAY);  
  150.     cvCvtColor(frame_gray,frame1,CV_GRAY2BGR);  
  151.     cvCanny(frame_gray,frame_canny,20,75,3);  
  152.     cvCvtColor(frame_canny,frame2,CV_GRAY2BGR);  
  153.   
  154.   
  155.     cvShowManyImages("video",4,frame,frame_not,frame1,frame2);  
  156.     cvWaitKey();  
  157.   
  158.     cvReleaseImage(&frame_not);  
  159.     cvReleaseImage(&frame1);  
  160.     cvReleaseImage(&frame_gray);  
  161.     cvReleaseImage(&frame2);  
  162.     cvReleaseImage(&frame_canny);  
  163.   
  164.     cvDestroyWindow("video");  
  165.   
  166.     return 0;  
  167.  
0 0
原创粉丝点击