简体   繁体   English

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

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

I installed the NAOqi C++ SDK on my MAC and I tried out some examples from the SDK. 我在MAC上安装了NAOqi C ++ SDK,并尝试了该SDK中的一些示例。 HelloWorld-Example worked fine but with the OnFaceDetection-Example I'll get an Error/Warning with qi.eventloop after the NAO detect my face. 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: Spawning more threads (5) [I] 4355 qi.eventloop:eventloop:产生更多线程(5)

[I] 4355 qi.eventloop: eventloop: Spawning more threads (6) [I] 4355 qi.eventloop:eventloop:产生更多线程(6)

[I] 4355 qi.eventloop: eventloop: Spawning more threads (7) [I] 4355 qi.eventloop:eventloop:产生更多线程(7)

[I] 4355 qi.eventloop: eventloop: Spawning more threads (8) [I] 4355 qi.eventloop:eventloop:产生更多线程(8)

[I] 4355 qi.eventloop: eventloop: Spawning more threads (9) [I] 4355 qi.eventloop:eventloop:产生更多线程(9)

[I] 4355 qi.eventloop: eventloop: Spawning more threads (10) [I] 4355 qi.eventloop:eventloop:产生更多线程(10)

Please, help me if you have any idea about what the problem is. 如果您对问题有任何了解,请帮助我。 Thank you! 谢谢!

My callback function: 我的回调函数:

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;
  }
}

As mentionned by @AlexandreMazel, this error is simply explaining you that the system is creating too many new threads as the function is called very often (up to 10x/s) but takes a few seconds to execute as there is a speech in it. 正如@AlexandreMazel所提到的那样,此错误只是向您说明系统正在创建太多新线程,因为该函数被频繁调用(最高10x / s),但是由于其中有语音提示而需要执行几秒钟。

You might want to have a flag or a non-blocking mutex to prevent the function to be run several times. 您可能想要一个标志或非阻塞互斥锁,以防止该函数多次运行。

About changing the tts.say, here's an example: 关于更改tts.say,下面是一个示例:

change the tts.say by a method handling all text commands 通过处理所有文本命令的方法来更改tts.say

tts.say(txt)

becomes: 变为:

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