3

Python で OpenCV 2.4 を使用して 2 つの画像の特徴を一致させてきましたが、「ORB」検出器のパラメーターの 1 つ (「nfeatures」を抽出する特徴の数) を変更したいのですが、方法がないようです。 Pythonでそうしてください。

C++ の場合、FeatureDetector/DescriptorExtractor の 'read' (または java の場合は 'load') メソッドによってパラメーター yml/xml ファイルをロードできます。ただし、Python バインディングにはこの関数/メソッドがありません。

また、ORB オブジェクトを直接作成するバインディングがないため、そこにパラメーターを渡すことができません (Python バインディングでは、文字列名で cv2.DescriptorExtractor_create を使用する必要があるようです。これは、間違った文字列名またはそれと一緒にパラメーター...さらに、その関数は、コンストラクターに渡すように見える他の引数を取ることができません。

私の唯一の希望は、xml から cv2.cv.Load(filename) を使用して完全なオブジェクトをロードすることのように見えましたが、それはアルゴリズム定義ではなくオブジェクト インスタンスを期待しているようで、新しいまたは古い Python バインディングが見つかりません。構文。OpenCV から保存された xml ファイルのスタイルを模倣するなど、ファイルの読み込みステップでいくつかのバリエーションを試しましたが、うまくいきませんでした。

OpenCVでパラメーターを検出器(SURFまたはORB、または任意の汎用アルゴリズム)に渡すために上で試した手順の1つに成功した人はいますか?

機能を抽出するために使用しているコードは次のとおりです。

def findFeatures(greyimg, detector="ORB", descriptor="ORB"):
    nfeatures = 2000 # No way to pass to detector...?
    detector = cv2.FeatureDetector_create(detector)
    descriptorExtractor = cv2.DescriptorExtractor_create(descriptor)
    keypoints = detector.detect(greyimg)
    (keypoints, descriptors) = descriptorExtractor.compute(greyimg, keypoints)
    return keypoints, descriptors

編集

検出器の設定を変更すると、Windows の実装でセグメンテーション違反のみが発生するようです。パッチまたは修正プログラムが OpenCV のサイトに表示されるのを待っています。

4

1 に答える 1

5
import cv2

# to see all ORB parameters and their values
detector = cv2.FeatureDetector_create("ORB")    
print "ORB parameters (dict):", detector.getParams()
for param in detector.getParams():
    ptype = detector.paramType(param)
    if ptype == 0:
        print param, "=", detector.getInt(param)
    elif ptype == 2:
        print param, "=", detector.getDouble(param)

# to set the nFeatures
print "nFeatures before:", detector.getInt("nFeatures")
detector.setInt("nFeatures", 1000)
print "nFeatures after:", detector.getInt("nFeatures")

出力付き:

ORB パラメーター (dict): ['WTA_K', 'edgeThreshold', 'firstLevel', 'nFeatures', 'nLevels', 'patchSize', 'scaleFactor', 'scoreType']
WTA_K = 2
edgeThreshold = 31
firstLevel = 0
nFeatures = 500
nLevels = 8
patchSize = 31
scaleFactor = 1.20000004768
scoreType = 0
nFeatures 前: 500
nFeatures 後: 1000

編集: OpenCV 3.0 で同じことを行うのが簡単になりました

import cv2

detector = cv2.ORB_create()
for attribute in dir(new_detector):
    if not attribute.startswith("get"):
        continue
    param = attribute.replace("get", "")
    get_param = getattr(new_backend, attribute)
    val = get_param()
    print param, '=', val

セッターと同様に。

于 2013-02-26T21:21:41.100 に答える