开发环境:VS2012 + OpenCV2.4 (OpenCV语句使用 旧版本形式)
功能:使用鼠标控制三个窗口的放大与缩小
使用见程序:
#include
#include
#include
#include
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 showFusion()
{
cvResize(imagesum,large_display,CV_INTER_LINEAR);
cvSetImageROI(m_display,rectLarge);
cvCopy(large_display,m_display);
cvResetImageROI(m_display);
}
void showVison()
{
cvResize(vis_image,large_display,CV_INTER_LINEAR);
cvSetImageROI(m_display,rectLarge);
cvCopy(large_display,m_display);
cvResetImageROI(m_display);
}
void showRed()
{
cvResize(ir_image,large_display,CV_INTER_LINEAR);
cvSetImageROI(m_display,rectLarge);
cvCopy(large_display,m_display);
cvResetImageROI(m_display);
}
void showThreeImage()
{
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 process0(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://点击融合图像
showFusion() ;
cvShowImage("fusion" , m_display) ;
flag = 1 ;
break;
case 1://点击可见光图像
showVison() ;
cvShowImage("fusion" , m_display) ;
flag = 2 ;
break;
case 2://点击红外光图像
showRed() ;
cvShowImage("fusion" , m_display) ;
flag = 3 ;
break;
default:
break;
}
}
void process1(int x , int y , int &flag)
{
showThreeImage() ;
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://三个窗口下点击
process0(x , y , ID) ;
break;
default://其他单窗口下点击
process1(x , y , ID) ;
break;
}
break;
default:
break;
}
}
int main()
{
//flag = 0 ;表示显示三个子窗口,flag = 1 ,放大显示融合窗口 ,
//flag = 2 ,放大显示可见光窗口,flag = 3 放大显示红外光窗口
int flag = 0 ;
//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)showThreeImage() ;
else if(1 == flag)showFusion() ;
else if(2 == flag)showVison() ;
else showRed() ;
cvShowImage("fusion" , m_display) ;
cvSetMouseCallback("fusion" , onMouse , &flag) ;
int key = cvWaitKey(1) ;
if(key >= 0)break ;
}
//cvWaitKey() ;
return 0 ;
}