【正文】
ete pPallete。 fclose(fp)。 return 0。}int CKMDVisionDemoDlg::MakeBmpInfoHeader(CapInfoStruct *pCapInfo, BITMAPINFO *pBmpInfo){ UCHAR btScale = ( pCapInfoControl amp。 0x18 )。 int nScaleMode。 switch( btScale ) { case 0: nScaleMode = 1。 break。 case 8: nScaleMode = 4。 break。 case 16: nScaleMode = 8。 break。 case 24: nScaleMode = 2。 break。 default: nScaleMode = 1。 break。 } pCapInfoWidth /= nScaleMode。 pCapInfoHeight /= nScaleMode。 pBmpInfo = sizeof(BITMAPINFOHEADER)。 pBmpInfo = 1。 pBmpInfo = BI_RGB。 pBmpInfo = 0。 pBmpInfo = 0。 pBmpInfo = 0。 pBmpInfo = 0。 pBmpInfo = 0。 pBmpInfo = 8。 pBmpInfo = pCapInfoWidth。 pBmpInfo = pCapInfoHeight。 return 0。}void CKMDVisionDemoDlg::OnTimer(UINT nIDEvent) { KillTimer(1)。 Start()。 OpenSearchImgs(m_pDispData,640,480)。 SearchKernalRect=。 SetSearchAreas(,(),())。 //SetSearchAreas(0,0,620,460)。 ()。 RunSearchs(0)。 float MatchSpeed =(TRUE)。 float Angledd=GetSearchAngles(0)。 for(int i=0。im_MatchNum。i++) { ResultX=GetSearchResultsX(i,Null)。 ResultY=GetSearchResultsY(i,Null)。 CString ss。 (模板的中心位置為 X=%f Y=%f\n定位后的中心位置為 X=%f Y=%f(單位:像素)\n分數(shù)是%d\n角度是%f\n定位時間%f ,GetModOrgCenterX(),GetModOrgCenterY(),ResultX,ResultY,GetSearchScores(i),Angledd,MatchSpeed)。 GetDlgItem(IDC_RESULTTEXT)SetWindowText(ss)。 if(ResultX!=0 amp。amp。 ResultY!=0) DrawResult(ResultX, ResultY,GetModWidths(),GetModHeights())。 else { GetDlgItem(IDC_RESULTTEXT)SetWindowText(定位失敗!)。 } } SetTimer(1,50,NULL)。 CDialog::OnTimer(nIDEvent)。}void CKMDVisionDemoDlg::DrawImage(){ CDC *pDC = GetDlgItem(IDC_VIEWWND)GetDC()。 CDC MemDC。 CBitmap bm。 (pDC)。 (pDC,640,480)。 CBitmap *pOldBm=(amp。bm)。 ::SetStretchBltMode(MemDC,COLORONCOLOR)。 ::StretchDIBits(MemDC,0,0, 640,480,0,0, 640,480, m_pDispData,m_pBmpInfo,DIB_RGB_COLORS,SRCCOPY)。 ShowResult(amp。MemDC)。 pDCBitBlt(, (),(),amp。MemDC,0,0,SRCCOPY)。 ()。 ()。 ReleaseDC(pDC)。}void CKMDVisionDemoDlg::ShowResult(CDC *pDC){ CPen NewPen(PS_SOLID,1,0x00ff00)。 CPen *pOldPen=pDCSelectObject(amp。NewPen)。 float x = 0。//m_CenterX。 float y = 0。//m_CenterY。 //draw center pDCMoveTo((int)x,(int)y+9)。 pDCLineTo((int)x,(int)y8)。 pDCMoveTo((int)x+9,(int)y)。 pDCLineTo((int)x8,(int)y)。}void CKMDVisionDemoDlg::OnDestroy(){ CDialog::OnDestroy()。}// : Defines the class behaviors for the application.//include include include ifdef _DEBUGdefine new DEBUG_NEWundef THIS_FILEstatic char THIS_FILE[] = __FILE__。endif/////////////////////////////////////////////////////////////////////////////// CKMDVisionDemoAppBEGIN_MESSAGE_MAP(CKMDVisionDemoApp, CWinApp) //{{AFX_MSG_MAP(CKMDVisionDemoApp) // NOTE the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CKMDVisionDemoApp constructionCKMDVisionDemoApp::CKMDVisionDemoApp(){ // TODO: add construction code here, // Place all significant initialization in InitInstance}/////////////////////////////////////////////////////////////////////////////// The one and only CKMDVisionDemoApp objectCKMDVisionDemoApp theApp。/////////////////////////////////////////////////////////////////////////////// CKMDVisionDemoApp initializationBOOL CKMDVisionDemoApp::InitInstance(){ AfxEnableControlContainer()。 // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need.ifdef _AFXDLL Enable3dControls()。 // Call this when using MFC in a shared DLLelse Enable3dControlsStatic()。 // Call this when linking to MFC staticallyendif CKMDVisionDemoDlg dlg。 m_pMainWnd = amp。dlg。 int nResponse = ()。 if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK }// else if (nResponse == IDCANCEL)// { // TODO: Place code here to handle when the dialog is // dismissed with Cancel// } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application39。s message pump. return FALSE。