void DiscardFaceDetectorShapes (vec_SHAPE &Shapes, // io: updated vec_string &Tags, // io: updated bool fDiscardUnderscores) { unsigned iShape1 = 0; unsigned nShapes = Tags.size(); ASSERT(Shapes.size() == nShapes); for (unsigned iShape = 0; iShape < nShapes; iShape++) { const char *sTag = Tags[iShape].c_str(); // tag string should be of the form: "1234 filename" or "12345678 filename" if (sTag[4] != ' ' && sTag[8] != ' ') Err("malformed tag \"%s\"", sTag); unsigned Attr; if (1 == sscanf(sTag, "%x", &Attr) && !((Attr & FA_ViolaJones) || (Attr & FA_Rowley)) && // not a face detector shape (!fDiscardUnderscores || sGetBasenameFromTag(sTag)[0] != '_')) { Shapes[iShape1].assign(Shapes[iShape]); Tags[iShape1] = Tags[iShape]; iShape1++; } } if (nShapes - iShape1) lprintf("Ignored %d face detector%s shape%s\n", nShapes - iShape1, (fDiscardUnderscores? " and underscore": ""), (nShapes - iShape1 == 1? "": "s")); Shapes.resize(iShape1); Tags.resize(iShape1); }
vec_string& GetCPPFILES() { static vec_string vCPP; vCPP.push_back("cpp"); vCPP.push_back("c"); vCPP.push_back("cxx"); return vCPP; }
//----------------------------------------------------------------------------- static void ShowFirstFewShapes (const vec_string &Tags) // in { if (Tags.size() == 0) lprintf("No shapes"); else { lprintf("First few shapes are "); unsigned iShape; for (iShape = 0; iShape < MIN(5, Tags.size()); iShape++) lprintf("%s ", sGetBase(sGetBasenameFromTag(Tags[iShape]))); if (iShape < Tags.size()) lprintf("..."); lprintf("\n"); } }
void GetHeaderFileIn(const string &str, vec_string &v) { try { string::size_type pos = str.find("#"); if (string::npos == pos) { return; } pos = str.find("include", pos + 1); if (string::npos == pos) { return; } pos = str.find("\"", pos + 7); if (string::npos == pos) { return; } string::size_type posEnd = str.find("\"", pos + 1); if (string::npos == posEnd) { return; } v.push_back(str.substr(pos + 1, posEnd - pos - 1)); } catch (exception) { } }
void GetCurrDirFiles(vec_string &v) { DIR *dirp; struct dirent *dp; if ((dirp = opendir(".")) != NULL) { while ((dp = readdir(dirp)) != NULL) { v.push_back(dp->d_name); } closedir(dirp); } }
void GetCurrDirFiles(vec_string &v) { enum { SZ_SIZE = 1024 }; char szBuff[SZ_SIZE + 1]; GetCurrentDirectory(SZ_SIZE, szBuff); string str = szBuff; str += "\\*"; WIN32_FIND_DATA wfd = {0}; HANDLE h = FindFirstFile(str.c_str(), &wfd); while (FindNextFile(h, &wfd)) { v.push_back(wfd.cFileName); } FindClose(h); }
//----------------------------------------------------------------------------- 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); }
//----------------------------------------------------------------------------- static int iGetRefShapeIndex1 (const vec_string &Tags, unsigned Mask0, unsigned Mask1, const char sFile[]) // in: for error reporting { for (unsigned iShape = 0; iShape < Tags.size(); iShape++) { const char *sTag = Tags[iShape].c_str(); if (!sTag || sTag[0] == 0) Err("GetRefShapeIndex: shape index %d in %s does not have a tag", iShape, sFile); unsigned Tag; if (sTag[4] != ' ' && sTag[8] != ' ') Err("GetRefShapeIndex: tag %s in %s is malformed", sTag, sFile); if (1 != sscanf(sTag, "%x", &Tag)) Err("GetRefShapeIndex: tag %s in %s is not a hex number", sTag, sFile); if (fMatchAttr(Tag, Mask0, Mask1)) return iShape; // found it } return -1; // not found }
static void SelectNShapes ( vec_SHAPE &Shapes, // io vec_string &Tags, // io: also shuffled, in step with Shapes int nWantedShapes, // in: 0 means return all shapes int nSeed=0) // in: 0 means no random selection; if any other // val select randomly with rand seed=nSeed { unsigned nShapes = Tags.size(); if (nWantedShapes == 0) nWantedShapes = nShapes; nWantedShapes = MIN((unsigned)nWantedShapes, nShapes); if (nSeed) { // generate a shuffled set of indices in iShuffledShapes vec_int iShuffledShapes(nShapes); unsigned iShape; for (iShape = 0; iShape < nShapes; iShape++) iShuffledShapes[iShape] = iShape; SeedRand(nSeed); // We use our own random shuffle here because different compilers // give different results which messes up regression testing. // (I think only Visual C 6.0 is incompatible with everyone else?) // // Following code is equivalent to // random_shuffle(iShuffledShapes.begin(), iShuffledShapes.end(), // pointer_to_unary_function<int,int>(Rand)); vec_int::iterator pNext = iShuffledShapes.begin(); for (int i = 2; ++pNext != iShuffledShapes.end(); ++i) iter_swap(pNext, iShuffledShapes.begin() + Rand(i)); iShuffledShapes.resize(nWantedShapes); // sort the selected indices so we can do an in-place replacement in Shapes sort(iShuffledShapes.begin(), iShuffledShapes.end()); // keep the first nWantedShapes in iShuffledShapes for (iShape = 0; iShape < unsigned(nWantedShapes); iShape++) { unsigned iOldShape = iShuffledShapes[iShape]; if (iShape > 0 && Shapes[0].nrows() != Shapes[iOldShape].nrows()) { static bool fIssuedWarning; if (!fIssuedWarning) { fIssuedWarning = true; WarnWithNewLine("different sized shapes (%s has %d rows, %s has %d rows)\n", sGetBasenameFromTag(Tags[0].c_str()), Shapes[0].nrows(), sGetBasenameFromTag(Tags[iOldShape].c_str()), Shapes[iOldShape].nrows()); } } Shapes[iShape].assign(Shapes[iOldShape]); Tags[iShape] = Tags[iOldShape]; } } Shapes.resize(nWantedShapes); Tags.resize(nWantedShapes); }