// Returns true if contains some faces. Hilight with a rectangle the face on the // image. std::vector<cv::Rect> FaceClassifier::classify(const cv::Mat& image) { std::vector<cv::Rect> allCandidates; cv::Mat1b gray = Preprocessor::gray(image); // pyramid downsampling // from smaller to bigger. // avoid to search where a face in a lower scale is found < image, scale // factor > std::vector<std::pair<cv::Mat1b, float>> pyramid; for (float factor = 1;; factor *= _scaleFactor) { // Size of the image scaled down (from bigger to smaller) cv::Size sz(image.cols / factor, image.rows / factor); // Difference between sized of the scaled image and the original detection // window cv::Size sz1(sz.width - _windowSize.width, sz.height - _windowSize.height); // if the actual scaled image is smaller than the origina detection window, // break if (sz1.width < 0 || sz1.height < 0) { break; } cv::Mat1b level; cv::resize(gray, level, sz, 0, 0, cv::INTER_NEAREST); pyramid.push_back(std::pair<cv::Mat1b, float>(level, factor)); } // from smaller to bigger for (auto rit = pyramid.rbegin(); rit != pyramid.rend(); rit++) { cv::Mat1b level = (*rit).first; float factor = (*rit).second; _slidingSearch(level, factor, allCandidates); } return allCandidates; }
static void test_CSize() { CSize empty; ok(empty.cx == 0, "Expected cx to be 0, was %ld\n", empty.cx); ok(empty.cy == 0, "Expected cy to be 0, was %ld\n", empty.cy); CSize szPointA(10, 25); SIZE sz; sz.cx = 10; sz.cy = 25; CSize szPointB(sz); POINT pt; pt.x = 10; pt.y = 25; CSize szPointC(pt); CPoint ptObject(10, 25); CSize szPointD(ptObject); DWORD dw = MAKELONG(10, 25); CSize szPointE(dw); ok_size(szPointA, szPointB); ok_size(szPointB, szPointC); ok_size(szPointC, szPointD); ok_size(szPointD, szPointE); ptObject = szPointA + pt; CPoint res(20,50); ok_point(ptObject, res); ptObject = szPointA - pt; res = CPoint(0, 0); ok_point(ptObject, res); CSize sz1(135, 135); CSize sz2(135, 135); ok_size(sz1, sz2); sz1 = CSize(222, 222); sz2 = CSize(111, 111); ok(sz1 != sz2, "Wrong size, expected '%s' NOT to equal '%s'\n", wine_dbgstr_size(&sz1), wine_dbgstr_size(&sz2)); sz1 = CSize(100, 100); sz2 = CSize(50, 25); sz1 += sz2; CSize szResult(150, 125); ok_size(sz1, szResult); sz1 = CSize(100, 100); SIZE sz3; sz3.cx = 50; sz3.cy = 25; sz1 += sz3; ok_size(sz1, szResult); sz1 = CSize(100, 100); sz1 -= sz2; szResult = CSize(50, 75); ok_size(sz1, szResult); sz3.cx = 50; sz3.cy = 25; sz1 = CSize(100, 100); sz1 -= sz3; ok_size(sz1, szResult); sz1 = CSize(100, 100); CSize szOut; szOut = sz1 + sz2; szResult = CSize(150, 125); ok_size(szOut, szResult); sz3.cx = 50; sz3.cy = 25; szOut = sz1 + sz3; ok_size(szOut, szResult); szOut = sz1 - sz2; szResult = CSize(50, 75); ok_size(szOut, szResult); sz3.cx = 50; sz3.cy = 25; szOut = sz1 - sz3; ok_size(szOut, szResult); szResult = CSize(-50, -75); szOut = -szOut; ok_size(szOut, szResult); RECT rc = { 1, 2, 3, 4 }; CRect rcres = sz1 + &rc; CRect rcexp(101, 102, 103, 104); ok_rect(rcexp, rcres); rcres = sz1 - &rc; rcexp = CRect(-99, -98, -97, -96); ok_rect(rcexp, rcres); }