Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python在OpenCv中设置ORB参数_Python_Opencv - Fatal编程技术网

使用Python在OpenCv中设置ORB参数

使用Python在OpenCv中设置ORB参数,python,opencv,Python,Opencv,我一直在使用Python中的OpenCV 2.4来匹配两个图像之间的功能,但我想更改“ORB”检测器的一个参数(它提取的“nfeatures”功能的数量),在Python中似乎没有办法这样做 < C++ >你可以通过“Read”(或“Load”java)?但是Python绑定缺少此函数/方法 它还缺少直接创建ORB对象的绑定,因此我无法在那里传递参数(Python绑定似乎要求您使用cv2.DescriptorExtractor\u按字符串名称创建——如果您传递了错误的字符串名称或随附的参数,这将

我一直在使用Python中的OpenCV 2.4来匹配两个图像之间的功能,但我想更改“ORB”检测器的一个参数(它提取的“nfeatures”功能的数量),在Python中似乎没有办法这样做

< C++ >你可以通过“Read”(或“Load”java)?但是Python绑定缺少此函数/方法

它还缺少直接创建ORB对象的绑定,因此我无法在那里传递参数(Python绑定似乎要求您使用cv2.DescriptorExtractor\u按字符串名称创建——如果您传递了错误的字符串名称或随附的参数,这将导致segfault…此外,该函数不能接受它似乎传递给构造函数的任何其他参数

我唯一的希望似乎是用cv2.cv.Load(文件名)从xml加载完整的对象,但这似乎是一个对象实例,而不是算法定义,我找不到任何新语法或旧语法的Python绑定。我在文件加载步骤中尝试了几种变体,包括模仿OpenCV中保存的xml文件的样式,但没有成功

在我上面尝试的将参数传递到OpenCV中的检测器(SURF或ORB,或任何通用算法)的步骤中,有人成功过吗

以下是我用来提取特征的代码:

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的站点上

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','nLevel','patchSize','scaleFactor','scoreType']
WTA_K=2
edgeThreshold=31
第一级=0
n特征=500
nLevel=8
补丁大小=31
scaleFactor=1.2000004768
scoreType=0
n之前的功能:500
n之后的特征: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

与setter类似。

在我发布问题之前,我已经尝试过了。在Windows 7上的OpenCV 2.4下,64位运行32位Python,Windows Vista 32位运行32位Python,这段代码在
detector.getParams()上出错
没有stacktrace,没有要捕获的异常,也没有来自OpenCV的错误消息。您使用的是什么安装程序,而这不会立即发生故障?对我来说,它只会在DescriptorMatcher的getParams()上崩溃但是检测器可以工作。我正在使用Fedora 17 64位、OpenCV 2.4.3、Python 2.7.3 64位。检测器可以工作,但我无法设置或获取检测器上的任何参数,这使得它无法使用,因为默认值与所有视觉问题不匹配(因此我使用了不同的检测器)。如果它在getParams上崩溃,您是如何打印上述输出的?我可能会尝试fedora vm,看看相同的调用是否在我的机器上崩溃。您完全正确,可调参数对于任何计算机视觉问题都至关重要。上面的代码完全在我的设置中工作(我上面提到的那一个)我不知道Windows可能有什么问题,但我建议您尝试类似的设置或检查Windows是否存在已知的bug。