#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;
}
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com -->
相关推荐
程序作用,输入两个视频,将两个视频在同一窗口中显示,存成一个视频输出。代码配置opencv后可直接执行。
opencv 一个窗口显示多个图像 源代码
Opencv学习笔记 辛苦收集希望和大家交流
opencv配置VS2008 单窗口进行多个视频或图像的现实
这个一个很基础的opencv学习笔记,一些常会遇到的问题,在这里做了肤浅的介绍,还有很多问题没有提及,以后会陆续整理,并上传
爱分享、爱极客的编程怪兽--DaveBobo 博文 《【OpenCV学习笔记 005】 操作像素》 博文链接: http://blog.csdn.net/davebobo/article/details/52541612 OpenCV版本:2.4.9
OpenCV学习笔记,(基础概念,归纳总结),相信你所选择的。
# PyQt5+OpenCV+PyCharm使用本地摄像头并实时显示图像 GUI可视化 代码内写有详细注释 包含两个demo:一个是只有实时显示摄像头图像的简单版demo,另一个是同时加入了两个按钮控制图像翻转和灰度的demo,供大家学习。
OpenCV学习笔记(C++版OpenCV学习笔记,主要包括基础模块和DNN模块)带详细注释源码!!!
# PyQt5+OpenCV播放本地视频GUI窗口 mp4等格式 1. 使用QTimer定时刷新画面 2. 播放/暂停按键
爱分享、爱极客的编程怪兽--DaveBobo 博文 《【OpenCV学习笔记 013】处理视频序列》 博文链接: http://blog.csdn.net/davebobo/article/details/52677657 OpenCV版本:2.4.9
学习笔记
有关学习opencv与C++过程中的一些学习笔记
OpenCV学习笔记入门版,真正的入门级别,自己写的
在opencv中可以直接弹出小窗口显示图片,这个很突兀,如果显示图片多的化就很麻烦,本代码实现了在Qt界面中将opencv的图片直接显示在lable控件上。
利用opencv来读取文件中的多个视频,对于刚学习opencv的人来说,具有一定的学习借鉴作用
OpenCV实现同一窗口显示多幅图片,开发平台OpenCV2.4.2+VS2008
此源代码配套博客使用,代码主要是利用OpenCV的函数调用电脑摄像头并显示在MFC的图片控件上。
OpenCV打开摄像机显示在 OpenCV窗口上