static void TraceFaces( // write image showing detected face rects const vec_DetPar& detpars, // in const Image& img, // in const char* path) // in { #if TRACE_IMAGES // will be 0 unless debugging (defined in stasm.h) CImage cimg; cvtColor(img, cimg, CV_GRAY2BGR); // color image for (int iface = 0; iface < NSIZE(detpars); iface++) { const DetPar &detpar = detpars[iface]; rectangle(cimg, cv::Point(cvRound(detpar.x - detpar.width/2), cvRound(detpar.y - detpar.height/2)), cv::Point(cvRound(detpar.x + detpar.width/2), cvRound(detpar.y + detpar.height/2)), CV_RGB(255,255,0), 2); ImgPrintf(cimg, // 10 * iface to minimize overplotting detpar.x + 10 * iface, detpar.y, C_YELLOW, 1, ssprintf("%d", iface)); } lprintf("%s\n", path); if (!cv::imwrite(path, cimg)) Err("Cannot write %s", path); #endif }
static void ProcessFace( CImage& cimg, // io: color version of image const float* landmarks, // in int nfaces, // in const char* imgpath) // in { Shape shape(LandmarksAsShape(landmarks)); shape = ConvertShape(shape, nlandmarks_g); if (shape.rows == 0) Err("Cannot convert to a %d point shape", nlandmarks_g); if (writeimgs_g) DrawShape(cimg, shape); if (multiface_g) { logprintf("face %d\n", nfaces); double xmin, xmax, ymin, ymax; // needed to position face nbr ShapeMinMax(xmin, xmax, ymin, ymax, shape); ImgPrintf(cimg, (xmin + xmax)/2, ymin - (ymax-ymin)/50., 0xff0000, 1, "%d", nfaces); } if (csv_g) LogShapeAsCsv(shape, imgpath); else LogShape(shape, imgpath); }
static void TraceEyeMouthImg( CImage& cimg, // in DetPar& detpar, // in int ileft_best, // in int iright_best, // in int imouth_best) // in { rectangle(cimg, // border color shows eyaw cv::Point(0, 0), cv::Point(cimg.cols-1, cimg.rows-1), EyawAsColor(detpar.eyaw), 4); ImgPrintf(cimg, .8 * cimg.cols, .05 * cimg.rows, C_YELLOW, 1, "%s", EyawAsString(detpar.eyaw)); char sl[SLEN]; sl[0] = 0; if (ileft_best < 0) strcat(sl, "_noleye"); char sr[SLEN]; sr[0] = 0; if (iright_best < 0) strcat(sl, "_noreye"); char sm[SLEN]; sm[0] = 0; if (imouth_best < 0) strcat(sl, "_nomouth"); double rot = detpar.rot; // INVALID rots will appear as 99999 in filename PossiblySetRotToZero(rot); char path[SLEN]; sprintf(path, "%s_20_rot%d_eyemouth%s%s%s.bmp", Base(imgpath_g), int(ABS(rot)), sl, sr, sm); lprintf("%s\n", path); if (!cv::imwrite(path, cimg)) Err("Cannot write %s", path); }
static void TraceShape( // write an image file showing current shape on the image const Shape& shape, // in: current search shape const Image& pyrimg, // in: image scaled to this pyramid level int ilev, // in: pyramid level (0 is full size) int iter, // in: model iteration (-1 if start shape) const char* suffix) // in { #if TRACE_IMAGES // will be 0 unless debugging (defined in stasm.h) static int index; // number images so they appear in order in the directory // start at index 30 because lower indices have already used for facedet etc. if (strcmp(suffix, "start") == 0) index = 30; Image img; // pyrimg rescaled back to full size image (after rescaling by eyemouth) const double RESOLUTION = 2; // 1 for no extra resolution, 2 for double resolution const double rescale = RESOLUTION / GetPyrScale(ilev); cv::resize(pyrimg, img, cv::Size(), rescale, rescale, cv::INTER_NEAREST); CImage cimg; cvtColor(img, cimg, CV_GRAY2BGR); // color image DesaturateImg(cimg); Shape shape1(RoundMat(shape)); shape1 += .4; // put shape points in center of rescaled pixels shape1 *= rescale; DrawShape(cimg, shape1, C_YELLOW, false, 1); char path[SLEN]; if (iter < 0) // start shape? sprintf(path, "%s_%2.2d_%s.bmp", Base(imgpath_g), index, suffix); else sprintf(path, "%s_%2.2d_lev%d_iter%d_%s.bmp", Base(imgpath_g), index, ilev, iter, suffix); ImgPrintf(cimg, 10 * RESOLUTION, 20 * RESOLUTION, C_YELLOW, 2, path); if (iter >= 0) { // draw 1D patch boundary at one point (patch is drawn // horizontal, not rotated to shape boundary as it should be) // [Thanks to Satish Lokkoju for RoundMat fix] Shape shape2(RoundMat(shape)); int ipoint = 0; int proflen = 9; // TASM_1D_PROFLEN int x1 = cvRound(shape2(ipoint, IX)) - proflen / 2; int x2 = x1 + proflen; int y1 = cvRound(shape2(ipoint, IY)); int y2 = y1 + 1; rectangle(cimg, cv::Point(cvRound(rescale * x1), cvRound(rescale * y1)), cv::Point(cvRound(rescale * x2), cvRound(rescale * y2)), CV_RGB(255,0,0), 1); // draw 2D patch boundary at one point if (ilev <= HAT_START_LEV) // we use HATs only at upper pyr levs { // get position of left eye pupil by first converting to a shape17 ipoint = 0; // assume we can't get position of left eye pupil Shape newshape(Shape17OrEmpty(shape2)); if (newshape.rows) // successfully converted to a shape17? ipoint = L17_LPupil; else newshape = shape2; #define round2(x) 2 * cvRound((x) / 2) int patchwidth = HAT_PATCH_WIDTH + round2(ilev * HAT_PATCH_WIDTH_ADJ); x1 = cvRound(newshape(ipoint, IX)) - patchwidth / 2; x2 = x1 + patchwidth; y1 = cvRound(newshape(ipoint, IY)) - patchwidth / 2; y2 = y1 + patchwidth; rectangle(cimg, cv::Point(cvRound(rescale * x1), cvRound(rescale * y1)), cv::Point(cvRound(rescale * x2), cvRound(rescale * y2)), CV_RGB(255,0,0), 1); } } lprintf("%s\n", path); if (!cv::imwrite(path, cimg)) Err("Cannot write %s", path); index++; #endif // TRACE_IMAGES }