www.pudn.com > PlateDSP.rar > demoDlg.cpp


// demoDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "demo.h" 
#include "demoDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoDlg dialog 
 
CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CDemoDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CDemoDlg) 
	m_LabelPlate = _T(""); 
	m_LabelType = _T(""); 
	m_LabelColor = _T(""); 
	m_LabelPercent = _T(""); 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CDemoDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CDemoDlg) 
	DDX_Control(pDX, IDC_PICTUREPLATE, m_PicturePlate); 
	DDX_Control(pDX, IDC_PICTURECAR, m_PictureCar); 
	DDX_Control(pDX, IDC_PLATEDSPX1, m_PlateDSPX1); 
	DDX_Text(pDX, IDC_LABELPLATE, m_LabelPlate); 
	DDX_Text(pDX, IDC_LABELTYPE, m_LabelType); 
	DDX_Text(pDX, IDC_LABELCOLOR, m_LabelColor); 
	DDX_Text(pDX, IDC_LABELPERCENT, m_LabelPercent); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog) 
	//{{AFX_MSG_MAP(CDemoDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoDlg message handlers 
 
BOOL CDemoDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// 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 
	m_PlateDSPX1.VideoConnect(0); 
	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// 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 CDemoDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CDemoDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
BEGIN_EVENTSINK_MAP(CDemoDlg, CDialog) 
    //{{AFX_EVENTSINK_MAP(CDemoDlg) 
	ON_EVENT(CDemoDlg, IDC_PLATEDSPX1, 4 /* OnRecoged */, OnOnRecogedPlatedspx1, VTS_I4) 
	//}}AFX_EVENTSINK_MAP 
END_EVENTSINK_MAP() 
 
void CDemoDlg::OnOnRecogedPlatedspx1(long PlateNum)  
{ 
	// TODO: Add your control notification handler code here 
    try 
    { 
        //save and display captured bmp 
        CString TmpFile; 
        TmpFile = theApp.m_pszAppName + "CaptureTmp1.bmp"; 
        m_PlateDSPX1.SaveCapturePicture( TmpFile ); 
		m_PictureCar. 
        ImageCar->Picture->LoadFromFile( TmpFile ); 
        //check recog result 
        if( PlateNum > 0 ) 
        { 
            //get recognition result 
            LabelPlateNumber->Caption = PlateDSPX1->GetPlateNumber(0); 
            LabelPlateType->Caption = "种类:" + AnsiString(PlateDSPX1->GetPlateClassName(0)); 
            LabelPlateColor->Caption = "颜色:" + AnsiString(PlateDSPX1->GetPlateColor(0)); 
            int i = -1; 
            int Per = PlateDSPX1->GetPlateReliability(0,i); 
            AnsiString PerStr = "置信度:" + AnsiString(Per) + " ("; 
            while ( 1 ) 
            { 
                Per = PlateDSPX1->GetPlateReliability(0, ++i); 
                if( Per >= 0 ) 
                { 
                    PerStr = PerStr + " " + AnsiString(Per); 
                } 
                else 
                { 
                    break; 
                } 
            }; 
            LabelPlatePercent->Caption = PerStr + " )"; 
            TmpFile = ExtractFilePath(Application->ExeName) + "PlateTmp1.bmp"; 
            PlateDSPX1->SavePlatePicture( 0, WideString(TmpFile) ); 
            ImagePlate->Picture->LoadFromFile( TmpFile ); 
            ImagePlate->Visible = true; 
        } 
        else 
        { 
            LabelPlateNumber->Caption = ""; 
            LabelPlateType->Caption = ""; 
            LabelPlateColor->Caption = ""; 
            LabelPlatePercent->Caption = ""; 
            ImagePlate->Visible = false; 
        } 
    } 
    catch(...) 
    { 
    } 
	 
}