Пример #1
0
//-----------------------------------------------------------------------------
void ReadSelectedShapes (
        vec_SHAPE &Shapes,              // out:
        vec_string &Tags,               // out:
        char sImageDirs[],              // out:
        const char sShapeFile[],        // in:
        int nMaxShapes,                 // in: nbr of wanted shapes, 0 for all
        const char sTagRegex[],         // in: only read matrices whose tag
                                        //     matches this regular expression
        unsigned Mask0, unsigned Mask1) // in: only read matrices where
                                        //     Attr&Mask0 == Mask1
                                        //     (Attr is hex part of tag string)
{
ReadShapeFile(Shapes, Tags, sImageDirs, sTagRegex, Mask0, Mask1, sShapeFile);

DiscardFaceDetectorShapes(Shapes, Tags);

unsigned nShapes = Tags.size();
if (nShapes == 0)
    Err("no shapes");
if (unsigned(nMaxShapes) > nShapes)
    {
    lprintf("\n");
    ShowFirstFewShapes(Tags);
    Err("want %d shapes but there are only %d shapes", nMaxShapes, nShapes);
    }
if (nMaxShapes != 0)
    {
    SelectNShapes(Shapes, Tags, nMaxShapes, CONF_nSeed_SelectShapes);
    if (CONF_nSeed_SelectShapes)
        lprintf("Selected a random sample of %d shape%s from %d shape%s (seed=%d)\n",
            nMaxShapes, ((nMaxShapes==1)? "":"s"),
            nShapes, ((nShapes==1)? "":"s"), CONF_nSeed_SelectShapes);
    else
        lprintf("Selected the first %d shape%s of %d shape%s\n",
            nMaxShapes, ((nMaxShapes==1)? "":"s"),
            nShapes, ((nShapes==1)? "":"s"));
    }
else
    lprintf("Read %d shape%s\n", nShapes, ((nShapes==1)? "":"s"));

ShowFirstFewShapes(Tags);
}
Пример #2
0
StasmMat FindMatInFile (const char sFile[],  // in
                   char *psImageDirs[], // out: directories in shape file if any, optional
                   const char sRegex[], // in: can be null
                   unsigned Mask0,      // in
                   unsigned Mask1)      // in
{
static char       sFile1[SLEN]; // the mat file name
static char       sImageDirs[SLEN];
static vec_Mat    MatV;         // the matrices read in from the file
static vec_string Tags;         // the tags (i.e. string before each mat in the file)
static vec_int    TagInts;      // hex number at start of each of above tags

// iMat is static so we start where we finished last time, which means that
// searches are fast if this function is invoked for matrices in order
// It also means with multiple matches to sRegex, succesive matching shapes
// are returned each time this function is called.

static unsigned iMat;

if (strcmp(sFile, sFile1))  // first time (for this file)?
    {
    // initialize the static variables

    strcpy(sFile1, sFile);
    iMat = 0;
    // read all shapes, we will filter the one we want later
    ReadShapeFile(MatV, Tags, sImageDirs, NULL, 0, 0, sFile);
    TagInts.resize(MatV.size());
    for (size_t i = 0; i < MatV.size(); i++)
        {
        char const *s = Tags[i].c_str();
        unsigned n;
        if (1 != sscanf(s, "%x", &n))
            Err("can't convert tag %s in %s to a hex number", s, sFile);
        TagInts[i] = n;
        }
    }
// regcomp flags: egrep style expression (supports |),
// ignore case, use simple failure reporting in regexec

// regex_t CompiledRegex;
// if (0 != regcomp(&CompiledRegex, sRegex, REG_EXTENDED|REG_ICASE|REG_NOSUB))
    // Err("invalid regular expression %s", sRegex);

size_t i;
for (i = 0; i < MatV.size(); i++)
    {
    if (fMatchAttr(TagInts[iMat], Mask0, Mask1))
	    // && // filter first on attributes
        // fRegexMatch(CompiledRegex, sGetBasenameFromTag(Tags[iMat])))
        {
        break;                  // found
        }
    iMat++;
    if (iMat >= MatV.size())
        iMat = 0;               // wrap
    }
// regfree(&CompiledRegex);

if (psImageDirs)
    *psImageDirs = sImageDirs;

StasmMat m;                          // returned matrix
if (i < MatV.size())            // found?
    m = MatV[iMat];

return m;
}