# Using opencv\_contrib with python and ROS

**URL:** <https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736>\
**Category:** Python\
**Tags:** build, ros\
**Created:** [October 3, 2023, 3:34pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736 "2023-10-03T15:34:34Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 3, 2023, 3:34pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/1 "2023-10-03T15:34:34Z")

</div>

Hello,  
I’ve installed OpenCv 4.8.0 with contribs and linked it with ROS.  
I can use the extra modules with C++ nodes, but I can’t with Python. I found that I have to rebuild OpenCv with OPENCV\_ENABLE\_NONFREE = ON, but it is not working.  
Do I have to rebuild even the vision\_opencv pacage I’ve got in my workspace?

Thanks in advance for your help

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 3, 2023, 3:41pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/2 "2023-10-03T15:41:30Z")

</div>

if you build opencv yourself, you also have to “install” it properly. if you do not, you will not get _that_ opencv in your python. you’ll get whatever you installed previously.

---

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 3, 2023, 3:52pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/3 "2023-10-03T15:52:49Z")

</div>

This is the error I get when I try to run the python node I’ve written in ROS:

cv2.error: OpenCV(4.7.0) /io/opencv\_contrib/modules/xfeatures2d/src/surf.cpp:1026: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV\_ENABLE\_NONFREE CMake option and rebuild the library in function ‘create’

But I’m not sure I’m doing this properly

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 3, 2023, 4:41pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/4 "2023-10-03T16:41:23Z")

</div>

you describe two issues.

first:

> [@frapi](#):
>
> I can use the extra modules with C++ nodes, but I can’t with Python.

second:

> [@frapi](#):
>
> (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV\_ENABLE\_NONFREE CMake option and rebuild the library in function ‘create’

you’ve provided evidence for the latter. I don’t see evidence that the former is an actual issue. I’ll ignore that then.

yes, you have to build with that flag if you want parts of OpenCV that require the flag.

please set it (use cmake-gui or pass via CLI), have cmake regenerate the build files, then build.

---

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 4, 2023, 7:50am UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/5 "2023-10-04T07:50:57Z")

</div>

I’ve built with OPENCV\_ENABLE\_NONFREE=ON, but it still doesn’t work with Python. I get the same error.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 4, 2023, 8:37am UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/6 "2023-10-04T08:37:07Z")

</div>

after you’ve built the library, how do you install it?

---

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 4, 2023, 8:43am UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/7 "2023-10-04T08:43:50Z")

</div>

OpenCv is already installed, I’ve just rebuilt the package.  
Sorry, I don’t know much about these things so maybe I don’t understand what you mean

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 4, 2023, 10:18am UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/8 "2023-10-04T10:18:08Z")

</div>

> [@frapi](#):
>
> OpenCv is already installed

perhaps, but not the one you just built.

what do you think happens when you build the library? do you think python somehow knows about those files?

I am trying to tell you that you are missing some steps.

---

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 4, 2023, 10:36am UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/9 "2023-10-04T10:36:40Z")

</div>

Ok, well I thought the files were there and I just had to “link” them or something, but, as I said, I don’t know much about what happen when I build a library.  
Do you have any suggestion about the steps you think I am missing?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 4, 2023, 1:28pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/10 "2023-10-04T13:28:26Z")

</div>

what build files do you generate from cmake? makefiles? ninja? something else?

---

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 4, 2023, 1:38pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/11 "2023-10-04T13:38:30Z")

</div>

I think only Makefiles.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 4, 2023, 6:18pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/12 "2023-10-04T18:18:37Z")

</div>

have you run the “make install” command on a successful opencv build?

what is the resulting output?

---

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 4, 2023, 8:14pm UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/13 "2023-10-04T20:14:40Z")

</div>

No, I’ve run the command: make -j8

---

<div class="post-metadata">

**Author:** ![frapi](https://avatars.discourse-cdn.com/v4/letter/f/e56c9b/32.png) [@frapi](https://forum.opencv.org/u/frapi)\
**Post date:** [October 5, 2023, 7:47am UTC](https://forum.opencv.org/t/using-opencv-contrib-with-python-and-ros/14736/14 "2023-10-05T07:47:14Z")

</div>

I’ve tried to run “make install”, but I still get the same error as before.
