1

我是編程和圖像處理新手。最近我開發了一個系統,可以檢測視頻中的人臉並識別出人物。如果該人已經在數據庫上可用,則將其姓名標記到框架上,否則如果該人是新的,則它要求他們的姓名並且在數據庫中存儲足夠的照片並存儲,以便它可以在下次識別該人時。我正在使用fisher-faces算法來完成這項任務。 現在我的問題是,我想讓系統談談。我想讓它告訴它最近識別的人的名字。 我可以使用自主實時人臉識別系統

static class Once { public: Once(){talk();}} Once_; 

一次調用函數的談話。 但它不是有機的,談話功能不接受來自用戶的輸入。

任何人都可以請建議我一個解決方案,或從哪裏開始解決這個問題。

的通話功能

int speech(char* value) 
{ 

ISpVoice * pVoice = NULL; 

if (FAILED(::CoInitialize(NULL))) 
    return FALSE; 

HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice); 
if(SUCCEEDED(hr)) 
{ 
    hr = pVoice->Speak(L"userINPUT", SPF_IS_XML, NULL); 
    pVoice->Release(); 
    pVoice = NULL; 
} 

::CoUninitialize(); 
return TRUE; 
} 
+0

什麼是你的靜態類的目的一次?爲什麼不直接在識別後調用速度,在哪裏知道名稱? (並且請編輯並稱之爲'speak'或類似的,而不是'速度' – berak

+0

我在識別後調用語音,但函數hr = pVoice-> Speak(L「userINPUT」,SPF_IS_XML,NULL);不支持userInput。只讀取userIndut作爲文本 – raj3209812

+0

我需要一個函數,可以將用戶輸入作爲屬性或參數傳遞的語音函數 – raj3209812

回答

0

所以,這裏是我的建議:

// -- >8 ---------- speech.h -------------------------- 
#ifndef __speech_onboard__ 
#define __speech_onboard__ 


struct ISpVoice; // fwd ref, since mixing opencv and windows headers is a receipt for desaster 

namespace Speech 
{ 
    class Voice 
    { 
     ISpVoice * spVoice; 

    public: 

     Voice(); 
     ~Voice(); 


     int speak(const char * txt, int flags=0) const ; 

     // Supported values range from -10 to 10 
     int setRate(int s); 

     // Supported values range from 0 to 100 
     int setVolume(int s); 
    }; 
}; 


#endif // __speech_onboard__ 



// ---- >8 speech.cpp ------------------------------ 
#include <windows.h> 
#include <sapi.h> 
#include "speech.h" 


#define COM_RELEASE(x) { if ((x)) (x)->Release(); (x) = NULL; } 


namespace Speech 
{ 
    struct _ComUser 
    { 
     _ComUser() {CoInitialize(0);} 
     ~_ComUser() {CoUninitialize();} 
    } _we_need_a_singleton_per_module; 


    inline int w2a(WCHAR *in, char *out) 
    { 
     out[0]=0; 
     return WideCharToMultiByte(CP_ACP, 0, in, -1, out, MAX_PATH, 0, 0); 
    } 

    inline int a2w(const char *in, WCHAR *out) 
    { 
     out[0]=0; 
     return MultiByteToWideChar(CP_ACP, 0, in, -1, out, MAX_PATH); 
    } 




    Voice::Voice() 
     : spVoice(0) 
    { 
     HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_INPROC_SERVER, IID_ISpVoice, (LPVOID *)&(spVoice)); 
    } 


    Voice::~Voice() 
    { 
     COM_RELEASE(spVoice); 
    } 

    //SPF_ASYNC = (1L << 0) , 
    //SPF_PURGEBEFORESPEAK = (1L << 1) , 
    //SPF_IS_FILENAME = (1L << 2) , 
    //SPF_IS_XML = (1L << 3) , 
    //SPF_IS_NOT_XML = (1L << 4) , 
    //SPF_PERSIST_XML = (1L << 5) , 
    //SPF_NLP_SPEAK_PUNC = (1L << 6) , 
    //SPF_PARSE_SAPI = (1L << 7) , 
    //SPF_PARSE_SSML = (1L << 8) , 
    //SPF_PARSE_AUTODETECT = 0, 
    int Voice::speak(const char * txt, int flags) const 
    { 
     if (! spVoice) 
      return 0; 

     WCHAR wtxt[800]; 
     a2w(txt,wtxt); 

     ULONG pulstream = 0; 
     HRESULT hr = spVoice->Speak(wtxt, flags, &pulstream); 

     return hr==S_OK; 
    } 


    // Supported values range from -10 to 10 
    int Voice::setRate(int s) 
    { 
     if (! spVoice) 
      return 0; 

     HRESULT hr = spVoice->SetRate(s); 

     return hr==S_OK; 
    } 

    // Supported values range from 0 to 100 
    int Voice::setVolume(int s) 
    { 
     if (! spVoice) 
      return 0; 

     HRESULT hr = spVoice->SetVolume (s); 

     return hr==S_OK; 
    } 
} 



// ----- >8 main.cpp -------------------------------------------- 

#include "opencv2/core/core.hpp" 
#include "opencv2/highgui/highgui.hpp" 

using namespace cv; 

#include "speech.h" 

int main(int argc, char** argv) 
{ 
    Speech::Voice voice; 
    voice.speak("hello , oh, hello!", 1); // async 

    Mat img(300,300,CV_8UC3,Scalar(255,0,0)); 
    namedWindow("Display window",0); 
    putText(img,"lala la",Point(20,120),0,2.5,Scalar(0,200,0),5); 
    imshow("Display window", img); 
    waitKey(0); 

    voice.speak("bye bye, see you later !"); // sync 
    return 0; 
} 
+0

看起來不錯,我現在就試試看,並會回來。 – raj3209812

+0

我有一個小問題,在voice.speak(「你好,哦,你好!」,1);我可以傳遞來自用戶的字符串,例如voice.speak(「hello」inputstring,1); – raj3209812

+0

我發現這[link](http://stackoverflow.com/questions/15573246/store-a-variable-that-holds-user-input-data-in-sapi5-speak-function) – raj3209812