Ejemplo n.º 1
0
void ParseTree::showDetection(cv::Mat img, bool display)
{
    for ( int i = 0; i < nodeSet().size(); ++i ) {
        if ( nodeSet()[i]->idx()(PtNode::IDX_TYPE) != static_cast<int>(Node::T_NODE) ) {
            continue;
        }
        const ParseInfo * info = nodeSet()[i]->parseInfo(this);
        cv::rectangle(img, info->cvRect(), cv::Scalar::all(255), 3);
        cv::rectangle(img, info->cvRect(), cv::Scalar(255, 0, 0), 2);
        /*if ( display ) {
        	cv::String winName("AOGDetection");
        	cv::imshow(winName, img);
        	cv::waitKey(0);
        }*/
    }

    cv::rectangle(img, rootNode()->parseInfo(this)->cvRect(), cv::Scalar::all(255), 5);
    cv::rectangle(img, rootNode()->parseInfo(this)->cvRect(), cv::Scalar(0, 0, 255), 3);

    if ( display ) {
        cv::String winName("AOGDetection");
        cv::imshow(winName, img);
        cv::waitKey(0);
    }
}
Ejemplo n.º 2
0
std::vector<const PtNode *> ParseTree::findSingleObjAndNodes() const
{
    const ParseTree &pt(*this);

    std::vector<const PtNode *> sobj;

    for ( int i = 0; i < nodeSet().size(); ++i ) {
        const PtNode * n = nodeSet()[i];
        if ( n->idx()[PtNode::IDX_TYPE] != static_cast<int>(Node::T_NODE) )
            continue;

        // Bottom-up: tnode -> and-node -> or-node -> single obj and-node
        const PtNode * a1 = n->inEdge(0, pt)->fromNode(pt);
        const PtNode * o  = a1->inEdge(0, pt)->fromNode(pt);
        const PtNode * a2 = o->inEdge(0, pt)->fromNode(pt);

        if ( a2->idx()[PtNode::IDX_VALID] <= 0 )
            continue;

        bool found = false;
        for ( int j = 0; j < sobj.size(); ++j ) {
            if ( a2 == sobj[j] ) {
                found = true;
                break;
            }
        }
        if ( !found ) {
            sobj.push_back(a2);
        }
    }

    return sobj;
}
Ejemplo n.º 3
0
std::vector<PtNode *> ParseTree::getNode(const int idxG)
{
    std::vector<PtNode *> n;

    for ( int i = 0; i < nodeSet().size(); ++i ) {
        if ( nodeSet()[i]->idx()[PtNode::IDX_G] == idxG ) {
            n.push_back(getNodeSet()[i]);
        }
    }

    return n;
}
Ejemplo n.º 4
0
int ParseTree::addNode(int gNode, int type)
{
    int idx = nodeSet().size();

//    for ( int i = 0; i < idx; ++i ) {
//        if ( nodeSet()[i]->idx()[PtNode::IDX_G] == gNode ) {
//            RGM_LOG(error, "duplicated pt node" );
//            return -1;
//        }
//    }

    getNodeSet().push_back( new PtNode(gNode) );

    getNodeSet().back()->getIdx()[PtNode::IDX_MYSELF] = idx;
    getNodeSet().back()->getIdx()[PtNode::IDX_TYPE] = type;

    return idx;
}
bool
CPatcherAppConfig::LoadConfig( const CORE::CDataNode& treeroot )
{GUCEF_TRACE;

    CORE::CDataNode::TConstDataNodeSet configNodes( treeroot.FindChildrenOfType( "PatcherAppConfig", true ) );
    CORE::CDataNode::TConstDataNodeSet::iterator i = configNodes.begin();
    if ( i != configNodes.end() )
    {
        const CORE::CDataNode* configNode = (*i);

        CORE::CString value = configNode->GetAttributeValueOrChildValueByName( "LogFilePath" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_logfilePath = value;
        }
        value = configNode->GetAttributeValueOrChildValueByName( "IsFileLoggerEnabled" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_isFileLoggerEnabled = CORE::StringToBool( value );
        }
        value = configNode->GetAttributeValueOrChildValueByName( "IsConsoleLoggerEnabled" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_isConsoleLoggerEnabled = CORE::StringToBool( value );
        }
        value = configNode->GetAttributeValueOrChildValueByName( "IsConsoleWindowEnabled" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_isConsoleWindowEnabled = CORE::StringToBool( value );
        }

        value = configNode->GetAttributeValueOrChildValueByName( "WindowManager" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_windowManagerName = value;
        }

        CORE::CDataNode::TConstDataNodeSet nodeSet( configNode->FindChildrenOfType( "InitialForm", true ) );
        CORE::CDataNode::TConstDataNodeSet::iterator n = nodeSet.begin();
        if ( n != nodeSet.end() )
        {
            const CORE::CDataNode* formInfoNode = (*n);

            m_guiBackendName = formInfoNode->GetAttributeValueOrChildValueByName( "GuiBackend" );
            if ( !m_guiBackendName.IsNULLOrEmpty() )
            {
                m_initialFormTypeName = formInfoNode->GetChildValueByName( "FormTypeName" );
                m_initialFormResourcePath = formInfoNode->GetChildValueByName( "FormResource" );
            }
        }

        nodeSet = configNode->FindChildrenOfType( "FontsToLoadFromAssets", true );
        n = nodeSet.begin();
        while ( n != nodeSet.end() )
        {
            const CORE::CDataNode* fontInfoNode = (*n);
            CString fontAsset = fontInfoNode->GetAttributeValueOrChildValueByName( "FontAsset" );
            if ( !fontAsset.IsNULLOrEmpty() )
            {
                m_fontAssetsToLoad.push_back( fontAsset );
            }
            ++n;
        }

    }
    return true;
}
Ejemplo n.º 6
0
 /// Returns if a grammar is empty
 bool empty() const { return nodeSet().size() == 0; }
