다음을 통해 공유


기본 인식 샘플

이 애플리케이션은 간단한 필기 인식 애플리케이션을 빌드하는 방법을 보여 줍니다.

이 프로그램은 InkCollector 개체를 만들어 잉크 창 및 기본 인식기 컨텍스트 개체를 사용하도록 설정합니다. 애플리케이션의 메뉴에서 실행된 "Recognize!" 명령을 받으면 수집된 잉크 스트로크가 인식기 컨텍스트로 전달됩니다. 최상의 결과 문자열은 메시지 상자에 표시됩니다.

RecognizerContext 개체 만들기

애플리케이션에 대한 WndProc 프로시저에서 시작 시 WM_CREATE 메시지를 받으면 기본 인식기를 사용하는 새 인식기 컨텍스트가 만들어집니다. 이 컨텍스트는 애플리케이션의 모든 인식에 사용됩니다.

case WM_CREATE:
{
    HRESULT hr;
    hr = CoCreateInstance(CLSID_InkRecognizerContext,
             NULL, CLSCTX_INPROC_SERVER, IID_IInkRecognizerContext,
             (void **) &g_pIInkRecoContext);
    if (FAILED(hr))
    {
        ::MessageBox(NULL, TEXT("There are no handwriting recognizers installed.\n"
            "You need to have at least one in order to run this sample.\nExiting."),
            gc_szAppName, MB_ICONERROR);
        return -1;
    }
  //...

스트로크 인식

인식 명령은 사용자가 Recognize!를 클릭할 때 수신됩니다. 메뉴 항목입니다. 이 코드는 InkDisp 개체에서 잉크 InkStrokes(pIInkStrokes)에 대한 포인터를 가져오고 putref_Strokes 호출을 사용하여 InkStrokes 인식기 컨텍스트에 전달합니다.

 case WM_COMMAND:
  //...
  else if (wParam == ID_RECOGNIZE)
  {
      // change cursor to the system's Hourglass
      HCURSOR hCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
      // Get a pointer to the ink stroke collection
      // This collection is a snapshot of the entire ink object
      IInkStrokes* pIInkStrokes = NULL;
      HRESULT hr = g_pIInkDisp->get_Strokes(&pIInkStrokes);
      if (SUCCEEDED(hr)) 
      {
          // Pass the stroke collection to the recognizer context
          hr = g_pIInkRecoContext->putref_Strokes(pIInkStrokes);
          if (SUCCEEDED(hr)) 
          {

그런 다음 코드는 InkRecognizerContext 개체의 Recognize 메서드를 호출하고 IInkRecognitionResult 개체에 대한 포인터를 전달하여 결과를 저장합니다.

              // Recognize
              IInkRecognitionResult* pIInkRecoResult = NULL;
              hr = g_pIInkRecoContext->Recognize(&pIInkRecoResult);
              if (SUCCEEDED(hr)) 
              {

마지막으로 코드는 IInkRecognitionResult 개체의 TopString 속성을 사용하여 상위 인식 결과를 문자열 변수로 검색하고, IInkRecognitionResult 개체를 해제하고, 메시지 상자에 문자열을 표시합니다.

                  // Get the best result of the recognition 
                  BSTR bstrBestResult = NULL;
                  hr = pIInkRecoResult->get_TopString(&bstrBestResult);
                  pIInkRecoResult->Release();
                  pIInkRecoResult = NULL;

                  // Show the result string
                  if (SUCCEEDED(hr) && bstrBestResult)
                  {
                      MessageBoxW(hwnd, bstrBestResult, 
                                  L"Recognition Results", MB_OK);
                      SysFreeString(bstrBestResult);
                  }  }
        

사용량 간에 인식기 컨텍스트를 다시 설정해야 합니다.

              // Reset the recognizer context
              g_pIInkRecoContext->putref_Strokes(NULL);
          }
          pIInkStrokes->Release();
      }
      // restore the cursor
      ::SetCursor(hCursor);
  }