Skip to content Skip to sidebar Skip to footer

Setting ORB Parameters In OpenCv With Python

I've been using OpenCV 2.4 in Python to match features between two images, but I want to change one of the parameters of the 'ORB' detector (the number of features it extracts 'nfe

Solution 1:

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")

with output:

ORB parameters (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 before: 500
nFeatures after: 1000

EDIT: To do the same with OpenCV 3.0 is now easier

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

and analogically with a setter.


Post a Comment for "Setting ORB Parameters In OpenCv With Python"