Ejemplo n.º 7
0
int ParseTree::compareFeatures(const ParseTree & pt) const
{
    assert(grammar() != NULL && grammar() == pt.grammar() );

    for ( int i = 0;  i < nodeSet().size(); ++i ) {
        int idxG = nodeSet()[i]->idx()(PtNode::IDX_G);

        int ii = 0;
        for ( ; ii < pt.nodeSet().size(); ++ii ) {
            int idxG1 = pt.nodeSet()[ii]->idx()(PtNode::IDX_G);
            if ( idxG1 == idxG ) {
                break;
            }
        } // for ii

        if ( ii == pt.nodeSet().size() ) {
            return 1;
        }

        for ( int j = PtNode::IDX_BIAS; j < PtNode::IDX_APP+1; ++j ) {
            int fidx  = nodeSet()[i]->idx()(j);
            int fidx1 = pt.nodeSet()[ii]->idx()(j);
            if (fidx != -1 && fidx1 != -1 ) {
                switch (j) {
                case PtNode::IDX_BIAS: {
                    if ( biasSet()[fidx] > pt.biasSet()[fidx1] ) {
                        return 1;
                    } else if ( biasSet()[fidx] < pt.biasSet()[fidx1] ) {
                        return -1;
                    }

                    break;
                }
                case PtNode::IDX_DEF: {
                    const Deformation::Param & p(*deformationSet()[fidx]);
                    const Deformation::Param & p1(*pt.deformationSet()[fidx1]);
                    for ( int k = 0; k < 4; ++k ) {
                        if ( p(k) > p1(k) ) {
                            return 1;
                        } else if (p(k) < p1(k)) {
                            return -1;
                        }
                    }
                    break;
                }
                case PtNode::IDX_SCALEPRIOR: {
                    const Scaleprior::Param & p(*scalepriorSet()[fidx]);
                    const Scaleprior::Param & p1(*pt.scalepriorSet()[fidx1]);
                    for ( int k = 0; k < 3; ++k ) {
                        if ( p(k) > p1(k) ) {
                            return 1;
                        } else if (p(k) < p1(k)) {
                            return -1;
                        }
                    }
                    break;
                }
                case PtNode::IDX_APP: {
                    const Appearance::Param & p(*appearanceSet()[fidx]);
                    const Appearance::Param & p1(*pt.appearanceSet()[fidx1]);
                    for ( int row=0; row < p.rows(); ++ row )
                        for ( int col=0; col < p.cols(); ++col )
                            for ( int k = 0; k < FeaturePyramid::NbFeatures; ++k ) {
                                if ( p(row, col)(k) > p1(row, col)(k) ) {
                                    return 1;
                                } else if (p(row, col)(k) < p1(row, col)(k)) {
                                    return -1;
                                }
                            }
                    break;
                }
                }
            } else {
                if (fidx != -1 && fidx1 == -1) {
                    return 1;
                }

                if (fidx == -1 && fidx1 != -1) {
                    return -1;
                }
            }
        }

    } // for i

    return 0;
}
Ejemplo n.º 8
0
const PtNode * ParseTree::rootNode() const
{
    return nodeSet()[idxRootNode()];
}
Ejemplo n.º 9
0
bool ParseTree::empty() const
{
    return nodeSet().size() == 0;
}