在单个窗口中显示多个视频子窗口

OpenCV学习笔记(5)在单个窗口中显示多个视频子窗口 参考OpenCV中文论坛的一个帖子(http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=7996&start=0)实现了在一个窗口显示多个视频子窗口,能够读入单个的视频或摄像头数据,然后在一个窗口中分别显示原始帧图像、反色图像、灰度图像以及Canny边缘检测图像。并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的。 阅读详情

代码如下:

#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

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

// 隐藏 console 窗口
#pragma comment( linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"" )

// 单窗口显示多幅图像的函数
void cvShowMultiImages(char* title, int nArgs, ...) 
{

   // img - Used for getting the arguments 
   IplImage* img;

   // DispImage - the image in which all the input images are to be copied
   IplImage* DispImage;

   int size;    // size - the size of the images in the window
   int ind;        // ind - the index of the image shown in the window
   int x, y;    // x,y - the coordinate of top left coner of input images
   int w, h;    // w,h - the width and height of the image

   // r - Maximum number of images in a column 
   // c - Maximum number of images in a row 
   int r, c;

   // scale - How much we have to resize the image
   float scale;
   // max - Max value of the width and height of the image
   int max;
   // space - the spacing between images
   int space;

   // If the number of arguments is lesser than 0 or greater than 12
   // return without displaying 
   if(nArgs <= 0) {
      printf("Number of arguments too small..../n");
      return;
   }
   else if(nArgs > 12) {
      printf("Number of arguments too large..../n");
      return;
   }
   // Determine the size of the image, 
   // and the number of rows/cols 
   // from number of arguments 
   else if (nArgs == 1) {
      r = c = 1;
      size = 300;
   }
   else if (nArgs == 2) {
      r = 2; c = 1;
      size = 300;
   }
   else if (nArgs == 3 || nArgs == 4) {
      r = 2; c = 2;
      size = 300;
   }
   else if (nArgs == 5 || nArgs == 6) {
      r = 3; c = 2;
      size = 200;
   }
   else if (nArgs == 7 || nArgs == 8) {
      r = 4; c = 2;
      size = 200;
   }
   else {
      r = 4; c = 3;
      size = 150;
   }

   // Create a new 3 channel image to show all the input images
   DispImage = cvCreateImage( cvSize(60 + size*r, 20 + size*c), IPL_DEPTH_8U, 3 );

   // Used to get the arguments passed
   va_list args;
   va_start(args, nArgs);

   // Loop for nArgs number of arguments
   space = 20;
   for (ind = 0, x = space, y = space; ind < nArgs; ind++, x += (space + 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
      w = img->width;
      h = img->height;

      // Find whether height or width is greater in order to resize the image
      max = (w > h)? w: h;

      // Find the scaling factor to resize the image
      scale = (float) ( (float) max / size );

      // Used to Align the images
      // i.e. Align the image to next row
      if( ind % r == 0 && x!= space) {
         x  = space;
         y += space + size;
      }

      // Set the image ROI to display the current image
      cvSetImageROI(DispImage, cvRect(x, y, (int)( w/scale ), (int)( h/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);


   // End the number of arguments
   va_end(args);

   // Release the Image Memory
   cvReleaseImage(&DispImage);
}


int main( int argc, char** argv ) 
{
   CvCapture* capture;   
   
   if (argc == 1)
   {
      capture = cvCreateCameraCapture( 0 );
   }
   else
   {
      capture = cvCreateFileCapture( argv[1] );      
   }
   
   IplImage* frame;
   
   cvNamedWindow("video",1);
   cvResizeWindow("video",750,750);
   
   CvFont timeFont,timeFont1;
   cvInitFont(&timeFont,  CV_FONT_HERSHEY_COMPLEX, 1.0f,1.0f,0,1,8);
   cvInitFont(&timeFont1, CV_FONT_HERSHEY_COMPLEX, 1.0f,1.0f,0,1,8);
   
   // Initialize new applied memory of 'time1'
   char timestr[25];
   memset(timestr, 0, 25 * sizeof(char));
   
   while (1)
   {
      frame = cvQueryFrame( capture );
      if (!frame) break;
         
      // Get the systme local time info
      time_t rawtime; 
      struct tm* timeinfo; 
      //time( &rawtime ); 

      rawtime = time( NULL ); 
      timeinfo = localtime( &rawtime ); 
      char* p = asctime( timeinfo );
      
      // the 25th character of array 'p' is '/n'
      // but it can not be display correctly in the image
      // so we just read out the first 24 character of 'p'
      for (int i = 0; i < 24; i++)
      {
         timestr[i] = *p;
         p++;
      }
      p = NULL;
      
      // Bitwise inversion of every element of the current frame
      IplImage* frame_not = cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
      cvNot(frame,frame_not);
      
      // Get the gray scale image of the current frmae
      // and transform the gray image from single channel to three channels
      IplImage* frame_gray=cvCreateImage(cvGetSize(frame),frame->depth,1);
      IplImage* frame1=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
      cvCvtColor(frame,frame_gray,CV_RGB2GRAY);
      cvCvtColor(frame_gray,frame1,CV_GRAY2BGR);
      
      // Do Canny edge detection
      // and transform the result image from single channel to three channels
      IplImage* frame_canny=cvCreateImage(cvGetSize(frame),frame->depth,1);
      IplImage* frame2=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
      cvCanny(frame_gray,frame_canny,20,75,3);
      cvCvtColor(frame_canny,frame2,CV_GRAY2BGR);

      // Display the local time information in each image
      cvPutText( frame,        timestr, cvPoint(5,25), &timeFont,  CV_RGB(255,0,0) );
      cvPutText( frame1,    timestr, cvPoint(5,25), &timeFont,  CV_RGB(255,0,0) );
      cvPutText( frame2,    timestr, cvPoint(5,25), &timeFont1, CV_RGB(255,0,0) );
      cvPutText( frame_not, timestr, cvPoint(5,25), &timeFont1, CV_RGB(255,0,0) );

      cvShowMultiImages("video",4,frame,frame_not,frame1,frame2);

      
      //cvWaitKey(33);
      int key = cvWaitKey(33);
      if( key == 27 ) break;

      cvReleaseImage(&frame_not);
      cvReleaseImage(&frame1);
      cvReleaseImage(&frame_gray);
      cvReleaseImage(&frame2);
      cvReleaseImage(&frame_canny);   

   }
   
   cvDestroyWindow("video");
   cvReleaseCapture(&capture);

   return 0;

}

有几点需要注意: 1、在 while 循环中,处理完的图像应及时释放所占用的内存(cvReleaseImage),否则会不断占用内存空间以致系统当机。 2、图像数据的指针若是由 cvCreateImage 返回的,则应由 cvReleaseImage 来释放内存;如果是读取自视频或摄像头的帧图像,则应用 cvReleaseCapture 来释放内存,不必再用 cvReleaseImage() ,在 while 循环中使用 cvReleaseImage( &frame )  会导致生成的程序在执行时出错。 3、有关va_list、va_start、va_arg、va_end的原理与使用,参见 http://www.cppblog.com/qiujian5628/archive/2008/01/21/41562.html

OpenCV3实现一个窗口中显示多张Mat型图片(任意张) 用vector容器可以动态装若干图片,用ROI实现图片定位,达到将多张图片在同一个窗口中显示的功能。环境配置是VS2015+OpenCV3,使用低版本的用户记得修改头文件。 立即下载

相关推荐

Splunk CVE-2018-11409认证绕过漏洞深度解析

Splunk作为主流企业级日志分析平台,其Web管理接口的认证机制直接关系到整个安全运营体系的可信边界。CVE-2018-11409本质上是REST API路由层会话校验缺失引发的未授权访问问题,根源在于`/en-US/splunkd/__raw/`路径绕过了splunkweb与splunkd之间的信任链验证,导致配置文件、用户哈希、App源码等敏感信息明文泄露。该漏洞凸显了Web接口权限模型设计失守的风险,尤其在默认配置未加固、HTTPS未启用、初始密码未修改的生产环境中危害急剧放大。结合vulfocus

weixin_30875157的博客 597

一个页面展示多个视频窗口(vue)

<template> <divid="video-play"> <Row> <Colv-for="(item,i)inlistArray":span="item.span"> <divstyle="text-align:center;border:1pxsolid#ece9e...

weixin_42206447的博客 6516

新能源知识库(68)复叠压缩式热泵蒸汽系统介绍

复叠压缩式热泵蒸汽系统通过多级压缩技术将低品位热能转化为高品位蒸汽,在汽车电镀场景中实现了高效、精准的能源利用。随着超高温工质与智能联供系统的发展,该技术将深度赋能电镀行业的高质量可持续发展。​:±1℃控温保障镀层均匀性,提升产品良率;多台复叠热泵+储热装置(如纺织厂6台热泵)复叠热泵+余热回收+智能控制(化工厂案例)​:无燃烧设计契合汽车行业ESG目标。单台高温热泵机组(如92P型号)复叠压缩式热泵蒸汽系统以。67.4万元(↓22%)600万–1200万元。事故率 ↓90%​​。150万–600万元。

竹君子之家 1419

opencv如何隐藏窗口

今天处理视频的时候想将opencv中的窗口隐藏起来,以便进行多线程的处理。     在opencv中可以通过cvGetWindowHandle获取窗口句柄。cvGetWindowHandle的返回值解释为:函数cvGetWindowHandle返回原始的窗口句柄(在Win32情况下返回HWND,GTK+情况下返回GtkWidget)。一开始的处理时,通过以下方法: cvNamedWi

ahuang1900的专栏 6969

从零构建机械臂规划栈:Pinocchio、OMPL与Ruckig的工程化融合实践

本文详细介绍了如何从零构建机械臂规划栈,通过融合Pinocchio、OMPL和Ruckig三大核心组件,实现高性能的机械臂运动规划与轨迹生成。文章深入探讨了技术选型、工程架构设计及实战优化技巧,特别针对逆解、路径规划和轨迹平滑等关键环节提供了实用解决方案,适用于工业场景中的高实时性需求。

weixin_29072299的博客 433

从ROS2到ROS1:Lightning-LM激光SLAM模块的移植实践与核心代码解析

本文详细解析了将高性能激光SLAM算法Lightning-LM从ROS2移植到ROS1的完整实践过程。针对ROS1与ROS2在节点初始化、话题通信、参数服务器及TF发布等核心API的差异,文章提供了loc_system和slam模块的核心代码改造示例,并给出了适配catkin的CMakeLists.txt与package.xml配置方案,帮助开发者在现有ROS1生态中高效集成先进的SLAM模块。

weixin_29224529的博客 172

将OpenCV输出的图像嵌入显示到子窗口控件中(支持Windows、Linux)

OpenCV用来做视频处理很方便,能用窗口显示处理后的图像,但是它默认显示图像的窗口是弹出式的,而我们很多情况下需要将图像显示到自己软件的窗口控件中。这应该怎么做呢?上网搜过一些方案,也试了一下,最后自己优化了一下,把其中几种比较靠谱的方法分享给大家。 第一种,使用Cvvimage类 + GDI方式显示图像。 CvvImage类有个函数DrawPicToHDC (IplImage *img, ...

爱写代码的自由人 3654

如何在 FPGA 中做数学运算

FPGA 非常适合进行数学运算,但是需要一点技巧,所以我们今天就看看如何在 FPGA 中进行简单和复杂的数学运算。介绍由于FPGA可以对算法进行并行化,所以FPGA 非常适合在可编程逻辑中实现数学运算。我们可以在 FPGA 中使用数学来实现信号处理、仪器仪表、图像处理和控制算法等一系列应用。这意味着 FPGA 可用于从自动驾驶汽车图像处理到雷达和飞机飞行控制系统的一系列应用。因为 FPGA 寄存器...

OpenFPGA的博客 2915

C#上位机学习-多窗口显示时,如何在放大某一个窗口的同时不显示其他窗口

本项目的目的是制作一个上位机并且显示多个相机的拍摄画面,所以需要创建多个WindowsFormsHost窗口来实现多个画面同时显示,其中遇到一个问题,当我双击某一窗口并放大该窗口时,相机画面的一部分会被其他窗口所遮挡到并且双击其他窗口的位置也会放大另一个窗口,从而导致故障,只能重新启动才能正常运行。

hanshengrui的博客 289

【经验&技巧】IBIS AMI模型眼图仿真问题探讨

在ADS的仿真环境中,不论发送和接收的AMI模型是否为true或者false,都可以将通道仿真设置为统计模式,但是,如果有一方的Init函数为false,在统计模式下,处于false状态的模型将不能执行其自带的后处理功能,如下图所示,左边的统计模式和右边的逐比特模式眼图存在明显的差异,原因在于,接收端的init函数为false导致在统计模式中不能对眼图进行DFE处理,换言之,此时统计模式下的眼图就是未经任何处理的“生图”。

一只豌豆象的博客 1765

SY6982C 7.4V锂电池1A充电模块原理图设计,已量产

在手持设备、便携工具与小型无人机等场景中,7.4V(2S)锂聚合物电池的应用愈发广泛。这类电池对充电系统的安全性、效率与兼容性提出了明确要求:需支持 USB 5V 输入、1A 安全充电,同时具备多重保护机制。本文将结合一款基于 SY6982C 的充电原理图,深入解析其电路设计与技术亮点。

不脱发的程序猿 360

OpenCV學習筆記(5)在單個窗口中顯示多個視頻子窗口

http://blog.youkuaiyun.com/chenyusiyuan/article/details/4642297 參考OpenCV中文論壇的一個帖子(http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=7996&start=0)實現了在一個窗口顯示多個視頻子窗口,能夠讀入單個的視頻或攝像頭數據,然後在一個窗口中分別顯示原始幀圖像、反色圖

I am Rocky 1813

Unity 实战项目 ☀️| 只用一个脚本做一个 刮刮乐 案例,一不小心刮出来一个女朋友!【学习娱乐一下】

只用一个脚本做一个刮刮乐,一不小心刮出来一个女朋友!【学习娱乐一下!】

努力前行,总会成为自己心中的那道光 23万+

OpenCV笔记4:在单个窗口中显示多个视频子窗口

http://blog.youkuaiyun.com/chenyusiyuan/article/details/4642297 运行结果 源代码: #include "stdafx.h" #include #include #include #include #include #include // 单窗口显示多幅图像的函数 void cvShowMultiIma

gududeyhc的专栏 1781

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

OpenCV学习笔记-在单个窗口中显示多个视频子窗口

转自http://blog.youkuaiyun.com/chenyusiyuan/article/details/4642297 参考OpenCV中文论坛的一个帖子(http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=7996&start=0)实现了在一个窗口显示多个视频子窗口,能够读入单个的视频或摄像头数据,然后在一个窗口中分别显示原...

weixin_30662011的博客 81

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

OPENCV多窗口实现

实现了在一个窗口显示多个视频子窗口,能够读入单个的视频或摄像头数据,然后在一个窗口中分别显示原始帧图像、反色图像、灰度图像以及Canny边缘检测图像。并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的。 代码如下: #include "stdafx.h" #include #include #include #include #includ

尸姐II的专栏 4318

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

在一个窗口显示多个视频子窗口

参考OpenCV中文论坛的一个帖子(http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=7996&start=0)实现了在一个窗口显示多个视频子窗口,能够读入单个的视频或摄像头数据,然后在一个窗口中分别显示原始帧图像、反色图像、灰度图像以及Canny边缘检测图像。并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的。

q123456789098的专栏 3206

一个窗口显示多个视频子窗口

参考OpenCV中文论坛的一个帖子(http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=7996&start=0)实现了在一个窗口显示多个视频子窗口,能够读入单个的视频或摄像头数据,然后在一个窗口中分别显示原始帧图像、反色图像、灰度图像以及Canny边缘检测图像。并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的。

fuquanjun的专栏 1059

Qt实现两个窗口重叠,下层播放视频,上次透明显示方框

最近要实现一个功能,在播放着的视频上动态显示方框,类似于深度学习物体识别中经常见到的方框图。如下图: 动手! 1、 下层窗口播放视频,上次透明画方框 setWindowFlags(Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground);//窗口设置透明 设置完运行 ?! Qt控件在透...

wwpp的博客 2万+

OpenCV-python进行多个摄像头同步采集并拼接显示(多个视频拼接到一个窗口显示)

以下是两个摄像头进行拼接的代码,同理可以拼接N个。 效果如下:由于两个摄像头分辨率不一样,以及懒得resize成一样的大小,显示效果左边视频上下留黑了。 import cv2 import numpy as np ##选择摄像头 videoLeftUp = cv2.VideoCapture(0) videoRightUp = cv2.VideoCapture(1) width = (...

学习随笔 2万+

OpenCV在一个窗口中显示多个视频子窗口

在一个窗口中显示多个视频,并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的#include #include #include #include #include void cvShowManyImages(char* title, int nArgs, ...) { // img - Used for getting the argumen

Augusdi的专栏 5669
上一篇: 获取文件夹中的子文件夹或文件的名字以及路径
下一篇: 多个摄像头同步工作
wanglp094
博客等级 码龄22年 144粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值