码迷,mamicode.com
首页 > 其他好文 > 详细

在一个窗口中显示多个视频,并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的

时间:2015-10-17 11:56:19      阅读:502      评论:0      收藏:0      [点我收藏+]

标签:

#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>

void cvShowManyImages(char* title, int nArgs, ...){
    IplImage *img;
    IplImage *DispImage;
    int size;
    int i;
    int m, n;
    
    int x, y;
      int w, h;
        // scale - How much we have to resize the image
        float scale;
        int max;
        // If the number of arguments is lesser than 0 or greater than 12
        // return without displaying
         w = 2; h = 2;
         size = 300;
        /**
        if(nArgs <= 0) {
                printf("Number of arguments too small....\n");
                return;
        }
        else if(nArgs > 12) {
                printf("Number of arguments too small....\n");
                return;
        }
        // Determine the size of the image,
        // and the number of rows/cols
        // from number of arguments
        else if (nArgs == 1) {
                w = h = 1;
                size = 300;
        }
        else if (nArgs == 2) {
                w = 2; h = 1;
                size = 300;
        }
        else if (nArgs == 3 || nArgs == 4) {
                w = 2; h = 2;
                size = 300;
        }
        else if (nArgs == 5 || nArgs == 6) {
                w = 3; h = 2;
                size = 200;
        }
        else if (nArgs == 7 || nArgs == 8) {
                w = 4; h = 2;
                size = 200;
        }
        else {
                w = 4; h = 3;
                size = 150;
        }
        */
         // Create a new 3 channel image
        DispImage = cvCreateImage( cvSize(100 + size*w, 60 + size*h), 8, 3 );
        // Used to get the arguments passed
        va_list args;
        va_start(args, nArgs);
        // Loop for nArgs number of arguments
       // for (i = 0, m = 20, n = 20; i < nArgs; i++, m += (20 + size)) {
        for (i = 0, m = 20, n = 20; i < nArgs; i++, m += (20 + size)) {
                // Get the Pointer to the IplImage
                img = va_arg(args, IplImage*);
                // Check whether it is NULL or not
                // If it is NULL, release the image, and return
                if(img == 0) {
                        printf("Invalid arguments");
                        cvReleaseImage(&DispImage);
                        return;
                }
                // Find the width and height of the image
                x = img->width;
                y = img->height;
                // Find whether height or width is greater in order to resize the image
                max = (x > y)? x: y;
                // Find the scaling factor to resize the image
                scale = (float) ( (float) max / size );
                // Used to Align the images
                if( i % w == 0 && m!= 20) {
                        m = 20;
                        n+= 20 + size;
                }
                // Set the image ROI to display the current image
                cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));
                // Resize the input image and copy the it to the Single Big Image
                cvResize(img, DispImage);
                // Reset the ROI in order to display the next image
                cvResetImageROI(DispImage);
        }
        // Create a new window, and show the Single Big Image
        //cvNamedWindow( title, 1 );
        cvShowImage( title, DispImage);
        /*cvWaitKey(0);*/
        //cvDestroyWindow(title);
        // End the number of arguments
        va_end(args);
        // Release the Image Memory
        cvReleaseImage(&DispImage);
}
int main(int argc,char **argv)
{
        CvCapture *capture;
      //  int i=0;
     
       capture=cvCreateFileCapture("E:\\Videos\\xx.avi");
      
        IplImage *frame;
        cvNamedWindow("video",1);
        cvResizeWindow("video",700,660);
        //CvFont timeFont,timeFont1;
       // cvInitFont(&timeFont,CV_FONT_HERSHEY_COMPLEX,0.5f,0.5f,0,1,8);
       // cvInitFont(&timeFont1,CV_FONT_HERSHEY_COMPLEX,0.5f,0.5f,0,1,8);
       // char time1[25];
      //   memset(time1,0,25*sizeof(char));
        while (1)
        {
                frame=cvQueryFrame( capture );
                if (!frame)
                {
                        break;
                }
                /**
                IplImage *frame_not=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
                cvNot(frame,frame_not);
                */
               // time_t rawtime;
             //   struct tm * timeinfo;
              //  time ( &rawtime );
            //    timeinfo = localtime ( &rawtime );
               
       
             //   char *p=asctime(timeinfo);
  //数组p的第25个字符为‘\n‘,在图像上显示时为乱码,这里取其前24个字符显示在图像上
               
            /** for (i=0;i<24;i++)
                {
                time1[i]=*p;
                p++;
                }
                p=NULL;
            */   
                IplImage *frame_gray=cvCreateImage(cvGetSize(frame),frame->depth,1);
                IplImage *frame1=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
                IplImage *frame_canny=cvCreateImage(cvGetSize(frame),frame->depth,1);
                IplImage *frame2=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
                cvCvtColor(frame,frame_gray,CV_RGB2GRAY);
                cvCvtColor(frame_gray,frame1,CV_GRAY2BGR);
                cvCanny(frame_gray,frame_canny,20,75,3);
                cvCvtColor(frame_canny,frame2,CV_GRAY2BGR);
              //  cvPutText(frame,time1,cvPoint(0,15),&timeFont,CV_RGB(255,0,0));
                //cvPutText(frame1,time1,cvPoint(0,15),&timeFont,CV_RGB(255,0,0));
               // cvPutText(frame2,time1,cvPoint(0,15),&timeFont1,CV_RGB(255,0,0));
              //  cvPutText(frame_not,time1,cvPoint(0,15),&timeFont1,CV_RGB(255,0,0));
              //  cvShowManyImages("video",4,frame,frame_not,frame1,frame2);
                 cvShowManyImages("video",3,frame,frame1,frame2);
                cvWaitKey(33);
               // cvReleaseImage(&frame_not);
                cvReleaseImage(&frame1);
                cvReleaseImage(&frame_gray);
                cvReleaseImage(&frame2);
                cvReleaseImage(&frame_canny);
       
               
        }
               cvDestroyWindow("video");
               cvReleaseCapture(&capture);
        return 0;
}

转载自:http://www.opencv.org.cn/forum.php?mod=viewthread&tid=7996&extra=&page=1

在一个窗口中显示多个视频,并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的

标签:

原文地址:http://www.cnblogs.com/beihaidao/p/4887051.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!