我正在使用支持人脸识别的2.4.7版opencv。但是我收到以下错误:
/home/fereres/recognition-build-desktop- Qt_4_8_1_in_PATH__System__Release/../recognition/program.cpp:58: error: 'FaceRecognizer' was not declared in this scope
编辑: 该程序正在运行,因为我刚刚更换计算机。我按照相同的说明安装了OpenCV。什么可能导致该错误?我的QT专业文件如下:
QT += core
QT -= gui
TARGET = identification
CONFIG += console/home/fereres/projectCV-build-desktop- Qt_4_8_1_in_PATH__System__Release
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /home/fereres/Desktop/OpenCV/opencv-2.4.7/include/opencv \
INCLUDEPATH += /home/fereres/Desktop/OpenCV/opencv-2.4.7/include/opencv2 \
INCLUDEPATH += /home/fereres/Desktop/OpenCV/opencv-2.4.7/modules/core/include/opencv2/core
LIBS += -L/home/fereres/Desktop/OpenCV/opencv-2.4.7/build/lib \
-lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_ml \
-lopencv_video \
-lopencv_features2d \
-lopencv_calib3d \
-lopencv_objdetect \
-lopencv_contrib \
-lopencv_legacy \
-lopencv_flann
SOURCES += \
program.cpp \
prediction.cpp \
Detection.cpp
HEADERS += \
prediction.h \
Detection.h
编译出来没有错误。但是,当我运行我的应用程序时,我得到了
./identification: error while loading shared libraries: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
fereres@ubuntu:~/identification-build-desktop-Qt_4_8_1_in_PATH__System__Release$
/ usr / local / lib forlder只包含一个我无法在那里找到我的库的python文件夹。
EDIT2: 我再次安装opencv,现在一切正常。我想安装opencv的最后一步没有用,所以我的/ usr / local文件夹是空的。现在一切都在掌控之中。
答案 0 :(得分:2)
最好将INCLUDEPATH
初始化调整为以下内容,否则在路径开头引用 opencv2 的每个#include
语句都会导致编译错误:
INCLUDEPATH += "/home/fereres/Desktop/OpenCV/opencv-2.4.7/include" \
"/home/fereres/Desktop/OpenCV/opencv-2.4.7/include/opencv" \
"/home/fereres/Desktop/OpenCV/opencv-2.4.7/include/opencv2" \
"/home/fereres/Desktop/OpenCV/opencv-2.4.7/modules/core/include/opencv2/core"
然后,在recognition/program.cpp
,不要忘记包含相应的头文件:
#include <opencv2/contrib/contrib.hpp>
注意:由于您使用 pkg-config 添加所有OpenCV库,因此您无需执行此操作,但对于那些单独指定库的人员,你们需要将 opencv_contrib 添加到LIBS
。