void CDIPDlg::OnOpen() { // TODO: Add your command handler code here CString fileName; CFileDialog OpenDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_EXPLORER,"图像文件格式(*.bmp)|*.bmp|JPG file format (*.jpg)|*.jpg|",NULL); if(OpenDlg.DoModal()!=IDOK) return; fileName=OpenDlg.GetPathName(); std::string tempName=(LPCSTR)CString(fileName); const char* tmp=tempName.c_str(); if((pImg=cvLoadImage(tmp,1))==0) return; wImg=cvCreateImage(cvGetSize(pImg),pImg->depth,pImg->nChannels); cvCopy(pImg,wImg,NULL); ShowImage( pImg,IDC_STATIC_P ); ShowOImage( pImg, IDC_STATIC_O ); } void CDIPDlg::OnSave() { // TODO: Add your command handler code here CFileDialog SaveDlg(FALSE,"bmp","未命名",OFN_HIDEREADONLY|OFN_EXPLORER,"图像文件格式(*bmp)|*.bmp|JPG file format (*jpg)|*.jpg|",NULL); if(SaveDlg.DoModal()==IDOK){ CString savefileName=SaveDlg.GetPathName(); std::string tempSaveName=(LPCSTR)CString(savefileName); const char* nameOfFile=tempSaveName.c_str(); if(wImg) cvSaveImage(nameOfFile,wImg); else cvSaveImage(nameOfFile,pImg); MessageBox("ok!"); } else MessageBox("no!"); } void CDIPDlg::OnEsc() { // TODO: Add your command handler code here CDialog::OnDestroy(); cvReleaseImage(&pImg;); cvReleaseImage(&wImg;); cvReleaseImage(&gImg;); cvDestroyAllWindows(); AfxGetMainWnd()->SendMessage(WM_CLOSE); } void CDIPDlg::OnGaos() { // TODO: Add your command handler code here wImg=cvCreateImage(cvGetSize(pImg),pImg->depth,pImg->nChannels); cvCopy(pImg,wImg,NULL); IplImage* in; in = wImg; IplImage* out = cvCreateImage(cvGetSize(in),IPL_DEPTH_8U,wImg->nChannels); // 建立辅助位图 cvSmooth(in,out,CV_GAUSSIAN,3,wImg->nChannels); // Gauss 平滑 // cvNamedWindow("高斯滤波",1); // cvShowImage("高斯滤波",out); ShowImage( out,IDC_STATIC_P ); wImg=cvCreateImage(cvGetSize(out),out->depth,out->nChannels); cvCopy(out,wImg,NULL); cvWaitKey(0); // cvDestroyWindow("高斯滤波"); cvReleaseImage(∈); cvReleaseImage(&out;); }
1