将区域覆盖为黑色或白色

时间:2022-11-11 21:18:17
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main()
{
    cv::Mat ref = cv::imread("beethoven_ode_to_joy.jpg");
    cv::Mat tpl = cv::imread("test.jpg");
    if (ref.empty() || tpl.empty())
        return -1;

    cv::Mat gref, gtpl;
    cv::cvtColor(ref, gref, CV_BGR2GRAY);
    cv::cvtColor(tpl, gtpl, CV_BGR2GRAY);

    cv::Mat res(ref.rows - tpl.rows + 1, ref.cols - tpl.cols + 1, CV_32FC1);
    cv::matchTemplate(gref, gtpl, res, CV_TM_CCOEFF_NORMED);
    cv::threshold(res, res, 0.8, 1., CV_THRESH_TOZERO);

    while (true)
    {
        double minval, maxval, threshold = 0.8;
        cv::Point minloc, maxloc;
        cv::minMaxLoc(res, &minval, &maxval, &minloc, &maxloc);

        if (maxval >= threshold)
        {
            cv::rectangle(
                ref,
                maxloc,
                cv::Point(maxloc.x + tpl.cols, maxloc.y + tpl.rows),
                CV_RGB(0, 255, 0), 2
                );
            cv::floodFill(res, maxloc, cv::Scalar(0), 0, cv::Scalar(.1), cv::Scalar(1.));
        }
        else
            break;
    }

    cv::imshow("reference", ref);
    cv::waitKey();
    return 0;
}

将区域覆盖为黑色或白色 The First Image is the main input 将区域覆盖为黑色或白色 While the second input is the Template to be match

第一个图像是主输入,而第二个输入是要匹配的模板

The thing that what i want the code to do is detect the G clef and the horizontal staff line of it and remove it, can anyone help me please.

我想要代码做的事情就是检测G谱号及其水平人员线并将其删除,任何人都可以帮助我。

1 个解决方案

#1


0  

Don't flood fill rectangle, just put there staff image without G clef.

不要淹没填充矩形,只是放在没有G谱号的员工图像。

#1


0  

Don't flood fill rectangle, just put there staff image without G clef.

不要淹没填充矩形,只是放在没有G谱号的员工图像。