OpenCV 2.4.13 error: ‘Moments’ in namespace ‘cv’ does not name a type

时间:2017-06-15 09:35:21

标签: c++ opencv codeblocks

I'm a beginner in using OpenCV and I get this error when I try to compile my main.cpp-file (among many other errors):

enter image description here

enter image description here

I do not know what I'm doing wrong here. I downloaded OpenCV 2.4.13 zip-file, extracted it into my project folder (see the image) and included the cv.h-file into my main.cpp. What do I need to do? What causes this problem?

I'm using Ubuntu 14.04 LTS, Codeblocks 13.12.

1 个答案:

答案 0 :(得分:1)

According to the error messages, you are mixing the local OpenCV instance headers (/home/jjepoh/Document/codeblocks_workspace/opencv/opencv-2.4.13/include/opencv) with the system-wide instance (/usr/local/include/opencv2/).

The system-wide instance is probably a different version, and because the local instance most likely uses "#include <opencv/xxx.h>" for inclusion of dependent headers, the system-wide location is selected in preference. So at the end you get a mixture of two different versions of OpenCV, which apparently doesn't work.

There are basically two (or three) possibilities to fix:

  1. Install the new version system-wide.
  2. Remove the different system-wide version (probably an opencv devel package).
  3. Not use the new version and use the system-wide version installed in the system.