📄 mshapes.cpp
字号:
Fprintf(pgOut, "0 0\n"); // 60 Fprintf(pgOut, "0 0\n"); // 61 Fprintf(pgOut, "0 0\n"); // 62 Fprintf(pgOut, "0 0\n"); // 63 Fprintf(pgOut, "0 0\n"); // 64 Fprintf(pgOut, "0 0\n"); // 65 Fprintf(pgOut, "0 0\n"); // 66 Fprintf(pgOut, "%g %g\n", MamX(M_NoseTip), MamY(M_NoseTip)); // Nose 67 Fprintf(pgOut, "}\n"); iMat++; } }lprintf("%d shapes\n", nShapes);fclose(pFile);}//-----------------------------------------------------------------------------static void DoBioid (void){#define BioidX(x) ((x) - 384 / 2)#define BioidY(y) (286 / 2 - (y))Fprintf(pgOut, "#-- %s ------------------------------------------------------------\n", "rowley/bioid.cpp");lprintf("Reading Bioid shapes from rowley/bioid.cpp ");int nShapes = 0;for (int i = 0; i < N_BDATA; i++) { const tBData *p = &gBData[i]; nShapes++; ngShapes++; Fprintf(pgOut, "\"%4.4x %s.pgm\"\n", p->Attributes, p->sName); Fprintf(pgOut, "{ 20 2\n"); Fprintf(pgOut, "%g %g\n", BioidX(p->xrEye), BioidY(p->yrEye)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlEye), BioidY(p->ylEye)); Fprintf(pgOut, "%g %g\n", BioidX(p->xrMouth), BioidY(p->yrMouth)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlMouth), BioidY(p->ylMouth)); Fprintf(pgOut, "%g %g\n", BioidX(p->xrBrowOut), BioidY(p->yrBrowOut)); Fprintf(pgOut, "%g %g\n", BioidX(p->xrBrowIn), BioidY(p->yrBrowIn)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlBrowOut), BioidY(p->ylBrowOut)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlBrowIn), BioidY(p->ylBrowIn)); Fprintf(pgOut, "%g %g\n", BioidX(p->xrTemple), BioidY(p->yrTemple)); // no corresponding internal landmark, but include anyway Fprintf(pgOut, "%g %g\n", BioidX(p->xrEyeOut), BioidY(p->yrEyeOut)); Fprintf(pgOut, "%g %g\n", BioidX(p->xrEyeIn), BioidY(p->yrEyeIn)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlEyeIn), BioidY(p->ylEyeIn)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlEyeOut), BioidY(p->ylEyeOut)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlTemple), BioidY(p->ylTemple)); // no corresponding internal landmark, but include anyway Fprintf(pgOut, "%g %g\n", BioidX(p->xNose), BioidY(p->yNose)); Fprintf(pgOut, "%g %g\n", BioidX(p->xrNostril), BioidY(p->yrNostril)); Fprintf(pgOut, "%g %g\n", BioidX(p->xlNostril), BioidY(p->ylNostril)); Fprintf(pgOut, "%g %g\n", BioidX(p->xLipUp), BioidY(p->yLipUp)); Fprintf(pgOut, "%g %g\n", BioidX(p->xLipLow), BioidY(p->yLipLow)); Fprintf(pgOut, "%g %g\n", BioidX(p->xChin), BioidY(p->yChin)); Fprintf(pgOut, "}\n"); }lprintf("%d shapes\n", nShapes);}//-----------------------------------------------------------------------------#define nnX(x) (double)((x) - Img.width / 2)#define nnY(y) (double)(Img.height / 2 - (y))static void DoNn (void){tFaceEyeLocation *pLocations;int iFaces, iImage = 0;char sNet0[FLEN], sNet1[FLEN], sNet2[FLEN], sNet3[FLEN], sNetEye[FLEN];strcpy(sNet0, "face17c");strcpy(sNet1, "face18c");strcpy(sNet2, "face19c");strcpy(sNet3, "face20c");strcpy(sNetEye, "eye");char sPath[SLEN];sprintf(sPath, "%s/%s", CONF_sNnImageDir, "*.pgm");GetFileNamesIntoGlobalFileArray(sPath);lprintf("Neural net search on %d files in %s\n", ngFiles, sPath);Fprintf(pgOut, "#-- Landmarks located using neural net ------------------------------------\n");lprintf("TrackFindNet: umec ");lprintf("Net0:%s Net1:%s Net2:%s Net3:%s NetEye:%s\n", sNet0, sNet1, sNet2, sNet3, sNetEye);while (iImage < ngFiles && !fgUserInt) { ngShapes++; Image Img; sprintf(sPath, "%s/%s", CONF_sNnImageDir, sgFiles[iImage]);#if CONF_fWriteNnImages RgbImage RgbImg; sLoadImage(&Img, &RgbImg, sPath, QUIET);#else sLoadImage(Img, sPath, QUIET);#endif iFaces = Track_FindAllFaces(&pLocations, Img, VERBOSE); lprintf("%d%% %d: %s ", (int)((iImage * 100 + 0.5)/ngFiles), iImage, sPath); int nEyes = 0; if (iFaces) nEyes = pLocations[0].LeftFlag + pLocations[0].RightFlag; lprintf("%d face%s %d eye%s ", iFaces, (iFaces == 1? "":"s"), nEyes, ((nEyes == 1)? "" :"s")); char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; _splitpath(sPath, drive, dir, fname, ext); if (iFaces != 1) { lprintf("SKIPPED didn't find exactly one face"); Fprintf(pgOut, "# %s%s SKIPPED didn't find exactly one face\n", fname, ext); } else if (pLocations[0].LeftFlag != 1 || pLocations[0].RightFlag != 1) { lprintf("SKIPPED didn't find two eyes"); Fprintf(pgOut, "# %s%s SKIPPED didn't find two eyes\n", fname, ext); } else { Fprintf(pgOut, "\"%4.4x %s%s\"\n", FA_Rowley, fname, ext); // FA_Rowley 2000 means landmarks located using neural net Fprintf(pgOut, "{ "); Fprintf(pgOut, "%d 2\n", NBR_ROWLEY_POINTS); Fprintf(pgOut, "%g %g\n", nnX(pLocations[0].x1), nnY(pLocations[0].y1)); // 00 NN_BottomLeft Fprintf(pgOut, "%g %g\n", nnX(pLocations[0].x2), nnY(pLocations[0].y2)); // 01 NN_TopRight Fprintf(pgOut, "%g %g\n", nnX(pLocations[0].xRightEye), nnY(pLocations[0].yRightEye)); // 02 NN_LEye Fprintf(pgOut, "%g %g\n", nnX(pLocations[0].xLeftEye), nnY(pLocations[0].yLeftEye)); // 03 NN_REye Fprintf(pgOut, "}\n"); fflush(pgOut);#if CONF_fWriteNnImages DrawNnResult(RgbImg, pLocations[0]);#endif } free(pLocations);#if CONF_fWriteNnImages char sDrive[_MAX_DRIVE], sDir[_MAX_DIR], sFname[_MAX_FNAME], sExt[_MAX_EXT], sOutPath[SLEN]; _splitpath(sgFiles[iImage], sDrive, sDir, sFname, sExt); sprintf(sOutPath, "out/%s.bmp", sFname); WriteBmp(RgbImg, sOutPath, true);#else lprintf("\n");#endif iImage++; }if (iImage >= 0) iImage--;lprintf("%d image%s\n", iImage, (iImage == 1? "": "s"));}//-----------------------------------------------------------------------------int __cdecl main (int argc, const char *argv[]){bool fIndexOnly = false, fSkipMam = true /*TODO*/, fSkipNn = false, fMerge = false, fOutFileSpecifed = false;bool fSkipBioId = false;InitMallocDebug();while (--argc > 0 && (*++argv)[0] == '-') // command line arguments: masm [flags] { switch (*(*argv + 1)) { case 'o': // output file argv++; argc--; if (argc < 1) { printf("-o needs an argument. Use mshapes -? for help.\n"); exit(-1); } strcpy(sgOutFile, *argv); fOutFileSpecifed = true; break; case 'm': // merge fMerge = true; argv++; argc--; if (argc < 1) { printf("-m needs an argument. Use mshapes -? for help.\n"); exit(-1); } strcpy(sgMergeFile, *argv); break; case 'p': argv++; argc--; if (argc < 1) { printf("-p needs an argument. Use mshapes -? for help.\n"); exit(-1); } strcpy(sgTagRegExp, *argv); break; case 'I': // rebuild index fIndexOnly = true; break; case 'M': // skip MAM fSkipMam = true; break; case 'N': // skip NN fSkipNn = true; break; case 'B': // skip BioId fSkipBioId = true; break; default: printf(sgUsage, sgOutFile, CONF_sMamFilename, CONF_sNnImageDir); exit(-1); } }if (argc != 1) { printf("No input file specified. Use mshapes -? for help.\n"); exit(-1); }strcpy(sgInFile, *argv);char sDrive[_MAX_DRIVE], sDir[_MAX_DIR], sFname[_MAX_FNAME], sExt[_MAX_EXT]; // get index file nameif (fIndexOnly) { if (fMerge) lprintf("-I flag used so ignoring -m flag\n"); if (fOutFileSpecifed) lprintf("-I flag used so ignoring -o flag\n");#if 0 // currently fSkipMam is always enabled if (fSkipMam) lprintf("-I flag used so ignoring -M flag\n");#endif if (fSkipNn) lprintf("-I flag used so ignoring -N flag\n"); _splitpath(sgInFile, sDrive, sDir, sFname, sExt); strcpy(sgOutFile, sgInFile); }else _splitpath(sgOutFile, sDrive, sDir, sFname, sExt);_makepath(sgOutIndexFile, sDrive, sDir, sFname, "index");Init(VERBOSE, false, "mshapes.log");if (fIndexOnly) lprintf("\n");else { if (0 == stricmp(sgInFile, sgMergeFile) || 0 == stricmp(sgInFile, sgOutFile)) { printf("Can't have same name for input IN.shape %s and OUT.shape %s or UP.shape %s\n", sgInFile, sgOutFile, sgMergeFile); exit(-1); } lprintf("\nBuilding %s\n", sgOutFile); pgOut = Fopen(sgOutFile, "w"); time_t ltime; time(<ime); char *sTime = ctime(<ime); sTime[strlen(sTime)-1] = 0; // remove \n Fprintf(pgOut, "# %s: built by mshapes.exe [%s]\n", sgOutFile, sTime); if (fMerge) Merge(); else { DoM2(); if (fSkipMam) { lprintf("Skipping MAM!\n"); Fprintf(pgOut, "#--- Skipping MAM -----\n"); } else DoMam(); if (fSkipBioId) { lprintf("Skipping BioId!\n"); Fprintf(pgOut, "#--- Skipping BioId -----\n"); } else DoBioid(); if (fSkipNn) { lprintf("Skipping NN!\n"); Fprintf(pgOut, "#--- Skipping NN -----\n"); } else DoNn(); } fclose(pgOut); lprintf("Built %s, %d shapes in total\n", sgOutFile, ngShapes); }BuildMatIndexFile(sgOutFile, sgOutIndexFile, VERBOSE);Shutdown();return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -