2016-12-13 71 views
0

OpenCV 3でSimpleBlobDetectorを使用して、人などの熱画像の塊を検出しようとしています。どのような簡単なコードや例をいただければ幸いです。ブロブ検出器の使用方法

iは

#include <opencv2/core/core.hpp> 

#include <opencv2/highgui/highgui.hpp> 

#include <iostream> 

#include "opencv2\features2d.hpp" 

using namespace cv; 
using namespace std; 

int main(int argc, char** argv) 
{ 
if (argc != 2) 
{ 
    cout << " Usage: display_image ImageToLoadAndDisplay" << endl; 
    return 0; 
} 

Mat image; 
image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); // Read the file 

if (!image.data)        // Check for invalid input 
{ 
    cout << "Could not open or find the image" << std::endl; 
    return 0; 
} 



// Set up the detector with default parameters. 
//SimpleBlobDetector detector; 
// Setup SimpleBlobDetector parameters. 
SimpleBlobDetector::Params params; 

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

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

// 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; 

// Detect blobs. 
std::vector<KeyPoint> keypoints; 
cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params); 
//detector->detect(img, keypoints); 
detector->detect(image, keypoints); 
//params.detect(image, keypoints); 

// 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(image, keypoints, im_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS); 

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

//namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display. 
//imshow("Display window", image);     // Show our image inside it. 

//waitKey(0);           // Wait for a keystroke in the window 
//return 0; 

}をtried` `それはちょうど不変のグレー画像を返します。必要にOpenCVのでブロブを検出するため

答えて

1

  1. インスタンス化SimpleBlobDetectorタイプ
  2. はタイプKeyPoint
  3. コールSimpleBlobDetector::detect()

のベクトルを宣言華麗なチュートリアルがご来店中ですここ(コードからニックネーム):https://www.learnopencv.com/blob-detection-using-opencv-python-c/

using namespace cv; 
Mat im = imread("blob.jpg", IMREAD_GRAYSCALE); 

SimpleBlobDetector detector; 

std::vector<KeyPoint> keypoints; 
detector.detect(im, keypoints); 

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

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

また、パラメータを調整して、特定の属性を持つブロブを選択することもできます。詳細についてはチュートリアルに記載されています。私は、それがどのように動作するのかを感じるために、遊びをすることをお勧めします。

関連する問題