1.1.6-学习Opencv与MFC混合编程之---播放WAV音乐和 alpha融合功能

源代码:http://download.csdn.net/detail/nuptboyzhb/3961698

Alpha融合菜单项

1.      增加alpha融合菜单项,修改相应的属性,建立类向导,编辑消息处理函数。

2.      在消息处理函数中添加如下代码

void CCVMFCView::OnAlphaMix()

{

//TODO: Add your command handler code here

//TODO: Add your command handler code here

IplImage*src1, *src2;

CStringcsAVI="src1 Files(lena.bmp)|*.bmp|";

   CString csFilter=csAVI;

CStringcsFilter2="src2 Files(gs76.bmp)|*.bmp|";

CStringname[]={"","bmp",""};

CStringstrFileName;

CStringstrExtension;

CFileDialogFileDlg(true,NULL,NULL,OFN_HIDEREADONLY,csFilter);

if(FileDlg.DoModal()==IDOK ) {        //  选择了文件名

           strFileName= FileDlg.m_ofn.lpstrFile;

           if(FileDlg.m_ofn.nFileExtension == 0) { //  无文件后缀

                    strExtension= name[FileDlg.m_ofn.nFilterIndex];

                    strFileName= strFileName + '.' + strExtension;

                    //  加文件后缀

           }

           src1=cvLoadImage(strFileName);

           if(src1)

           {

          MessageBox("还需要打开一张图片!");

           }

       CFileDialog FileDlg(true,NULL,NULL,OFN_HIDEREADONLY,csFilter2);

           if(FileDlg.DoModal()==IDOK ) {        //  选择了文件名

                    strFileName= FileDlg.m_ofn.lpstrFile;

                    if(FileDlg.m_ofn.nFileExtension == 0) { //  无文件后缀

                             strExtension= name[FileDlg.m_ofn.nFilterIndex];

                             strFileName= strFileName + '.' + strExtension;

                             //  加文件后缀

           }

           src2=cvLoadImage(strFileName);

           cvNamedWindow("src1",CV_WINDOW_AUTOSIZE);

           cvMoveWindow("src1",300,300);

           cvShowImage("src1",src1);

           cvNamedWindow("src2",CV_WINDOW_AUTOSIZE);

           cvMoveWindow("src2",300+src1->width,300);

           cvShowImage("src2",src2);

           intx = 112;

       int y = 123;

       int width =src2->width;

       int height =src2->height;

       double alpha = 0.5;

       double beta  = 1-alpha;

       cvSetImageROI(src1, cvRect(x,y,width,height));

       cvSetImageROI(src2, cvRect(0,0,width,height));

       cvAddWeighted(src1, alpha, src2, beta,0.0,src1);

       cvResetImageROI(src1);

       cvNamedWindow( "Alpha_blend",CV_WINDOW_AUTOSIZE );

              cvMoveWindow("Alpha_blend",350+src1->width+src2->width,300);

       cvShowImage( "Alpha_blend", src1 );

       cvWaitKey(0);

           cvReleaseImage(&src1);

           cvReleaseImage(&src2);

           }

}

}


播放wav音乐

1.插入资源(插入->资源->定制->(输入WAVA))

2.在resources中找到"WAVA"文件,打开有个IDR_WAVA1

3.右键->import->浏览后缀名为.wav的音频文件

4.在CXXXXView的构造函数中添加:

PlaySound(MAKEINTRESOURCE(IDR_TAOBAO_SENT_SOUND),AfxGetResourceHandle(),SND_ASYNC|SND_RESOURCE);

5.在该文件的上方,添加头文件#include"mmsystem.h"

6.工程->设置->连接->库模板添加"winmm.lib"

你可能感兴趣的:(opencv)