static void TraceEyesMouth( Image& face_roi, // out: ROI around face, possibly rotated upright DetPar& detpar_roi) // out: detpar wrt to face_roi { #if TRACE_IMAGES // will be 0 unless debugging (defined in stasm.h) CImage cimg; cvtColor(face_roi, cimg, CV_GRAY2BGR); // color image rectangle(cimg, cv::Point(cvRound(detpar_roi.x - .5 * detpar_roi.width), cvRound(detpar_roi.y - .5 * detpar_roi.height)), cv::Point(cvRound(detpar_roi.x + .5 * detpar_roi.width), cvRound(detpar_roi.y + .5 * detpar_roi.height)), ToCvColor(C_BLUE), 3); if (Valid(detpar_roi.lex)) cv::circle(cimg, cv::Point(cvRound(detpar_roi.lex), cvRound(detpar_roi.ley)), MAX(2, face_roi.cols / 40), cv::Scalar(0, 0, 255), 2); if (Valid(detpar_roi.rex)) cv::circle(cimg, cv::Point(cvRound(detpar_roi.rex), cvRound(detpar_roi.rey)), MAX(2, face_roi.cols / 40), cv::Scalar(0, 0, 255), 2); if (Valid(detpar_roi.mouthx)) cv::circle(cimg, cv::Point(cvRound(detpar_roi.mouthx), cvRound(detpar_roi.mouthy)), MAX(2, face_roi.cols / 40), cv::Scalar(0, 0, 255), 2); char s[SLEN]; sprintf(s, "%s_25_eyemouth.bmp", Base(imgpath_g)); lprintf("%s\n", s); if (!cv::imwrite(s, cimg)) Err("Cannot write %s", s); #endif }
static void DrawRect( // draw a rectangle on an image CImage& img, // io const Rect& rect, // in unsigned color=0xff0000, // in: rrggbb, default is 0xff0000 (red) int linewidth=2) // in { rectangle(img, cv::Point(rect.x, rect.y), cv::Point(rect.x + rect.width, rect.y + rect.height), ToCvColor(color), linewidth); }
static void DrawFeat( // draw eye (or mouth) at index i in the eyes vec CImage& img, // io int i, // in const vec_Rect& eyes, // in unsigned col, // in int linewidth, // in bool best) // in: true if this is the best eye { double x, y; RectToImgFrame(x, y, eyes[i]); Rect rect; rect.x = cvRound(x - eyes[i].width / 2); rect.y = cvRound(y - eyes[i].height / 2); rect.width = eyes[i].width; rect.height = eyes[i].height; if (!best) col = Dark(col); DrawRect(img, rect, col, linewidth); cv::circle(img, cv::Point(cvRound(x), cvRound(y)), (best? 2: 1) * linewidth, ToCvColor(col), linewidth); }