【发布时间】: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