ででりんブログ

写真やプログラミングを中心とした雑記帳

スポンサーリンク

【OpenCV】特徴点の抽出(FeatureDetector編)

スポンサーリンク

前回までで各アルゴリズムによる特徴点の抽出を試してみました。
FeatureDetectorを使用することで同じプログラムで指定したアルゴリズムを使用することができるそうです。


そういうわけで早速試してみました。
結果は、文字列で指定したアルゴリズムで動作!
共通のクラスで動くことに感動。


調べたところ、次のアルゴリズムが対応しているそうです。
(間違っていたらすいません。。)
FeatureDetectorの対応アルゴリズム…FAST, FASTX, STAR, SIFT, SURF, ORB, BRISK, MSER, GFTT, HARRIS, Dense, SimpleBlob


キー入力でアルゴリズムを切り替えることができるようにしたサンプルを載せておくので、各動作を試したい方は参考にしてみてください。


ソースコード

#include <opencv2\opencv.hpp>
#include <opencv2\nonfree\nonfree.hpp>

int main( void )
{
	// 特徴点抽出アルゴリズム
	std::string algorithm = "ORB";

	// 特徴点アルゴリズムの選択
	std::cout << "特徴点アルゴリズムの選択" << std::endl;
	std::cout << "FAST, FASTX, STAR, SIFT, SURF, ORB, BRISK, MSER, GFTT, HARRIS, Dense, SimpleBlob" << std::endl;
	std::cin >> algorithm;

	// 選択アルゴリズムのチェック
	if( "FAST" != algorithm && "FASTX" != algorithm && "STAR" != algorithm && "SIFT" != algorithm &&
		"SURF" != algorithm && "ORB" != algorithm && "BRISK" != algorithm && "MSER" != algorithm &&
		"GFTT" != algorithm && "HARRIS" != algorithm && "Dense" != algorithm && "SimpleBlob" != algorithm ){
		return -1;
	}

	// SIFTまたはSURFの場合、initModule_nonfree()が必要
	if( "SIFT" == algorithm || "SURF" == algorithm ){
		cv::initModule_nonfree();
	}

	// 画像の読み込み
	cv::Mat	img_src = cv::imread( "Lenna.png" );

	// FeatureDetector
	cv::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create( algorithm );

	// 特徴点
	std::vector<cv::KeyPoint> keypoints;

	// 特徴点の取得
	detector->detect( img_src, keypoints );

	// 特徴点の記述
	cv::Mat	img_dst;
	cv::drawKeypoints( img_src, keypoints, img_dst );

	std::cout << "特徴点数:" << keypoints.size() << std::endl;

	// 画像の表示
	cv::namedWindow( "特徴点抽出", CV_WINDOW_AUTOSIZE );
	cv::imshow( "特徴点抽出", img_dst );
	cv::waitKey( 0 );

	return 0;
}



参考

OpenCVによる画像処理入門 (KS情報科学専門書)

OpenCVによる画像処理入門 (KS情報科学専門書)

スポンサーリンク