漫谈WinCE的手写识别技术(二)
GetProcAddress(hInstDll,TEXT(HwxDestroy)); HWXENDINPUT = (DLL_HWXENDINPUT) GetProcAddress(hInstDll,TEXT(HwxEndInput)); } else { return FALSE; } #endif //RECOGNIZE_FUNCTION_FROM_DLL if(HWXCONFIG() == FALSE) { return FALSE; } return TRUE; } //----------------------------------------------------------------------- //Descriptiong: // Begin recognizing //----------------------------------------------------------------------- BOOL CRecognizer::BeginRecognize() { BOOL bRes = FALSE; m_hrc = HWXCREATE(); if(m_hrc == NULL) { goto END; } bRes = HWXSETGUIDE(m_hrc,m_hwxGuide); if(bRes == FALSE) { goto END; } bRes = HWXALCVALID(m_hrc,m_alc); if(bRes == FALSE) { goto END; } bRes = TRUE; END: return bRes; } //----------------------------------------------------------------------- //Descriptiong: // End recognizing BOOL CRecognizer::EndRecognize() { BOOL bRes = FALSE; //Destroy the recognizer if(HWXDESTROY(m_hrc) == FALSE) { goto END; } bRes = TRUE; END: return bRes; } //Descriptiong: // Get the character //Parameters: // pWchar: [out] The character get to be stored // iCount: [in] The number of pWchar //Return Values: // 0: Failed // >0: The number of the characters to return int CRecognizer::GetCharacter(WCHAR *pWchar, int iCount) { int iGetNum = 0; int i = 0; HWXRESULTS *phwxResults; //Because each HWXRESULTS after the first one could store two characters, //so only allocate (iCount / 2 + 1) int iNum = iCount / 2 + 1; phwxResults = new HWXRESULTS[iNum]; memset(phwxResults,0,iNum * sizeof(HWXRESULTS)); //End the input if(HWXENDINPUT(m_hrc) == FALSE) { goto END; } //Analyze the information if(HWXPROCESS(m_hrc) == FALSE) { goto END; } //Get the character from recognizer if(HWXGETRESULTS(m_hrc,iCount,0,1,phwxResults) == FALSE) { goto END; } //Set the character to the stored buffer for(i = 0; i iNum; i++) { if(i == 0) { if(phwxResults[i].rgChar[0] != 0) { pWchar[iGetNum ++] = phwxResults[i].rgChar[0]; } else { break; } } else { //The indxBox member also store the character if(phwxResults[i].indxBox != 0) { pWchar[iGetNum ++] = phwxResults[i].indxBox ; } else { break; } if(phwxResults[i].rgChar[0] != 0) { pWchar[iGetNum ++] = phwxResults[i].rgChar[0]; } else { break; } } } END: if(phwxResults != NULL) { delete [] phwxResults; } return iGetNum; } //Descriptiong: // Input the stroke //Parameter: // lpPnt: [in] Pointer to the stroke POINT // iCount: [in] The count of the lpPnt // scale: [in] The scale base of lpPnt BOOL CRecognizer::InputStroke(POINT *lpPnt, int iCount, ScaleType scale) { BOOL bRes = FALSE; int i = 0; POINT *pt; pt = new POINT[iCount]; if(pt == NULL) { goto END; } for(i = 0; i iCount; i++) { pt[i] = lpPnt[i]; if(scale == SCALE_APPWND) { //Convert to the screen scale pt[i].x *= 4; pt[i].y *= 4; MapWindowPoints(m_hWndRecog, HWND_DESKTOP, pt[i], 1); } } //Input stroke bRes = HWXINPUT(m_hrc,pt,iCount,0); if(bRes == FALSE) { goto END; } bRes = TRUE; END: if(pt != NULL) { delete [] pt; } return bRes; } 不知道大家看到这段代码有什么感觉,反正我是挺高兴的,因为让我从繁琐的识别过程中脱离出来. 关于代码,也许最让人疑惑的可能是这两个宏:RECOGNIZE_FUNCTION_FROM_DLL,RECOGNIZE_FUNCTION_FROM_LIB. 顾名思义,RECOGNIZE_FUNCTION_FROM_DLL表明识别函数调用是来源于动态链接库(DLL),同理,RECOGNIZE_FUNCTION_FROM_LIB则是编译的时候链接到lib库.为什么需要定义这两个宏呢?因为在标准的SDK下,如果直接包含recog.h后调用相关识别函数,是会报link错误.因为标准的SDK是不包含任何手写识别组件的.从调试的便利性来说,这时候如果只拷贝识别库到模拟器就可以顺利测试程序,绝对比重新定制一个包含手写识别引擎的系统要来得方便. 在示例代码中,因为是识别繁体中文,所以包含的动态链接库为:hwxcht.dll.如果需要识别其它文字,则只要更改该动态链接库名称即可.当然,还要更改DEFAULT_ALC宏,这个宏定义了识别的范围. 因为示例代码中的识别函数全部是宏定义,具体意义根据函数![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
