OpenCV一个窗口显示多张图片
2016-03-11 22:11
429 查看
原文地址
http://blog.csdn.net/augusdi/article/details/9019473
void cvShowManyImages(char* title, int nArgs, ...)
{
// img - Used for getting the arguments
IplImage *img;
// DispImage - the image in which input images are to be copied
IplImage *DispImage;
int size;
int i;
int m, n;
int x, y;
// w - Maximum number of images in a row
// h - Maximum number of images in a column
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
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)
{
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 image0
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))
{
// 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+= 0 + size;
}
// Set the image ROI to display the current image
//cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));
cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));
// cout<<"x="<<m<<"y="<<n<<endl;
// 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);
//cvDestroyWindow(title);
// End the number of arguments
va_end(args);
// Release the Image Memory
cvReleaseImage(&DispImage);
}
int main(int argc,char **argv)
{
int i=0;
IplImage *frame=cvLoadImage(".\test.png");
cvNamedWindow("video",1);
cvResizeWindow("video",700,660);
IplImage *frame_not=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
cvNot(frame,frame_not);
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);
cvShowManyImages("video",4,frame,frame_not,frame1,frame2);
cvWaitKey();
cvReleaseImage(&frame_not);
cvReleaseImage(&frame1);
cvReleaseImage(&frame_gray);
cvReleaseImage(&frame2);
cvReleaseImage(&frame_canny);
cvDestroyWindow("video");
return 0;
}
http://blog.csdn.net/augusdi/article/details/9019473
void cvShowManyImages(char* title, int nArgs, ...)
{
// img - Used for getting the arguments
IplImage *img;
// DispImage - the image in which input images are to be copied
IplImage *DispImage;
int size;
int i;
int m, n;
int x, y;
// w - Maximum number of images in a row
// h - Maximum number of images in a column
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
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)
{
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 image0
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))
{
// 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+= 0 + size;
}
// Set the image ROI to display the current image
//cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));
cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));
// cout<<"x="<<m<<"y="<<n<<endl;
// 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);
//cvDestroyWindow(title);
// End the number of arguments
va_end(args);
// Release the Image Memory
cvReleaseImage(&DispImage);
}
int main(int argc,char **argv)
{
int i=0;
IplImage *frame=cvLoadImage(".\test.png");
cvNamedWindow("video",1);
cvResizeWindow("video",700,660);
IplImage *frame_not=cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
cvNot(frame,frame_not);
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);
cvShowManyImages("video",4,frame,frame_not,frame1,frame2);
cvWaitKey();
cvReleaseImage(&frame_not);
cvReleaseImage(&frame1);
cvReleaseImage(&frame_gray);
cvReleaseImage(&frame2);
cvReleaseImage(&frame_canny);
cvDestroyWindow("video");
return 0;
}
相关文章推荐
- Linux平台weblogic集群安装(一)
- At91sam9g35K烧录Linux系统
- 利用Photoshop进行快速切图
- codeforces 551D. GukiZ and Binary Operations 矩阵快速幂
- Linux下如何查看高CPU占用率线程 LINUX CPU利用率计算(转)
- Apache安装
- 高并发集群架构超细精讲
- Opengl学习笔记1 -- 做一个透视立方体
- Linux之:最常用的20条命令
- VMware安装ubuntu系统(Hadoop集群的节点准备)
- (15) PHP 随笔---LAMP Linux基本操作 对文件、目录的操作
- opencv配置之非配置文件版
- (14) PHP 随笔---LAMP Linux基础
- Linux 字符设备驱动开发基础(二)—— 编写简单 PWM 设备驱动
- centos6、7安装vlc
- nginx 域名映射
- 架构师速成8.2-架构师要懂产品
- 查找两个文件包含的字符串或不包含的字符串shell脚本
- Red Hat Linux 6.5配置本地yum源
- opencv imshow