2016-04-10 7 views
1

私はOpenBV 3.1を使用してSimpleBlobDetectorを使っていくつかのブロブ検出を行っていますが、私は運が無く、これを解決することはできません。私の環境はx64のXCodeです。opencvのSimpleBlobDetectorは何も検出しません

私はこの画像で出始めている: enter image description here

その後、私はグレースケールにそれを回すよ: enter image description here

最後に、私は、バイナリイメージにそれを回すと、この上のブロブ検出を行います。 enter image description here

「iostream」と「opencv2/opencv.hpp」が含まれています。

using namespace cv; 
using namespace std; 

Mat img_rgb; 
Mat img_gray; 
Mat img_keypoints;  
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(); 

vector<KeyPoint> keypoints; 

img_rgb = imread("summertriangle.jpg"); 

//Convert to greyscale 
cvtColor(img_rgb, img_gray, CV_RGB2GRAY); 

imshow("Grey Scale", img_gray); 

// Start by creating the matrix that will allocate the new image 
Mat img_bw(img_gray.size(), img_gray.type()); 

// Apply threshhold to convert into binary image and save to new matrix 
threshold(img_gray, img_bw, 100, 255, THRESH_BINARY); 

// Extract cordinates of blobs at their centroids, save to keypoints variable. 
detector->detect(img_bw, keypoints); 
cout << "The size of keypoints vector is: " << keypoints.size(); 

キーポイントベクトルは常に空です。私が試したことは何もありません。

+0

あなたのコードは 'SimpleBlobDetector'をまったく設定しません。デフォルト設定( 'minArea'、' maxArea'など)が処理している画像の種類には不適切である可能性があります。 – Dai

+0

OpenCVのGithubのblob-detectorサンプルは、最初に 'pDefaultBLOB'パラメータオブジェクトを設定する方法を見てください:https://github.com/Itseez/opencv/blob/2f4e38c8313ff313de7c41141d56d945d91f47cf/samples/cpp/detect_blob.cpp – Dai

+0

ありがとうDai - 私はいくつかのパラメータを設定しようとしました。私は 'minArea'を使って1に、' maxArea'を1000に設定しました。 –

答えて

7

私はこれを解決したので、ドキュメントの細かい部分は読んでいませんでした。 ParamsのヘッドアップのおかげでDaiさんは、私に文書を詳しく見せてくれました。

Default values of parameters are tuned to extract dark circular blobs.

私はSimpleBlobDetectorオブジェクトを作成するときに、単純にこれをしなければならなかった:

SimpleBlobDetector::Params params; 

params.filterByArea = true; 
params.minArea = 1; 
params.maxArea = 1000; 
params.filterByColor = true; 
params.blobColor = 255; 

Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params); 

これはそれをやりました。

関連する問題