cv::Mat TemplateMatchingCandidateFinder::getCandidates(
		cv::Mat source) {
	//TODO read from resource or get an absolute path (from startup path)
	cv::Mat signHeader = cv::imread("signHeader.png");
	cv::Mat result;

	fastMatchTemplate(source,signHeader,result,MAX_PYRAMID_LEVEL);
	return result;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    if (argc != 3) {
        std::cout << "Usage: subimage-search <Image> <SubImage>\n";
        return -1;
    }

    cv::Mat ref = cv::imread(argv[1]);
    cv::Mat tpl = cv::imread(argv[2]);
    if (ref.empty() || tpl.empty())
        return -1;

    cv::Mat ref_gray, tpl_gray;
    cv::cvtColor(ref, ref_gray, CV_BGR2GRAY);
    cv::cvtColor(tpl, tpl_gray, CV_BGR2GRAY);

    cv::Mat dst;
    fastMatchTemplate(ref_gray, tpl_gray, dst, 2);

    while (true)
    {
        double minval, maxval;
        cv::Point minloc, maxloc;
        cv::minMaxLoc(dst, &minval, &maxval, &minloc, &maxloc);

        if (maxval < 0.99) {
            break;
        }

        double poix, poiy;
        poix = maxloc.x + tpl.cols / 2.0;
        poiy = maxloc.y + tpl.rows / 2.0;
        poix = round(poix);
        poiy = round(poiy);

        std::cout << poix << " " << poiy << " " << maxval << "\n";

        // Change the currently selected region, so that the next region
	// is slected on the following pass.
        cv::floodFill(dst, maxloc,
                cv::Scalar(0), 0, cv::Scalar(.1), cv::Scalar(1.));
    }

    return 0;
}