对某些 opencv 函数的未定义引用

undefined reference to some of the opencv functions

我正在尝试在 Ubuntu 14.04 环境中编译 opencv 示例附带的 'motemple.c'。我认为 opencv 已经正确安装;大多数程序都符合预期 运行。但是,在编译上述文件时,多个函数会出现错误 "undefined reference"。下面是编译的输出:

Building target: ACTION_detection1
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "ACTION_detection1"  ./opencvexample/MotionSegmentation.o   -lopencv_core -lopencv_photo -lopencv_videoio -lopencv_videostab -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
./opencvexample/MotionSegmentation.o: In function `update_mhi':
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:103: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:105: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:114: undefined reference to `cvCalcMotionGradient'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:123: undefined reference to `cvSegmentMotion'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:149: undefined reference to `cvCalcGlobalOrientation'
collect2: error: ld returned 1 exit status
make: *** [ACTION_detection1] Error 1

可以看出,我已经将所有的opencv库链接到mu Eclipse项目中。我也尝试了here提供的命令行解决方案,但仍然得到同样的错误。

它们已从主存储库替换到 opencv_contrib。您可以在 optflow 模块中找到它们。

注意:cvUpdateMotionHistorycvCalcMotionGradient等是OpenCV1.xAPI函数的名称,现在是obsoleted/outdated所以尽量避免将它们替换为 cv::updateMotionHistorycv::calcMotionGradient