void CascadeClassifierNavigationPlayer::onEnter()
{
    if (m_classifier) {
        return;
    }

    QFile f(":/assets/lbpcascade_animeface.xml");
    if (!f.open(QIODevice::ReadOnly)) {
        qWarning("Fail to load cascade classifier");
        return;
    }

    QByteArray content = f.readAll();
    cv::FileStorage cvFile(content.toStdString(), cv::FileStorage::READ | cv::FileStorage::MEMORY);
    if (!cvFile.isOpened()) {
        qWarning("Fail to load cascade classifier as cv::FileStorage");
        return;
    }

    cv::CascadeClassifier *classifier = new cv::CascadeClassifier();
    if (!classifier->read(cvFile.getFirstTopLevelNode())) {
        qWarning("Fail to decode cascade classifer");
        delete classifier;
        return;
    }

    m_classifier = classifier;
}
示例#2
0
void doMiddle()
{
struct hash *cvHash = raReadAll((char *)cvFile(), CV_TERM);
struct hashCookie hc = hashFirst(cvHash);
struct hashEl *hEl;
struct slList *termList = NULL;
struct hash *ra;
int totalPrinted = 0;
boolean excludeDeprecated = (cgiOptionalString("deprecated") == NULL);

// Prepare an array of selected terms (if any)
int requestCount = 0;
char **requested = NULL;
char *requestVal = termOpt;
char *queryBy = CV_TERM;
if (tagOpt)
    {
    requestVal = tagOpt;
    queryBy = CV_TAG;
    }
else if (targetOpt)
    {
    requestVal = targetOpt;
    queryBy = CV_TERM;  // request target is special: lookup term, convert to target, display target
    }
else if (labelOpt)
    {
    requestVal = labelOpt;
    queryBy = CV_LABEL;
    }
if (requestVal)
    {
    (void)stripChar(requestVal,'\"');
    requestCount = chopCommas(requestVal,NULL);
    requested = needMem(requestCount * sizeof(char *));
    chopByChar(requestVal,',',requested,requestCount);
    }

char *org = NULL;
// if the org is specified in the type (eg. cell line)
// then use that for the org, otherwise use the command line option,
// otherwise use human.
char *type = findType(cvHash,requested,requestCount,&queryBy, &org, FALSE);
if (org == NULL)
    org = organismOptLower;
if (org == NULL)
    org = ORG_HUMAN;

// Special logic for requesting antibody by target
if (targetOpt && requestCount > 0 && sameWord(queryBy,CV_TERM) && sameWord(type,CV_TERM_ANTIBODY))
    {
    // Several antibodies may have same target.
    // requested target={antibody} and found antibody
    // Must now convert each of the requested terms to its target before displaying all targets
    char **targets = convertAntibodiesToTargets(cvHash,requested,requestCount);
    if (targets != NULL)
        {
        freeMem(requested);
        requested = targets;
        queryBy = CV_TARGET;
        }
    }
//warn("Query by: %s = '%s' type:%s",queryBy,requestVal?requestVal:"all",type);

// Get just the terms that match type and requested, then sort them
if (differentWord(type,CV_TOT) || typeOpt != NULL ) // If type resolves to typeOfTerm and
    {                                               // typeOfTerm was not requested,
    while ((hEl = hashNext(&hc)) != NULL)           // then just show definition
        {
        ra = (struct hash *)hEl->val;
        char *thisType = (char *)cvTermNormalized(hashMustFindVal(ra,CV_TYPE));
        if (differentWord(thisType,type) && (requested == NULL
        ||  differentWord(thisType,CV_TERM_CONTROL)))
            continue;
        // Skip all rows that do not match queryBy param if specified
        if (requested)
            {
            char *val = hashFindVal(ra, queryBy);
            if (val == NULL)
                {
                // Special case for input that has no target
                if (sameString(queryBy, CV_TARGET))
                    val = hashMustFindVal(ra, CV_TERM);
                else
                    continue;
                }
            if (-1 == stringArrayIx(val,requested,requestCount))
                continue;
            }
        else if (excludeDeprecated)
            {
            if (hashFindVal(ra, "deprecated") != NULL)
                continue;
            }
        slAddTail(&termList, ra);
        }
    }
slSort(&termList, termCmp);

boolean described = doTypeDefinition(type,FALSE,(slCount(termList) == 0));
boolean sortable = (slCount(termList) > 5);
if (sortable)
    {
    webIncludeResourceFile("HGStyle.css");
    jsIncludeFile("jquery.js",NULL);
    jsIncludeFile("utils.js",NULL);
    printf("<TABLE class='sortable' border=1 CELLSPACING=0 style='border: 2px outset #006600; "
           "background-color:%s;'>\n",COLOR_BG_DEFAULT);
    }
else
    printf("<TABLE BORDER=1 BGCOLOR=%s CELLSPACING=0 CELLPADDING=2>\n",COLOR_BG_DEFAULT);
if (slCount(termList) > 0)
    {
    doTypeHeader(type, org,sortable);

    // Print out the terms
    while ((ra = slPopHead(&termList)) != NULL)
        {
        if (doTypeRow( ra, org ))
            totalPrinted++;
        }
    }
puts("</TBODY></TABLE><BR>");
if (sortable)
    jsInline("{$(document).ready(function() "
         "{sortTable.initialize($('table.sortable')[0],true,true);});}\n");
if (totalPrinted == 0)
    {
    if (!described)
        warn("Error: Unrecognised type (%s)\n", type);
    }
else if (totalPrinted > 1)
    printf("Total = %d\n", totalPrinted);
}