功能程序:使用鼠标控制三个窗口的放大与缩小。
在此不附上运行结果效果图,若需体验其效果如何,可以自己动手copy参考代码,运行试试一下看。
参考程序如下所示:
#include <opencv2/opencv.hpp> using namespace std ; using namespace cv ; IplImage *vis_image ;//可见光图片 IplImage *ir_image ;//红外光图片 IplImage *imagesum ;//融合图片 IplImage *m_display=cvCreateImage(cvSize(1080,600),IPL_DEPTH_8U,3);//整个窗口 IplImage *temp_display=cvCreateImage(cvSize(720,560),IPL_DEPTH_8U,3);//左侧融合窗口 IplImage *temp1_display=cvCreateImage(cvSize(360,280),IPL_DEPTH_8U,3);//右上可见光窗口 IplImage *temp2_display=cvCreateImage(cvSize(360,280),IPL_DEPTH_8U,3);//右下红外窗口 IplImage *large_display = cvCreateImage(cvSize(1080,560),IPL_DEPTH_8U,3);//大窗口显示一个图片 CvRect rectsum=cvRect(0,0,720,560);//左侧融合窗口区域 CvRect rect1=cvRect(720,0,360,280);//右上可见光区域 CvRect rect2=cvRect(720,280,360,280);//右下红外光区域 CvRect rectLarge = cvRect(0 , 0 , 1080 , 560) ; void cvshowFusion(){ cvResize(imagesum,large_display,CV_INTER_LINEAR); cvSetImageROI(m_display,rectLarge); cvCopy(large_display,m_display); cvResetImageROI(m_display); } void cvshowVison(){ cvResize(vis_image,large_display,CV_INTER_LINEAR); cvSetImageROI(m_display,rectLarge); cvCopy(large_display,m_display); cvResetImageROI(m_display); } void cvshowRed(){ cvResize(ir_image,large_display,CV_INTER_LINEAR); cvSetImageROI(m_display,rectLarge); cvCopy(large_display,m_display); cvResetImageROI(m_display); } void cvshowThreeImage( ){ cvResize(imagesum,temp_display,CV_INTER_LINEAR); cvResize(vis_image,temp1_display,CV_INTER_LINEAR); cvResize(ir_image, temp2_display, CV_INTER_LINEAR); cvSetImageROI(m_display,rectsum); cvCopy(temp_display,m_display); cvResetImageROI(m_display); cvSetImageROI(m_display,rect1); cvCopy(temp1_display,m_display); cvResetImageROI(m_display); cvSetImageROI(m_display,rect2); cvCopy(temp2_display,m_display); cvResetImageROI(m_display); cvRectangle(m_display,cvPoint(1,1),cvPoint(719,559),CV_RGB(100,255,100), 1); cvRectangle(m_display,cvPoint(721,1),cvPoint(1079,279),CV_RGB(100,255,100), 1); cvRectangle(m_display,cvPoint(721,281),cvPoint(1079,559),CV_RGB(100,255,100), 1); } void cvprocess0(int x , int y , int &flag){//三个窗口下点击 int id ; if(x > 0 && x < 720)id = 0 ; else if(y > 0 && y < 280) id = 1; else id = 2; switch (id){ case 0://点击融合图像 cvshowFusion() ; cvShowImage("fusion" , m_display) ; flag = 1 ; break; case 1://点击可见光图像 cvshowVison() ; cvShowImage("fusion" , m_display) ; flag = 2 ; break; case 2://点击红外光图像 cvshowRed() ; cvShowImage("fusion" , m_display) ; flag = 3 ; break; default: break; } } void cvprocess1(int x , int y , int &flag){ cvshowThreeImage() ; cvShowImage("fusion" , m_display) ; flag = 0 ; } void onMouse(int Event , int x , int y , int flags , void *param){ int &ID = (*((int *)param)) ; switch(Event){ case CV_EVENT_LBUTTONDBLCLK://左键双击 switch (ID){ case 0://三个窗口下点击 cvprocess0(x , y , ID) ; break; default://其他单窗口下点击 cvprocess1(x , y , ID) ; break; } break; default: break; } } int main(int argc, char *argv[]){ int flag = 0 ;//flag = 0 ;表示显示三个子窗口,flag = 1 ,放大显示融合窗口 , //flag = 2 ,放大显示可见光窗口,flag = 3 放大显示红外光窗口 //CvCapture vison ,red , fusion ; cvNamedWindow("fusion") ; CvCapture *vison = cvCaptureFromFile("01.AVI") ; CvCapture *redLight = cvCaptureFromFile("02.AVI") ; CvCapture *fusion = cvCaptureFromFile("03.AVI") ; while((vis_image = cvQueryFrame(vison)) && (ir_image = cvQueryFrame(redLight)) && (imagesum = cvQueryFrame(fusion))){ // vis_image = cvLoadImage("1.jpg");//可见光图片 // ir_image = cvLoadImage("2.jpg");//红外光图片 // imagesum = cvLoadImage("3.jpg");//融合图片 if(0 == flag)cvshowThreeImage() ; else if(1 == flag)cvshowFusion() ; else if(2 == flag)cvshowVison() ; else cvshowRed() ; cvShowImage("fusion" , m_display) ; cvSetMouseCallback("fusion" , onMouse , &flag) ; int key = cvWaitKey(1) ; if(key >= 0)break ; } //cvWaitKey() ; return 0 ; }
利用OpenCV鼠标控制窗口大小,布布扣,bubuko.com
原文:http://blog.csdn.net/songzitea/article/details/23005315