www.pudn.com > PlateDSP.rar > demoView.cpp
// demoView.cpp : implementation of the CDemoView class
//
#include "stdafx.h"
#include "demo.h"
#include "demoDoc.h"
#include "demoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDemoView
IMPLEMENT_DYNCREATE(CDemoView, CFormView)
BEGIN_MESSAGE_MAP(CDemoView, CFormView)
//{{AFX_MSG_MAP(CDemoView)
ON_COMMAND(ID_FILE_BMP, OnFileBmp)
ON_COMMAND(ID_FILE_DVD, OnFileDvd)
ON_COMMAND(ID_SET_RECOG, OnSetRecog)
ON_COMMAND(ID_SET_CONTROL, OnSetControl)
ON_COMMAND(ID_ABOUT, OnAbout)
ON_COMMAND(ID_VIDEORESTART, OnVideorestart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemoView construction/destruction
CDemoView::CDemoView()
: CFormView(CDemoView::IDD)
{
//{{AFX_DATA_INIT(CDemoView)
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CDemoView::~CDemoView()
{
}
void CDemoView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemoView)
DDX_Control(pDX, IDC_STATIC_PLATEBMP, m_ImagePlate);
DDX_Control(pDX, IDC_STATIC_CARBMP, m_ImageCar);
DDX_Control(pDX, IDC_PLATEDSPX1, m_PlateDSPX1);
//}}AFX_DATA_MAP
}
BOOL CDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CDemoView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_PlateDSPX1.VideoConnect(0);
//
char Buffer[_MAX_PATH];
GetCurrentDirectory( sizeof(Buffer), Buffer );
CurPath = Buffer;
}
/////////////////////////////////////////////////////////////////////////////
// CDemoView diagnostics
#ifdef _DEBUG
void CDemoView::AssertValid() const
{
CFormView::AssertValid();
}
void CDemoView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CDemoDoc* CDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDoc)));
return (CDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDemoView message handlers
void CDemoView::OnFileBmp()
{
// TODO: Add your command handler code here
CFileDialog aDlg(true);
aDlg.m_ofn.nFilterIndex = 1;
aDlg.m_ofn.lpstrFilter = "Bitmap/JPG files(*.bmp;*.jpg)\0*.bmp;*.jpg\0"
"Bitmap files(*.bmp)\0*.bmp\0"
"JPG files(*.jpg)\0*.jpg\0"
"\0";
CString tmp = m_PlateDSPX1.GetOcxPath();
aDlg.m_ofn.lpstrInitialDir = tmp;
if( aDlg.DoModal() == IDOK )
{
m_PlateDSPX1.FileRecog( aDlg.GetPathName() );
}
}
void CDemoView::OnFileDvd()
{
// TODO: Add your command handler code here
CFileDialog aDlg(true);
aDlg.m_ofn.nFilterIndex = 1;
aDlg.m_ofn.lpstrFilter = "All (*.avi;*.mpg;*.wmv)\0*.avi;*.mpg;*.wmv\0"
"Video for windows files (*.avi)\0*.avi\0"
"MPEG files (*.mpg)\0*.mpg\0"
"Windows media file (*.wmv)\0*.wmv\0"
"\0";
CString tmp = m_PlateDSPX1.GetOcxPath();
aDlg.m_ofn.lpstrInitialDir = tmp;
if( aDlg.DoModal() == IDOK )
{
m_PlateDSPX1.FileRecog( aDlg.GetPathName() );
}
}
void CDemoView::OnSetRecog()
{
// TODO: Add your command handler code here
m_PlateDSPX1.RecogDlg();
}
void CDemoView::OnSetControl()
{
// TODO: Add your command handler code here
m_PlateDSPX1.ControlDlg();
}
void CDemoView::OnVideorestart()
{
// TODO: Add your command handler code here
m_PlateDSPX1.VideoConnect(0);
}
void CDemoView::OnAbout()
{
// TODO: Add your command handler code here
m_PlateDSPX1.AboutDlg();
}
BEGIN_EVENTSINK_MAP(CDemoView, CFormView)
//{{AFX_EVENTSINK_MAP(CDemoView)
ON_EVENT(CDemoView, IDC_PLATEDSPX1, 4 /* OnRecoged */, OnOnRecogedPlatedspx1, VTS_I4)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CDemoView::DisplayBmp(CString &File,CStatic &Image)
{
HBITMAP hbm = (HBITMAP)LoadImage(NULL, File, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if( hbm!=NULL )
{
BITMAP bm;
GetObject( hbm, sizeof(bm), &bm ); // get size of bitmap
HDC hdcImage = CreateCompatibleDC(NULL);
if( hdcImage )
{
SelectObject(hdcImage, hbm);
CDC *pDC = Image.GetDC();
CRect rect;
Image.GetClientRect(&rect);
SetStretchBltMode( pDC->m_hDC, COLORONCOLOR );
StretchBlt( pDC->m_hDC, 0, 0, rect.Width(), rect.Height(),
hdcImage, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY );
DeleteDC( hdcImage );
}
DeleteObject( hbm );
}
}
void CDemoView::OnOnRecogedPlatedspx1(long PlateNum)
{
// TODO: Add your control notification handler code here
CarBmpFile = CurPath + "\\CaptureTmp1.bmp";
m_PlateDSPX1.SaveCapturePicture( CarBmpFile );
m_ImageCar.Invalidate();
CString tmp;
if( PlateNum > 0 )
{
PlateBmpFile = CurPath + "\\PlateTmp1.bmp";
m_PlateDSPX1.SavePlatePicture( 0, PlateBmpFile );
m_ImagePlate.Invalidate();
tmp = "种类:" + m_PlateDSPX1.GetPlateClassName(0);
SetDlgItemText( IDC_STATIC_CLASS, tmp );
tmp = m_PlateDSPX1.GetPlateNumber(0);
SetDlgItemText( IDC_STATIC_PLATE, tmp );
tmp.Format( "颜色代码:%d", m_PlateDSPX1.GetPlateColor(0) );
SetDlgItemText( IDC_STATIC_COLOR, tmp );
int i=-1;
int Per = m_PlateDSPX1.GetPlateReliability(0,i);
tmp.Format( "置信度:%d(", Per );
while ( 1 )
{
Per = m_PlateDSPX1.GetPlateReliability(0, ++i);
if( Per >= 0 )
{
CString tmp1;
tmp1.Format( " %d", Per );
tmp = tmp + tmp1;
}
else
{
break;
}
};
tmp = tmp + " )";
SetDlgItemText( IDC_STATIC_PERCENT, tmp );
}
else
{
}
//Invalidate();
}
void CDemoView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
if( CarBmpFile!="" )
{
DisplayBmp( CarBmpFile, m_ImageCar );
CarBmpFile = "";
}
if( PlateBmpFile!="" )
{
DisplayBmp( PlateBmpFile, m_ImagePlate );
PlateBmpFile = "";
}
}