Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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.

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

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="">".

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

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.

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

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." 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!

click to hide/show revision 3
None

updated 2020-07-21 00:52:52 -0600

berak gravatar image

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

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)’:
char**)’:
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:33:9: error: ‘Tracker’ was not declared in this scope
33 | Ptr<tracker> Ptr<Tracker> tracker;
| ^~~~~~~
/home/sydney/Desktop/projects/Leaf_Tracking_cpp/tracker.cpp:33:16: error: template argument 1 is invalid
33 | Ptr<tracker> 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

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="">" #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="">".#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" `-lopencv_aruco` flag will be added." added."

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!

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

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!

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

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 build tool:            /usr/bin/gmake
    Configuration:               Release

  CPU/HW features:
Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (14 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX

  C/C++:
    Built as dynamic libs?:      NO
    C++ Compiler:                /usr/lib/ccache/compilers/c++  (ver 4.8.2)
    C++ flags (Release):         -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=s -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/lib/ccache/compilers/cc
    C flags (Release):           -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wuninitialized -Winit-self -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wuninitialized -Winit-self -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -L/root/ffmpeg_build/lib  -Wl,--gc-sections  
    Linker flags (Debug):        -L/root/ffmpeg_build/lib  -Wl,--gc-sections  
    ccache:                      YES
    Precompiled headers:         NO
    Extra dependencies:          ade /opt/Qt4.8.7/lib/libQtGui.so /opt/Qt4.8.7/lib/libQtTest.so /opt/Qt4.8.7/lib/libQtCore.so /lib64/libz.so dl m pthread rt
    3rdparty dependencies:       ittnotify libprotobuf libjpeg-turbo libwebp libpng libtiff libjasper IlmImf quirc

  OpenCV modules:    
To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto    
Disabled:                    world
 Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java js matlab ovis python2 sfm ts viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  GUI: 
    QT:                          YES (ver 4.8.7 EDITION = OpenSource)
      QT OpenGL support:         NO
    GTK+:                        NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /lib64/libz.so (ver 1.2.3)
    JPEG:                        libjpeg-turbo (ver 2.0.2-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES
      avcodec:                   YES (58.65.103)
      avformat:                  YES (58.35.101)
      avutil:                    YES (56.38.100)
      swscale:                   YES (5.6.100)
avresample:                NO
    GStreamer:                   NO
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            pthreads

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       NO   
Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (no extra features)
    Include path:                /io/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

Python 3:
    Interpreter:                 /opt/python/cp36-cp36m/bin/python (ver 3.6.10)
    Libraries:                   libpython3.6m.a (ver 3.6.10)
    numpy:                       /opt/python/cp36-cp36m/lib/python3.6/site-packages/numpy/core/include (ver 1.11.3)
  install path:                python

  Python (for build):            /opt/python/cp36-cp36m/bin/python
  Java:                          
    ant:                        NO
    JNI:                        NO
    Java wrappers:      NO
    Java tests:             NO

  Install to:                    /io/_skbuild/linux-x86_64-3.6/cmake-install
----------------------------------------------------------------