Ask Your Question
0

Linking opencv_video for CamShift

asked 2015-09-03 13:39:52 -0600

Ed C. gravatar image

From a ROS and CMake newbie.

I'm getting the following error which I believe to be a linking problem.

    Built target follow_generate_messages_lisp
   Built target follow_generate_messages_eus
    Scanning dependencies of target follow_generate_messages
    [100%] Built target follow_generate_messages
    /home/eepp/catkin_ws/src/follow/src/cam_shift_tracker.cpp: In member function ‘void CamShaftTracker::imageCallback(const ImageConstPtr&)’:
    /home/eepp/catkin_ws/src/follow/src/cam_shift_tracker.cpp:272:33: error: ‘CamShift’ is not a member of ‘cv’
          cv::RotatedRect trackBox = cv::CamShift(my_backproject, trackWindow,
                                     ^
    make[2]: *** [follow/CMakeFiles/cam_shift_tracker.dir/src/cam_shift_tracker.cpp.o] Error 1
    make[1]: *** [follow/CMakeFiles/cam_shift_tracker.dir/all] Error 2
    make: *** [all] Error 2
    Invoking "make -j4 -l4" failed

The source code is adapted from camshiftdemo.cpp which I found in the OpenCV version 2.4 samples. It compiles and executes fine stand alone. This is the code snippet as I've adapted it to my ROS follow application.

   cv::calcBackProject( &my_hue, 1, 0, my_histogram, my_backproject, &phranges);
       my_backproject &= my_mask;
   cv::RotatedRect trackBox = cv::CamShift(my_backproject, trackWindow,
              cv::TermCriteria (CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ));

In the stand alone demo code compiling it was a simple matter of linking libopencv_video.so. I can't figure out how to do that with catkin. (I'm currently porting some previous work in Electric to Jade). I've tried things like adding the following to package.xml:

  <build_depend>opencv_video</build_depend>

and the following plus other things to CMakeLists.txt:

catkin_package(
#  INCLUDE_DIRS include
LIBRARIES opencv_video
#  CATKIN_DEPENDS roscpp rospy std_msgs
DEPENDS opencv_video
)

add_executable(cam_shift_tracker src/cam_shift_tracker.cpp)
target_link_libraries(cam_shift_tracker
  ${catkin_LIBRARIES} 
  ${OpenCV_LIBRARIES}
  opencv_video
)

Your help with this endeavor to keep a retired engineer's mind agile by stretching it with new skills is appropriated. I learn by doing so I need to see the code before I can connect the dots with tutorials I've read. So I'm sure I've run across the solution but haven't recognized it.

I've also seen evidence of a camshift node which makes me believe that if I load the correct package I should be able to do what I'm doing without writing any code. This is something for me to investigate later.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2015-09-04 02:42:49 -0600

gvdhoorn gravatar image

updated 2015-09-04 02:51:35 -0600

This is not a linking problem, but a compilation error. The compiler reports that it 'believes' that CamShift is not a member of the cv namespace. That can happen if you did not #include <..> the relevant headers, or if the class is really not declared to be in that namespace.

Linker errors are generally of the form can't resolve symbol for .. etc.

The source code is adapted from camshiftdemo.cpp which I found in the OpenCV version 2.4 samples. It compiles and executes fine stand alone. This is the code snippet as I've adapted it to my ROS follow application.

Have you checked to make sure your include path is setup correctly? Can you update your question (use the edit link/button) with the contents of your CMakeLists.txt (please remove all the boilerplate comments first)?


Edit:

I've also seen evidence of a camshift node which makes me believe that if I load the correct package I should be able to do what I'm doing without writing any code. This is something for me to investigate later.

I think you're referring to the opencv_apps package, part of vision_opencv.

edit flag offensive delete link more

Comments

Thanks - I immediately found the error. I missed the include for opencv2/video/tracking.hpp.

I have no excuse for that oversight. I misread the error message and was sloppy when I moved the code over. My apologies.

Ed C. gravatar imageEd C. ( 2015-09-04 11:37:08 -0600 )edit

No problem, happens to all of us.

Also: here on ROS Answers it's a bit different from a forum: use comments to interact with answer authors. Only post an answer to answer the question. Thanks.

gvdhoorn gravatar imagegvdhoorn ( 2015-09-04 11:54:38 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-09-03 13:39:52 -0600

Seen: 336 times

Last updated: Sep 04 '15