0
$\begingroup$

Rosanswers logo

Hey, i want to use the tracking packageof opencv3 contrib in my ROS package.

The tracking packagee seems to be installed correctly, i can find the tracker.cpp in my opencv folder and also use other functions like

Ptr tracker = TrackerMIL::create();

But when i want to use "selectROI" is get an error:

error: ‘selectROI’ was not declared in this scope
 Rect2d r = selectROI(im);

I tried the solution from here but that didn't work for me.

In my opinion i got a linking error like the OP from the link, but what i don't understand is how i can create a Tracker but when i want to use the "selectROI" function its not declared.

Thats the Code i'm trying to compile:

#include <opencv2/opencv.hpp>
#include <opencv2/video/tracking.hpp>
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;


 int main (int argc, char **arv)
{
// Read image
Mat im = imread("~/catkin_ws/Bild.jpg");

// Select ROI
Rect2d r;
r = selectROI(im);

// Crop image
Mat imCrop = im(r);

// Display Cropped Image
imshow("Image", imCrop);
waitKey(0);

return 0;
}

Thanks in advance!


Originally posted by VAVROS on ROS Answers with karma: 1 on 2017-11-14

Post score: 0


Original comments

Comment by gvdhoorn on 2017-11-14:
Not a complete answer, but:

error: ‘selectROI’ was not declared in this scope

and

In my opinion i got a linking error [..]

No, this would be a compiler error: it cannot find the declaration of the symbol selectROI. Are you including the correct headers?

Comment by VAVROS on 2017-11-14:
I think i do, got the test code from here and just strg+C it to be able to better trace back the source of the problem. My complete code is more, but as the "selectROI" seems to be the problem i broke it down

Comment by gvdhoorn on 2017-11-14:
Well it's still a compiler error.

Comment by VAVROS on 2017-11-14:
But i don't get why everyone can use the function with the same headers, but when i try it can't compile. While other function of the tracking API are working just fine.

Comment by gvdhoorn on 2017-11-14:
I sympathise, but I can't help you with that. I just wanted to let you know it's not a linker error.

Comment by gvdhoorn on 2017-11-14:
Btw: OpenCV has its own forum: answers.opencv.org. You might want to ask this over there.

Comment by VAVROS on 2017-11-14:
Thanks for that, it helps to find a solution :)

Comment by gvdhoorn on 2017-11-14:
And OpenCV: Can't find modules from contrib repository (Tracker, selectROI) seems to suggest that perhaps the OpenCV version you are using doesn't include the necessary functionality. I'm not an OpenCV expert, but is the contribs stuff included?

Comment by VAVROS on 2017-11-14:
Yeah i included the contribs and i'm using the newest version of OpenCv which should normally include the necessary functions. I'm trying to figure out a work around to write the function myself.

Comment by gvdhoorn on 2017-11-14:
Kinetic ships its own version of OpenCV. You'll have to make sure which version of OpenCV you're actually compiling against.

Comment by VAVROS on 2017-11-14:
Oh ok, i didn't know that. How can i check if im'm compiling against the right OpenCV Version?

Comment by gvdhoorn on 2017-11-14:
If you're using the CMake snippet as shown on wiki/vision_opencv, then you're most likely using the version shipped with Kinetic.

For using a different version I suggest you search ROS Answers.

Comment by VAVROS on 2017-11-14:
Thank you very much!! I managed to compile against the stand alone version of OpenCV and it worked. The correct answer from here did the trick

Comment by gvdhoorn on 2017-11-14:
You changed the name of the dir in /opt/ros? Please don't do that.

You should be able to override where CMake looks or OpenCV using the regular approach: setting OpenCV_DIR before calling find_package(OpenCV). Be aware of the pitfalls when building against a custom OpenCV version.

Comment by VAVROS on 2017-11-14:
I'm looking for a better solution, but for checking if thats the right way to compile i changed the name in the dir

Comment by ZainMehdi on 2017-11-21:
Did u find any solution ? I have the same problem

Comment by VAVROS on 2017-11-21:
I renamed the folder opencv-3.2.0-dev in my ros/kinetic/include compiled afterwards, the only package giving an error then was cv_bridge. Therefore i editet the file cv_bridgeConfig.cmake in ros/kinetic/share/cv_bridge and changed the path to (in my case) /opt/opencv/ (line 94&96)

Comment by ZainMehdi on 2017-11-21:
renamed the folder opencv-3.2.0-dev to what ? can you specify please

Comment by VAVROS on 2017-11-21:
And in CMakeLists.txt from package i added find_package(OpenCV 3.3.0 REQUIRED COMPONENTS... to look specifically for OpenCV3.3 which is the one i installed instead of OpenCV 3.2 which was shipped with my ros kinetic

Comment by VAVROS on 2017-11-21:
Just renamed it to something else so ROS won't find it if it is looking for it to see which packages won't compile. Afterwards i could fix their path to use the required OpenCV Version

Comment by ZainMehdi on 2017-11-21:
thanks for your help. It gave me some direction.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Edit : Work around not a solution

For anyone still having the same issue I found another way of solving it. I assume that you have installed opencv from source in /usr/local

  1. Locate ROS version of opencv files in /opt/ros/kinetic/include/opencv-3.2.0-dev and /opt/ros/kinetic/lib.
  2. Copy and paste all files from /usr/local/include/opencv2 to /opt/ros/kinetic/include/opencv-3.2.0-dev/opencv2
  3. Do the same for /user/local/lib and /opt/ros/kinetic/lib. (Copy only opencv related lib files)

Assuming that you carried out above steps properly your code involving packages from contrib module including the one mentioned above (selectROI case) should compile fine now without the need of tweaking with cmake files at all.


Originally posted by ZainMehdi with karma: 225 on 2017-11-21

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by gvdhoorn on 2017-11-22:\

I found another way of solving it

please clearly emphasise that this is a work-around, not a solution. Renaming package manager / system installed directories and editing files like this is not recommended and very brittle: updated pkgs will overwrite / undo your changes.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.