2015-12-28 20 views
0

我需要檢測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); 

} 
+0

你必須明白,在簡歷中,事情並不那麼簡單......考慮到你所要求的複雜任務,這種簡單的方法無法成功。您需要深入細節,分析描述符所找到的圖像區域,然後將它們分類。但這遠遠超出了SO問題的範圍。 – kebs

+0

我可以問有沒有辦法檢測筆記頭? – Jon

+0

,無論它是整個音符還是半音符,都會導致我嘗試檢測音符頭並將它們打印到新圖像。 – Jon

回答

2

其實,我沒有OpenCV的now.But我嘗試一些在MATLAB來解決這個短time.Firstly,in this image你會意識到那頭音符比五線譜暗。當我們進入更多音符時,我們看到音符的中心值爲in this image。我建議你,你可以將RGB圖像轉換成灰度圖像,然後可以應用閾值。如果像素值等於0,他們可以,你應該得到它們,但如果沒有,你不會得到它們。它的結果是這裏in this image。然後,我認爲你可以應用一些像擴張這樣的形態學操作。因爲檢測到的音符的頭部會比原始的小一點。如果您想消除音符的上方(我的意思是粘住部分音符),您可以通過虛線轉換來檢測此部分,opencv具有此操作的功能(HoughLines或houghLinesP)。檢測後可以刪除這部分或者如果你不想要,你可以通過這一步。畢竟,你可以在圖像上找到循環對象,具有hough變換.HoughCircles函數在opencv中執行此任務。在Matlab使用findcircles功能會更容易一些。最後,您可以在matlab中繪製具有圓形函數的opencv或viscircles函數。結果是here

請注意,我沒有應用形態學操作來改善頭部大小筆記。此外,我沒有應用houghline轉換來檢測和擦除棒部分。如果您可以應用它們,我t哼,你會得到更好的結果。 這個算法只是一個建議,你可以通過嘗試一些其他操作找到更好的算法。