【发布时间】:2016-04-04 13:39:14
【问题描述】:
我正在尝试检测全音符和半音符,但对于半音符,我似乎无法检测到它,因为它是一个空心圆圈。有没有办法检测空心圆?
这是我的代码:
#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 = 15;
// Filter by Circularity
params.filterByCircularity = true;
params.minCircularity = 0.1;
// Filter by Convexity
params.filterByConvexity = true;
params.minConvexity = 0.01;
// 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);
imwrite("a.jpg", im_with_keypoints);
waitKey(0);
}
【问题讨论】:
-
请发布您的代码。
-
有很多方法可以做到这一点,但它确实取决于上下文,即代码将在哪里运行(服务器、仅浏览器、桌面应用程序)你想要什么编程语言使用,等等,等等。但总之是可以做到的。
-
将使用的编程语言是 c++ with opencv
-
有没有办法在不使用模板匹配的情况下检测空心圆?
-
您是否尝试过任何机器学习算法来解决您的问题?
标签: opencv image-processing machine-learning computer-vision