OpenCV 3.2.0-dev - 3.2.0 版本缺少 RTrees,无法找到开发版本

OpenCV 3.2.0-dev - 3.2.0 version missing RTrees, unable to find dev version

OpenCV 3.2.0 似乎没有 RTrees 库 .

但是互联网上到处都是 cv2.RTrees 的例子。我想可能是版本不匹配的问题——也许版本不对?应该是 3.2.0-dev 吗?

但是在 Fedora 24 上,我似乎找不到这个包,在互联网上也找不到。我只看到只有 ubuntu 用户可以安装 3.2.0-dev。我错过了什么吗?

>>> import cv2
>>> cv2.__version__
'3.2.0'
>>> cv2.RTrees
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'RTrees'
>>> cv2.ml.RTrees
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'RTrees'

在此日期之前,您可以在互联网上找到的大多数 RTrees 示例都来自版本 2.4.x。这是因为截至 1 月中旬,OpenCV 的 RTrees 模型的 Python 仍然没有包装器,正如我们在 OpenCV 答案页面上的 this question 中看到的那样。引用它(用户 berak 于 2017 年 1 月 12 日:

unfortunately, this is not possible atm., as of opencv3.2, only SVM and ANN_MLP have correctly wrapped load methods.

(yes, it's a bug)

进一步搜索发现这个问题最近已修复(正如 OpenCV git.

上的 this question); you can see this functionality was added in this pull request 所指出的

因此,更新 到最新的主分支并重建 应该可以解决问题。

注意:记得克隆主存储库(opencv), which is the one who actually contains the RTrees model, and if you are using it also clone the contrib repository (opencv_contrib)。请在每个上检查相同的版本以避免兼容性问题。

奖励: 查看 this OpenCV 的优秀安装指南,它还提供了一些额外的建议,例如使用 venv 进行安装(它也有指南对于其他 OS).