您的位置:首页 > 运维架构

opencv--用鼠标动态改变显示图像窗口大小

2010-12-24 21:51 1046 查看
Code:

// 缩小图像.cpp : Defines the entry point for the console application.

//



#include "stdafx.h"

#include <cv.h>

#include <highgui.h>



const double scale = 0.5;



IplImage* ResizeImage(IplImage *src)

{

// allocate memory for the dsc

IplImage* dsc = cvCreateImage(cvSize(src->width*scale, src->height*scale),

src->depth, src->nChannels);



// resizes Image(input array is resized to fit the output array )

cvResize(src, dsc, CV_INTER_LINEAR);

return dsc;



}

int main(int argc, char* argv[])

{

// load image

IplImage *src = cvLoadImage("e://lena.jpg", CV_LOAD_IMAGE_COLOR);



IplImage *dsc = NULL;

//

dsc = ResizeImage(src);



// create the window to shou image

// be carefull the follow function's 2 parameter



cvNamedWindow("src", 1);

cvNamedWindow("dsc", 0);



// show the image when the window changes

// and you can use the mouse the changes the window's size

cvResizeWindow("src", src->width, src->height);

cvResizeWindow("dsc", dsc->width, dsc->height);

// print image to the windows

cvShowImage("src", src);

cvShowImage("dsc", dsc);

// waiting a keyboard

cvWaitKey(0);



// release the memory

cvDestroyAllWindows();

cvReleaseImage(&src);

cvReleaseImage(&dsc);

printf("Hello World!/n");

return 0;

}

// Remark: when creat window we should make the 2 parameter of

// cvNamedWindow function is 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: