【问题标题】:Detecting all note head wether it is a whole note or half note检测所有音符头,无论是全音符还是半音符
【发布时间】:2016-04-02 10:08:28
【问题描述】:

我需要从given image 中检测所有全音符和半音符并将所有检测到的音符打印到新图像中。但似乎代码没有检测到半音符,它只检测到整个音符。

这是我的源代码

#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{

    // Read image
    Mat im = imread("beethoven_ode_to_joy.jpg", IMREAD_GRAYSCALE);

    // Setup SimpleBlobDetector parameters.
    SimpleBlobDetector::Params params;

    // Change thresholds
    params.minThreshold = 10;
    params.maxThreshold = 200;

    // Filter by Area.
    params.filterByArea = true;
    params.minArea = 25;

    // Filter by Circularity
    params.filterByCircularity = true;
    params.minCircularity = 0.1;

    // Filter by Convexity
    params.filterByConvexity = true;
    params.minConvexity = 0.87;

    // Filter by Inertia
    params.filterByInertia = true;
    params.minInertiaRatio = 0.01;


    // Storage for blobs
    vector<KeyPoint> keypoints;


#if CV_MAJOR_VERSION < 3   // If you are using OpenCV 2

    // Set up detector with params
    SimpleBlobDetector detector(params);

    // Detect blobs
    detector.detect(im, keypoints);
#else 

    // Set up detector with params
    Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);

    // Detect blobs
    detector->detect(im, keypoints);
#endif 

    // Draw detected blobs as red circles.
    // DrawMatchesFlags::DRAW_RICH_KEYPOINTS flag ensures
    // the size of the circle corresponds to the size of blob

    Mat im_with_keypoints;
    drawKeypoints(im, keypoints, im_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

    // Show blobs
    imshow("keypoints", im_with_keypoints);
    waitKey(0);

}

【问题讨论】:

  • 您必须明白,在 CV 中,事情并没有那么简单……考虑到您要求的复杂任务,这种简单的方法不会成功。您需要更深入地了解细节,分析描述符正在查找的图像区域,然后将它们分类。但这远远超出了 SO 问题的范围。
  • 请问有没有办法检测音符头?
  • 不管是全音符还是半音符,因为我正在尝试检测音符头并将它们打印到新图像上。
  • 想法:使用描述符提取其位置周围的小图像(比如 32x32),验证它们,然后提取上面预期尾部大小的矩形,然后检查是否有尾部,然后检查如果是全音符或半音符,则在该行的顶部。好多代码要写...
  • 投票以“过于宽泛”而关闭,因为转储 C++ 代码并仅仅说“它不起作用”是没有成效的。

标签: c++ opencv image-processing


【解决方案1】:

实际上,我现在没有openCV。但是我尝试在短时间内在matlab中解决这个问题。首先,in this image你会意识到音符的头部比五线谱更黑。当我们深入了解它时我们看到笔记中心的值为 0 in this image 。我建议你可以将你的 RGB 图像转换为灰度图像,之后可以应用阈值处理。如果像素的值等于 0,它们没关系,你应该得到它们,但如果不是,你不会得到它们。它的结果是这里in this image。然后,我想你可以应用一些形态学操作,比如膨胀。因为检测到的音符会比原来的小一点。如果你想消除音符的上边(我的意思是粘贴部分音符)你可以用霍夫线变换检测这部分,opencv有这个操作的功能(HoughLines或houghLinesP)。检测后可以删除这部分或者如果不想要也可以通过这一步。毕竟可以通过hough变换找到图像上的圆形物体。HoughCircles函数在opencv中执行这个任务。在Matlab中使用 findcircles 函数会更容易一些。最后,您可以在 opencv 中使用 circle 函数或 matlab 中的 viscircles 函数绘制已创建的圆。结果是here

请注意,我没有应用形态学操作来提高音符的大小。另外,我没有应用水平线变换来检测和擦除棒状部分。如果你能应用它们,我想你会得到更好的结果。 该算法只是一个建议,您可以通过尝试其他一些操作来找到更好的算法。

【讨论】:

    猜你喜欢
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多