簡體   English   中英

事件循環卡住:NAO C ++ SDK OnFaceDetection示例

[英]Eventloop stuck: NAO C++ SDK OnFaceDetection Example

我在MAC上安裝了NAOqi C ++ SDK,並嘗試了該SDK中的一些示例。 HelloWorld-Example工作得很好,但是使用OnFaceDetection-Example時 ,在NAO檢測到我的臉后,我將使用qi.eventloop得到一個錯誤/警告

Narongsones-MacBook-Pro:bin Narongsone$ ./onfacedetection --pip 192.168.1.138
[I] 1295 core.common.toolsmain: ..::: starting onfacedetection :::..

[I] 1295 core.common.toolsmain: Connecting to 192.168.1.138:9559...

[I] 1295 qimessaging.session: Session listener created on tcp://0.0.0.0:0
[I] 1295 qimessaging.transportserver: TransportServer will listen on:    tcp://192.168.1.136:64881
[I] 1295 qimessaging.transportserver: TransportServer will listen on: tcp://127.0.0.1:64881
[I] 1295 core.common.toolsmain: Connection with 192.168.1.138:9559 established

[I] 1295 module.example: No face detected

[I] 1295 core.common.toolsmain: onfacedetection is ready... Press CTRL^C to quit

[I] 3843 module.name: 1 face(s) detected.

[I] 4355 qi.eventloop:eventloop:產生更多線程(5)

[I] 4355 qi.eventloop:eventloop:產生更多線程(6)

[I] 4355 qi.eventloop:eventloop:產生更多線程(7)

[I] 4355 qi.eventloop:eventloop:產生更多線程(8)

[I] 4355 qi.eventloop:eventloop:產生更多線程(9)

[I] 4355 qi.eventloop:eventloop:產生更多線程(10)

如果您對問題有任何了解,請幫助我。 謝謝!

我的回調函數:

void OnFaceDetection::callback() {
  /** Use a mutex to make it all thread safe. */
  AL::ALCriticalSection section(fCallbackMutex);

  try {
    /** Retrieve the data raised by the event. */
    fFaces = fMemoryProxy.getData("FaceDetected");
    /** Check that there are faces effectively detected. */
    if (fFaces.getSize() < 2 ) {
      if (fFacesCount != 0) {
        qiLogInfo("module.example") << "No face detected" << std::endl;
        fTtsProxy.say("No face detected.");
        fFacesCount = 0;
      }
      return;
    }
    /** Check the number of faces from the FaceInfo field, and check that it has
    * changed from the last event.*/
    if (fFaces[1].getSize() - 1 != fFacesCount) {
      qiLogInfo("module.name") << fFaces[1].getSize() - 1 << " face(s) detected." << std::endl;
      char buffer[50];

      sprintf(buffer, "%d faces detected.", fFaces[1].getSize() - 1);
      fTtsProxy.say(std::string(buffer));

      /** Update the current number of detected faces. */
      fFacesCount = fFaces[1].getSize() - 1;
    }

  }
  catch (const AL::ALError& e) {
    qiLogError("module.name") << e.what() << std::endl;
  }
}

正如@AlexandreMazel所提到的那樣,此錯誤只是向您說明系統正在創建太多新線程,因為該函數被頻繁調用(最高10x / s),但是由於其中有語音提示而需要執行幾秒鍾。

您可能想要一個標志或非阻塞互斥鎖,以防止該函數多次運行。

關於更改tts.say,下面是一個示例:

通過處理所有文本命令的方法來更改tts.say

tts.say(txt)

變為:

if time.time() - self.lastSaidTime > 5.0 or txt != self.lastSaidText:
    self.lastSaidTime = time.time()
    self.lastSaidText = txt
    tts.say(txt)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM