为什么工程运行出来之后,图片调用不出来,是不是程序哪里有问题,求大神看一下程序!
#include "stdafx.h"
#include "GraduateThesis.h"
#include "GraduateThesisDlg.h"
#include "highgui.h"
#include "sobelVideoController.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CcvisionDlg dialog
CGraduateThesisDlg::CGraduateThesisDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGraduateThesisDlg::IDD, pParent)
, duration(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CGraduateThesisDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, duration);
}
BEGIN_MESSAGE_MAP(CGraduateThesisDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_OPEN, &CGraduateThesisDlg::OnOpen)
ON_BN_CLICKED(IDOK, &CGraduateThesisDlg::OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, &CGraduateThesisDlg::OnBnClickedCancel)
ON_BN_CLICKED(IDC_PROC, &CGraduateThesisDlg::OnProcess)
ON_BN_CLICKED(IDC_PAUSE, &CGraduateThesisDlg::OnBnClickedPause)
ON_BN_CLICKED(IDC_STOP, &CGraduateThesisDlg::OnBnClickedStop)
ON_BN_CLICKED(IDC_LOADIMAGE, &CGraduateThesisDlg::OnBnClickedLoadimage)
ON_BN_CLICKED(IDC_DEMO, &CGraduateThesisDlg::OnBnClickedDemo)
END_MESSAGE_MAP()
// CcvisionDlg message handlers
BOOL CGraduateThesisDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
//this->GetDlgItem(IDC_STATIC1)->SetWindowText("视频处理");//给控件加中文名
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//cvNamedWindow("Result");
image= 0;
//HWND hWnd=(HWND)cvGetWindowHandle("Result"); //改变初始窗口位置
/*HWND hParent=::FindWindow(" CGraduateThesisDlg","GraduateThesis");
RECT cvrect, hrect;
cvrect=(RECT)GetWindowRect(hWnd);
hrect=(RECT)GetWindowRect(hParent);*/
//SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
//SetWindowPos(hWnd,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
duration= 1000; // default value
UpdateData(false); // display the content of the variable in Edit Control
return TRUE; // return TRUE unless you set the focus to a control
}
void CGraduateThesisDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CGraduateThesisDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CGraduateThesisDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CGraduateThesisDlg::OnOpen()
{
CFileDialog dlg(TRUE, _T("*.avi"), NULL,
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,
_T("video files (*.avi) |*.avi|All Files (*.*)|*.*||"),NULL);
dlg.m_ofn.lpstrTitle= _T("Open Video");
if (dlg.DoModal() == IDOK) {
CString path= dlg.GetPathName(); // contain the selected filename
SobelVideoController::getInstance()->setFile(path);
}
}
void CGraduateThesisDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
cvDestroyAllWindows();
cvReleaseImage(&image);
SobelVideoController::getInstance()->destroy();
OnOK();
}
void CGraduateThesisDlg::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
cvDestroyAllWindows();
cvReleaseImage(&image);
SobelVideoController::getInstance()->destroy();
OnCancel();
}
void CGraduateThesisDlg::OnProcess()
{
UpdateData(true); // display the content of the variable in Edit Control
SobelVideoController::getInstance()->run();
}
void CGraduateThesisDlg::OnBnClickedPause()
{
}
void CGraduateThesisDlg::OnBnClickedStop()
{
SobelVideoController::getInstance()->stop();
}
void CGraduateThesisDlg::OnBnClickedLoadimage()
{
// TODO: 在此添加控件通知处理程序代码
CFileDialog dlg(TRUE,_T("*.bmp"),NULL,
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,
_T("image file(*.bmp;*.jpg)|*.bmp ; *.jpg | *.jpeg|All Files (*.*)|*.*||"),NULL);
dlg.m_ofn.lpstrTitle=_T("open image");
if (dlg.DoModal() == IDOK) {
CString path= dlg.GetPathName();
}
}
void CGraduateThesisDlg::OnBnClickedDemo()
{
// TODO: 在此添加控件通知处理程序代码
cvNamedWindow("Result");
}