cv - 複数画像テンプレートの特徴を検出 (:cv_detect_templates)
宣言
結果セット, 可視化画像 = 画像:cv_detect_templates(小画像テンプレートセットとオプション)
パラメータ
-
小画像テンプレート一覧とオプション
省略可能なテーブル。各配列要素は画像オブジェクトで、名前付きフィールドはオプションオプションフィールド
{
should_visualize = false | true, -- 省略可能。可視化出力を行うか。デフォルトは false
detector = 0 | 1 | 2, -- 省略可能。特徴検出器。0: ORB, 1: SIFT, 2: SURF。デフォルトは 0: ORB
score_thresh = number_value, -- 省略可能。パーセント単位の特徴点マッチングスコアのしきい値。デフォルトは 90
}
戻り値
-
結果一覧
テーブル。画像上で検出されたテンプレート特徴の情報一覧検出結果一覧の構造
{
{ -- 結果 1
{ -- 結果 1 の頂点 1
["y"] = number_value,
["x"] = number_value,
},
{ -- 結果 1 の頂点 2
["y"] = number_value,
["x"] = number_value,
},
{ -- 結果 1 の頂点 3
["y"] = number_value,
["x"] = number_value,
},
{ -- 結果 1 の頂点 4
["y"] = number_value,
["x"] = number_value,
},
confidence = number_value, -- 結果 1 の全特徴点を総合した信頼度
angle = number_value, -- 回転角度
index = number_value, -- 一致したテンプレートの小画像テンプレート一覧内でのインデックス
},
{ -- 結果 2
{ -- 結果 2 の頂点 1
["y"] = number_value,
["x"] = number_value,
},
{ -- 結果 2 の頂点 2
["y"] = number_value,
["x"] = number_value,
},
{ -- 結果 2 の頂点 3
["y"] = number_value,
["x"] = number_value,
},
{ -- 結果 2 の頂点 4
["y"] = number_value,
["x"] = number_value,
},
confidence = number_value, -- 結果 2 の全特徴点を総合した信頼度
angle = number_value, -- 回転角度
index = number_value, -- 一致したテンプレートの小画像テンプレート一覧内でのインデックス
},
...
} -
可視化画像
画像オブジェクト。options.should_visualize が true の場合、この戻り値は可視化結果の画像オブジェクト
説明
画像から小画像テンプレート一覧に含まれる画像の特徴を検出する。変形または回転した画像の特徴検出にも使用可能
各小画像テンプレートについて、スコアが score_thresh を超える最適な結果のみを返す
20250625 以降のバージョンでサポート
注意
パラメータの score_thresh と戻り値の confidence は意味が異なる
score_thresh は特徴点の絞り込みに使用し、confidence はテンプレートの全特徴点を総合した信頼度を表す
例
local cv = require("image.cv")
local img1 = image.load_file(XXT_SCRIPTS_PATH..'/1.png')
local img2 = image.load_file(XXT_SCRIPTS_PATH..'/2.png')
local results, visimg = screen.image():cv_detect_templates({
img1, img2;
score_thresh = 90,
detector = 1, -- SIFT
should_visualize = true, -- 可視化出力を行うか。true の場合、二番目の戻り値は画像
})
nLog(results) -- 検出結果の情報を出力
dialog():add_image(visimg):show() -- 検出結果の画像を可視化して表示