3

我已经安装了带有额外模块的 opencv 3.1.0,但是当我尝试使用

>>> s = cv2.face.MinDistancePredictCollector()

它返回一个错误

Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
s.MinDistancePredictCollector()
AttributeError: 'module' object has no attribute 'MinDistancePredictCollector'

我还检查了文档:

>>> help(cv2.face)
Help on module cv2.face in cv2:

NAME
    cv2.face

FILE
    (built-in)

FUNCTIONS
    StandardCollector_create(...)
    StandardCollector_create([, threshold]) -> retval

    createEigenFaceRecognizer(...)
    createEigenFaceRecognizer([, num_components[, threshold]]) -> retval

    createFisherFaceRecognizer(...)
    createFisherFaceRecognizer([, num_components[, threshold]]) -> retval

    createLBPHFaceRecognizer(...)
    createLBPHFaceRecognizer([, radius[, neighbors[, grid_x[, grid_y[,    threshold]]]]]) -> retval

我发现MinDistancePredictCollector()不存在。那么我该如何安装呢?

4

1 回答 1

3

我刚刚在Github上问过同样的问题,可以通过以下代码解决:

if cv2.__version__ >= "3.1.0":
    collector = cv2.face.StandardCollector_create()
    recognizer.predict_collect(face_img, collector)
    conf = collector.getMinDist()
    pred = collector.getMinLabel()
else:     # older version
    pred, conf = recognizer.predict(face_img)
于 2017-01-06T06:25:49.007 回答