Compiling Tracker from tutorial leads to error: ‘Tracker’ was not declared in this scope

asked 2020-07-20 13:57:10 -0600

sydsdk gravatar image

updated 2020-07-29 17:30:02 -0600

Hello, I have been using opencv in python without issues. I am now trying to switch to cpp, which I am new to. I have recently reinstalled opencv and compiled it with opencv_contrib following the instructions in the readme. I am using the tracking features of opencv for my project.

When I go to make my file I get the following error:

/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp: In function ‘int main(int, char**)’:
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:33:9: error: ‘Tracker’ was not declared in this scope
   33 |     Ptr<Tracker> tracker;
      |         ^~~~~~~
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:33:16: error: template argument 1 is invalid
   33 |     Ptr<Tracker> tracker;
      |                ^
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:37:19: error: ‘Tracker’ is not a class, namespace, or enumeration
   37 |         tracker = Tracker::create(trackerType);
      |                   ^~~~~~~
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:76:12: error: ‘selectROI’ was not declared in this scope; did you mean ‘select’?
   76 |     bbox = selectROI(frame, false);
      |            ^~~~~~~~~
      |            select
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:82:12: error: base operand of ‘->’ is not a pointer
   82 |     tracker->init(frame, bbox);
      |            ^~
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:91:26: error: base operand of ‘->’ is not a pointer
   91 |         bool ok = tracker->update(frame, bbox);
      |                          ^~
make[2]: *** [CMakeFiles/tracker.dir/build.make:63: CMakeFiles/tracker.dir/tracker.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/tracker.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I notice that others have had the same error here but its not clear how they were able to get the code to compile.

One thing to note is that when I use #include <opencv2/tracking.hpp> I get an error that it can't find tracking.hpp so I have replaced that line in the sample code with #include <opencv2/video/tracking.hpp>.

Another thing to note is that in step 8 of the opencv_contrib it says to

"to run, linker flags to contrib modules will need to be added to use them in your code/IDE. For example to use the aruco module, `-lopencv_aruco` flag will be added."

Here is my cmake lists file:

cmake_minimum_required(VERSION 3.1)
# Enable C++11
# cmake version 3.13.4
find_package( OpenCV REQUIRED ) #I added this
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
#SET(OpenCV_DIR /home/sydney/Desktop/projects/installation/OpenCV-master/lib/cmake/opencv4)

add_executable( tracker tracker.cpp )
target_link_libraries( tracker ${OpenCV_LIBS} )
target_link_libraries( tracker ${-lopencv_tracking} )

I have put the flag into my cmakeLists.txt file like so: target_link_libraries( tracker ${-lopencv_tracking} ) is this the proper way to link this? I think it is possible I have linked this incorrectly.

Any suggestions on how to solve this would be greatly appreciated! Thank you!

EDIT:

Here is my build info:

'General configuration for OpenCV 4.2.0 
=====================================
Version control:               4.2.0

Extra modules:
    Location (extra):            /io/opencv_contrib/modules
    Version control (extra):     4.2.0

  Platform:
   Timestamp:                   2020-04-04T14:50:03Z   
   Host:                        Linux 4.15.0-1028-gcp x86_64
    CMake:                       3.9.0
    CMake generator:             Unix Makefiles
    CMake ...
(more)
edit retag flag offensive close merge delete

Comments

can you add your cmakeLists.txt to the question, please ?

berak gravatar imageberak ( 2020-07-21 00:54:20 -0600 )edit
1

I have added my cmakeLists.txt to the question above

sydsdk gravatar imagesydsdk ( 2020-07-21 17:15:00 -0600 )edit
  1. it's still a compile problem (nessecary headers not included), not about linking (that comes later)
  2. #include <opencv2 tracking.hpp=""> I get an error that it can't find tracking.hpp so I have replaced that line in the sample code with #include <opencv2 video="" tracking.hpp="">.

no, that's wrong. try harder with <opencv2/tracking.hpp>

berak gravatar imageberak ( 2020-07-22 01:49:13 -0600 )edit

if you can find neither <opencv2/tracking.hpp> nor <opencv2/tracking/tracker.hpp> you have to go back to where you built the opencv libs and check, if the tracking module was built / installed at all.

check cv::getBuildInformation()

berak gravatar imageberak ( 2020-07-23 01:26:52 -0600 )edit
1

I have added my Build information above tracker is in the "to be built" section. Is that correct?

sydsdk gravatar imagesydsdk ( 2020-07-29 17:30:49 -0600 )edit

^^ yep, looks correct

berak gravatar imageberak ( 2020-07-30 01:25:25 -0600 )edit