Wednesday, December 29, 2021

[SOLVED] OpenCV 3.2.0-dev - 3.2.0 version missing RTrees, unable to find dev version

Issue

OpenCV 3.2.0 seems does not have RTrees library.

But internet is full of examples of cv2.RTrees. I thought maybe be the issue of versions mismatching - maybe version is wrong ? Should it be 3.2.0-dev ?

But on Fedora 24 i cant seem to find this package nor on the internet. All i see that only ubuntu users can install 3.2.0-dev. Am i missing something ?

>>> 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'

Solution

Most examples of RTrees you could find before this date on the internet are from versions 2.4.x. This is because as of mid January there was still no wrapper for Python of the RTrees model of OpenCV, as we can see in this question on the OpenCV answers page. Quoting from it (user berak on Jan 12 '17:

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)

Searching a bit more it was found that this issue was fixed recently (as pointed out in this question); you can see this functionality was added in this pull request on the OpenCV git.

Therefore, updating to the latest master branch and rebuilding should fix the problem.

Note: Remember to clone the main repository (opencv), which is the one who actually contains the RTrees model, and if you are using it also clone the contrib repository (opencv_contrib). Do checkout the same version on each to avoid compatibility issues.

Bonus: Check this great installation guide for OpenCV, which also provides some additional recommendations like using venv for the installation (it also has guides for other OS).



Answered By - DarkCygnus