Latent SVM 使ってみた

流行りのLatent-SVMに手を出してみました。

Latent-SVMはモデルをいろんなパーツを持った集合として捉え、モデルの隠れ変数となっている各パーツの位置関係を学習する手法です。参考URL → http://www.cs.berkeley.edu/~rbg/latent/

OpenCVにも実装されているので早速サンプルを動かしてみましょう!

#include <opencv2/opencv.hpp>

// --------------------------------------------------------------------------
// main(Number of arguments, Argument values)
// Description : This is the entry point of the program.
// Return value : SUCCESS:0 ERROR:-1
// --------------------------------------------------------------------------
int main(int argc, char **argv)
{
// 画像
cv::Mat image = cv::imread("cat.jpg");

// モデルデータ
std::vector<std::string> models;
models.push_back("cat.xml");

// LSVM
cv::LatentSvmDetector detector(models);

// 検出
std::vector<cv::LatentSvmDetector::ObjectDetection> detections;
detector.detect(image, detections);

// クラス名
const std::vector<std::string> classNames = detector.getClassNames();

// 検出したモデルの表示
for (size_t i = 0; i < detections.size(); i++) {
const cv::LatentSvmDetector::ObjectDetection &od = detections[i];
cv::rectangle(image, od.rect, CV_RGB(0, 255, 0), 2);
cv::putText(image, classNames[od.classID], cv::Point(od.rect.x+4, od.rect.y+13), cv::FONT_HERSHEY_SIMPLEX, 0.55, CV_RGB(255, 255, 255), 2);
}

// 画像表示
cv::imshow("cat", image);
cv::waitKey(0);

return 0;
}

lsvm_cat.jpg
ネコネコカワイイヤッター!

なんだか猫以外も検出していますね。

これ以外の学習済みモデルはopencv_extraにあります。いろいろ試してみましょう。

あれ?でもこれどうやって学習データ作るんだ?
関連記事

コメントの投稿

非公開コメント

プロフィール

puku

Author:puku
暇な時はゲームかプログラミングしてる人だよ。
だいたい月1更新。
CV Drone はこちら(GitHub)

最近はQiitaでOnsenUI2で遊んでいる。

最新記事
最新コメント
最新トラックバック
検索フォーム
カレンダー
04 | 2023/05 | 06
- 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 - - -
月別アーカイブ
カテゴリ
スポンサードリンク
RSSリンクの表示
FC2カウンター
リンク
ブロとも申請フォーム

この人とブロともになる

アクセスランキング
[ジャンルランキング]
コンピュータ
822位
アクセスランキングを見る>>

[サブジャンルランキング]
プログラミング
152位
アクセスランキングを見る>>
FC2ブログランキング

FC2Blog Ranking

QRコード
QR