📄 atland.cpp
字号:
} else if (!fPointUsed(Shape, MREye0) && !fPointUsed(Shape, MLEye0)) ; else SysErr("fConvertShapeToInternalFormat: synthesizing points"); }return fChanged;}//-----------------------------------------------------------------------------void DiscardGlobalFaceDetectorShapes (ShapeVec *pShapes, StringVec &TagStrings, // io bool fDiscardUnderscores) // in{int iShape1 = 0;int nShapes = TagStrings.size();DASSERT(pShapes == NULL || pShapes->size() == nShapes);for (int iShape = 0; iShape < nShapes && !fgErr; iShape++) { if ((TagStrings[iShape][0] != '2') && // FA_Rowley (TagStrings[iShape][0] != '1') && // FA_ViolaJones (!fDiscardUnderscores || TagStrings[iShape][FNAME_OFFSET] != '_')) { if (iShape != iShape1) // for efficiency { if (pShapes) (*pShapes)[iShape1].assign((*pShapes)[iShape]); TagStrings[iShape1] = TagStrings[iShape]; } iShape1++; } }if (nShapes - iShape1) lprintf("Ignored %d global face detector%s shape%s\n", nShapes - iShape1, (fDiscardUnderscores? " and underscore": ""), (nShapes - iShape1 == 1? "": "s"));if (pShapes) pShapes->resize(iShape1);TagStrings.resize(iShape1);}//-----------------------------------------------------------------------------void ConvertShapeFromInternalFormat (Mat &Shape, // out: file format const Mat &InShape, const char *sShape, int nWantedPoints) // in: internal format{#if CONF_nGenLandmarksUsedInternally != 0char cFirstCharOfFname = sShape[FNAME_OFFSET]; // use the file name to determine formatint iPoint;if (nWantedPoints != CONF_nGenLandmarksUsedInternally) { static bool fWarned = false; // prevent a stream of warnings if (!fWarned) { Warn("nWantedPoints %d != CONF_nGenLandmarksUsedInternally %d", nWantedPoints, CONF_nGenLandmarksUsedInternally); fWarned = true; } }switch (cFirstCharOfFname) { case 'm': // XM2VTS { int nUsed = nUsedLandmarks(InShape); if (nUsed != InShape.nrows()) { static bool fWarned = false; // prevent a stream of warnings if (!fWarned) { Warn("nUsedLandmarks %d != InShape.nrows() %d", nUsed, InShape.nrows()); fWarned = true; } } Shape.dimClear(InShape.nrows(), 2); Shape = InShape; Shape.dimKeep(nWantedPoints, 2); break; } case 'B': // BioId case 'a': // AR, same as BioId Shape.dimClear(CONF_nPointsBioid22, 2); for (iPoint = 0; iPoint < CONF_nPoints88; iPoint++) { int iNewPoint = igTransBioId[iPoint]; if (iNewPoint >= 0) { DASSERT(iNewPoint < CONF_nPointsBioid22); Shape(iNewPoint, VX) = InShape(iPoint, VX); Shape(iNewPoint, VY) = InShape(iPoint, VY); } } break; default: SysErr("ConvertShapeFromInternalFormat unrecognized name %s", sShape); break; }#else // CONF_nGenLandmarksUsedInternally == 0Shape.assign(InShape);#endif // CONF_nGenLandmarksUsedInternally}//-----------------------------------------------------------------------------int nUsedLandmarks (const Mat &Shape){int nPoints = Shape.nrows(), nUsed = 0;for (int iPoint = 0; iPoint < nPoints; iPoint++) if (fPointUsed(Shape, iPoint)) nUsed++;return nUsed;}//-----------------------------------------------------------------------------void CheckHasAllLandmarks (const Mat &Shape){ASSERT(nUsedLandmarks(Shape) == Shape.nrows());}//-----------------------------------------------------------------------------// Generate a bitmap which shows some attributes of the data in the landmark table// For debugging.#if CONF_fShowDebugImagesvoid ShowLandmarkTab (const Mat &Shape, const char sFname[], const char sImageDirs[]){#define IMAGE_SCALE 2#define NSHADES 4 // using a number of different shades help you see which line is whichchar sOutPath[SLEN];SHAPE ScaledShape = IMAGE_SCALE * Shape;// show mustache, beard, glassessprintf(sOutPath, "%s/landmarks.bmp", CONF_sOutDir);lprintf("%s ", sOutPath);Image Img; RgbImage RgbImg;sLoadImageGivenDirs(Img, sImageDirs, sFname);ScaleImage(Img, IMAGE_SCALE * Img.width, IMAGE_SCALE * Img.height, QUIET, IM_NEAREST_PIXEL);ConvertGrayImageToRgb(RgbImg, Img);CropRgbImageSoWidthIsDivisbleBy4(RgbImg); // this is unfortunately needed for RgbPrintfint nrows = ScaledShape.nrows();for (int iPoint = 0; iPoint < nrows; iPoint++) if (fPointUsed(ScaledShape, iPoint)) { unsigned Bits = (gLandTabAll[iPoint].Bits & (FA_Glasses|FA_Beard|FA_Mustache)); int ix = Img.width/2 + ScaledShape(iPoint, VX) + 2; int iy = Img.height/2 - ScaledShape(iPoint, VY) - 6; RgbPrintf(RgbImg, ix, iy, C_YELLOW, 80, "%s", sGetAtFaceString(Bits, true)); }DrawShape(RgbImg, ScaledShape, C_RED, 1.0, IM_NO_CONNECT_DOTS, IM_NO_ANNOTATE, IM_NO_WHISKERS, 0, IM_NO_TRANSPARENT);CropImageToFace(RgbImg, Shape, IMAGE_SCALE);RgbPrintf(RgbImg, 8, 3, C_YELLOW, 120, "Landmark attributes");WriteBmp(RgbImg, sOutPath);// draw lines to partner pointsif (nrows >= MNoseTip) { sprintf(sOutPath, "%s/partners.bmp", CONF_sOutDir); lprintf("%s ", sOutPath); sLoadImageGivenDirs(Img, sImageDirs, sFname); ScaleImage(Img, IMAGE_SCALE * Img.width, IMAGE_SCALE * Img.height, QUIET, IM_NEAREST_PIXEL); ConvertGrayImageToRgb(RgbImg, Img); CropRgbImageSoWidthIsDivisbleBy4(RgbImg); // this is unfortunately needed for RgbPrintf for (iPoint = 0; iPoint < nrows; iPoint++) if (fPointUsed(ScaledShape, iPoint)) { int iPartner = gLandTabAll[iPoint].iPartner; if (iPartner >= 0 && iPartner > iPoint) { byte Gray = (127/(NSHADES-1) * (iPoint % NSHADES)); int ix = iRound(ScaledShape(iPoint, VX)); int iy = iRound(ScaledShape(iPoint, VY)); int ix1 = iRound(ScaledShape(iPartner, VX)); int iy1 = iRound(ScaledShape(iPartner, VY)); BresenhamDrawLine(RgbImg, 127+Gray, 127+Gray, Gray, ix, iy, ix1, iy1); } } DrawShape(RgbImg, ScaledShape, C_RED, 1.0, IM_NO_CONNECT_DOTS, IM_NO_ANNOTATE, IM_NO_WHISKERS, 0, IM_NO_TRANSPARENT, NULL, NULL, IM_DRAW_CIRCLES); CropImageToFace(RgbImg, Shape, IMAGE_SCALE); RgbPrintf(RgbImg, 8, 3, C_YELLOW, 120, "Partners"); WriteBmp(RgbImg, sOutPath); // draw lines to partner points, moving backwards sprintf(sOutPath, "%s/partnersReverse.bmp", CONF_sOutDir); lprintf("%s ", sOutPath); sLoadImageGivenDirs(Img, sImageDirs, sFname); ScaleImage(Img, IMAGE_SCALE * Img.width, IMAGE_SCALE * Img.height, QUIET, IM_NEAREST_PIXEL); ConvertGrayImageToRgb(RgbImg, Img); CropRgbImageSoWidthIsDivisbleBy4(RgbImg); // this is unfortunately needed for RgbPrintf for (iPoint = nrows-1; iPoint >= 0; iPoint--) if (fPointUsed(ScaledShape, iPoint)) { int iPartner = gLandTabAll[iPoint].iPartner; if (iPartner >= 0 && iPartner < iPoint) { byte Gray = (127/(NSHADES-1) * (iPoint % NSHADES)); int ix = iRound(ScaledShape(iPoint, VX)); int iy = iRound(ScaledShape(iPoint, VY)); int ix1 = iRound(ScaledShape(iPartner, VX)); int iy1 = iRound(ScaledShape(iPartner, VY)); BresenhamDrawLine(RgbImg, 127+Gray, 127+Gray, Gray, ix, iy, ix1, iy1); } } DrawShape(RgbImg, ScaledShape, C_RED, 1.0, IM_NO_CONNECT_DOTS, IM_NO_ANNOTATE, IM_NO_WHISKERS, 0, IM_NO_TRANSPARENT, NULL, NULL, IM_DRAW_CIRCLES); CropImageToFace(RgbImg, Shape, IMAGE_SCALE); RgbPrintf(RgbImg, 8, 3, C_YELLOW, 120, "Partners (reverse)"); WriteBmp(RgbImg, sOutPath); }// show whiskers (helps you see if iPrev and iNext are correct)sprintf(sOutPath, "%s/whiskers.bmp", CONF_sOutDir);lprintf("%s ", sOutPath);sLoadImageGivenDirs(Img, sImageDirs, sFname);ScaleImage(Img, IMAGE_SCALE * Img.width, IMAGE_SCALE * Img.height, QUIET, IM_NEAREST_PIXEL);ConvertGrayImageToRgb(RgbImg, Img);SHAPE AlignedAvShape(ScaledShape);DrawShape(RgbImg, ScaledShape, C_YELLOW, 1.0, IM_CONNECT_DOTS, IM_NO_ANNOTATE, IM_WHISKERS, 0, IM_TRANSPARENT, gLandTab, &ScaledShape, IM_NO_DRAW_CIRCLES);CropRgbImageSoWidthIsDivisbleBy4(RgbImg); // this is unfortunately needed for RgbPrintfCropImageToFace(RgbImg, Shape, IMAGE_SCALE);RgbPrintf(RgbImg, 8, 3, C_YELLOW, 120, "Whiskers");WriteBmp(RgbImg, sOutPath);#undef IMAGE_SCALE#undef NSHADES}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -