【问题标题】:TUIO cursor + openframeworksTUIO光标+开放框架
【发布时间】:2014-03-21 18:55:02
【问题描述】:

我正在尝试制作一个应用程序来执行一些 blob 跟踪并使用 TUIO cursor 消息发送 Unity3D 的所有数据,就像 CCV 一样。 这就是我对消息的看法("media" 是一个按钮,用于在发送所有 blob 的位置/id 或发送平均值之间切换):

  void testApp::blobOn( int x, int y, int id, int order )
    {
        cout << "blobOn() - id:" << id << " order:" << order << endl;

    ofxOscMessage m;
    m.setAddress("/tuio2/2Dcur");
    m.addStringArg("set");

    if(media == false){
        m.addIntArg(id);
        m.addFloatArg(newX);
        m.addFloatArg(newY);
        cout << "Posicao x: " << newX << endl;
        cout << "Posicao y: " << newY << endl;
    }
    else{
        m.addIntArg(0);
        m.addFloatArg(newMediaX);
        m.addFloatArg(newMediaY);
    }

    m.addFloatArg(0);
    m.addFloatArg(0);
    m.addFloatArg(0);
    m.addFloatArg(0);

    ofxOscMessage l;
    l.setAddress("/tuio/2Dcur");
    l.addStringArg("alive");

    if (blobList.size() > 0)
    {
        if(media == false){
            for (std::map<int,blob>::iterator it=blobList.begin(); it!=blobList.end(); ++it){
                l.addIntArg(it -> first);
                cout << "it first: " << it -> first << endl;
            }
    }else{
        l.addIntArg(0);
        }
    }

    sender.sendMessage(l);
    sender.sendMessage(m);
}


 //--------------------------------------------------------------



void testApp::blobMoved( int x, int y, int id, int order)
{
    cout << "blobMoved() - id:" << id << " order:" << order << endl;

    ofCvTrackedBlob blob_ = blobTracker.getById( id );        

    ofxOscMessage m;
    m.setAddress("/tuio/2Dcur");
    m.addStringArg("set");
    if(media == false){
        m.addIntArg(id);
        m.addFloatArg(newX);
        m.addFloatArg(newY);
        cout << "Posicao x: " << newX << endl;
        cout << "Posicao y: " << newY << endl;
    }
    else{
        m.addIntArg(0);
        m.addFloatArg(newMediaX);
        m.addFloatArg(newMediaY);
    }


    m.addFloatArg(0);
    m.addFloatArg(0);
    m.addFloatArg(0);
    m.addFloatArg(0);

    ofxOscMessage n;
    n.setAddress("/tuio/2Dcur");
    n.addStringArg("alive");

    if (blobList.size() > 0)
    {

        if(media == false){
            for (std::map<int,blob>::iterator it=blobList.begin(); it!=blobList.end(); ++it){
                n.addIntArg(it -> first);
            }
        }
        else {
            n.addIntArg(0);
        }
    }

    sender.sendMessage(n);
    sender.sendMessage(m);
}


//--------------------------------------------------------------


void testApp::blobOff( int x, int y, int id, int order )
{
    cout << "blobOff() - id:" << id << " order:" << order << endl;

    ofxOscMessage m;
    m.setAddress("/tuio/2Dcur");
    m.addStringArg("alive");

    blobList.erase(id);


    if (blobList.size() > 0)
    {
        if(media == false){
            for (std::map<int,blob>::iterator it=blobList.begin(); it!=blobList.end(); ++it){
                m.addIntArg(it -> first);
            }
        }
        else {
            m.addIntArg(0);
        }
    }

    sender.sendMessage(m);
}

我的 Unity 应用程序没有收到我的消息/blob,所以我认为它们的格式不正确。谁能告诉我可能出了什么问题?

【问题讨论】:

    标签: c++ computer-vision blob openframeworks osc


    【解决方案1】:

    首先要提的是

    m.setAddress("/tuio2/2Dcur");

    应该是

    m.setAddress("/tuio/2Dcur");
    

    TUIO 标准(1.1 和 1.0)对 2Dcur 的定义如下:

    /tuio/2Dcur set s x y X Y m
    

    在您的代码中,您设置 s、x 和 y,然后添加四倍 0.0 (addFloatArg(0)),因此您实际上会收到如下消息:

    /tuio/2Dcur set s x y 0.0 0.0 0.0 0.0
    

    这是一个浮动太多。在 OSC 中,您通常订阅带有完整签名的消息。这就是您在 Unity 应用程序中没有收到消息的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-05
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多