相关疑难解决方法(0)

使用opencv matchtemplate进行泡罩包装检查

我正在做一个项目,我必须检查药物泡罩包装是否缺少药片.

我正在尝试使用opencv的matchTemplate函数.让我展示代码,然后是一些结果.

int match(string filename, string templatename)
{
    Mat ref = cv::imread(filename + ".jpg");
    Mat tpl = cv::imread(templatename + ".jpg");
    if (ref.empty() || tpl.empty())
    {
        cout << "Error reading file(s)!" << endl;
        return -1;
    }

    imshow("file", ref);
    imshow("template", tpl);

    Mat res_32f(ref.rows - tpl.rows + 1, ref.cols - tpl.cols + 1, CV_32FC1);
    matchTemplate(ref, tpl, res_32f, CV_TM_CCOEFF_NORMED);

    Mat res;
    res_32f.convertTo(res, CV_8U, 255.0);
    imshow("result", res);

    int size = ((tpl.cols + tpl.rows) / 4) * 2 + 1; //force size to be odd
    adaptiveThreshold(res, …
Run Code Online (Sandbox Code Playgroud)

opencv inspection matchtemplate

10
推荐指数
1
解决办法
6761
查看次数

标签 统计

inspection ×1

matchtemplate ×1

opencv ×1