1

我想用 CodeBlocks 或 Linux 终端编译以下 OpenCV 程序。

http://plaza.ufl.edu/tyler727/imdl/src/eigenface.cpp

    line 57:   nTrainFaces = loadFaceImgArray("/home/hacker/data/Eigenfacecpp/train.txt");

    line 192: // load test images and ground truth for person number
             nTestFaces = loadFaceImgArray("/home/hacker/data/Eigenfacecpp/test.txt");

    // project the training images onto the PCA subspace
    projectedTrainFaceMat = cvCreateMat(nTrainFaces, nEigens, CV_32FC1);
    for(i=0; i<nTrainFaces; i++)
    {
        cvEigenDecomposite(faceImgArr[i],
                           nEigens,
                           eigenVectArr,
                           0, 0,
                           pAvgTrainImg,
line 78:                    projectedTrainFaceMat->data.fl + i*nEigens);
    }

     cvCalcEigenObjects(nTrainFaces,
                        (void*)faceImgArr,
                        (void*)eigenVectArr,
                        CV_EIGOBJ_NO_CALLBACK,
                        0,
                        0,
                        &calcLimit,
                        pAvgTrainImg,
line 154:                eigenValMat->data.fl);

        //project the test image onto the PCA subspace
        cvEigenDecomposite(faceImgArr[i],
                           nEigens,
                           eigenVectArr,
                           0, 0,
                           pAvgTrainImg,
line 211:                   projectedTestFace);

我得到了这些错误:

Compiling: eigenface.cpp

In Function »void learn()«:
line 57:  deprecated conversion from string constant to ‘char*’ [Wwrite-strings]

In Function »double recognize()«:
line 192: deprecated conversion from string constant to ‘char*’ [Wwrite-strings]

/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
obj/Debug/eigenface.o: In function `learn()':
/home/hacker/data/Eigenfacecpp/eigenface.cpp:78: undefined reference to `cvEigenDecomposite'

obj/Debug/eigenface.o: In function `doPCA()':
/home/hacker/data/Eigenfacecpp/eigenface.cpp:154: undefined reference to `cvCalcEigenObjects'

obj/Debug/eigenface.o: In function `recognize()':
/home/hacker/data/Eigenfacecpp/eigenface.cpp:211: undefined reference to `cvEigenDecomposite'

我不明白我做错了什么。我认为这是愚蠢的,但我找不到它。

来自 CodeBlocks 的编译器和调试器设置:

链接器设置->其他选项:-lopencv_core -lopencv_objdetect -lopencv_imgproc-lopencv_highgui

搜索目录->编译器:/usr/local/include/opencv 搜索目录->链接器:/usr/lib

我在这里做错了什么?请帮我解决这个问题。

4

3 回答 3

0
  1. 您的源代码不包含main()函数,因此请从http://plaza.ufl.edu/tyler727/imdl/src/main.cppmain.cpp下载文件并将其放在您的项目目录中,或者取消注释eigenface.cpp 甚至可能编写自己的函数。main()main()
  2. 使用 opencv 的链接器选项的完整列表是:-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab当然,您可能不需要所有这些库,但它不会受到伤害,因为链接器足够智能并且只会包含您实际引用的库。
  3. 从命令行,您可以使用包含 OpenCV 标头的目录和包含所有库文件的目录发出g++ main.cpp eigenface.cpp -o eigenface -I/usr/include/opencv -L/usr/lib <all linker flags in "2">替换。如果您使用发行版的包管理器(例如 apt-get 或 yum)来安装 OpenCV,这些可能是默认位置。 /usr/inlude/opencv/usr/lib
于 2013-04-12T13:28:38.633 回答
0

查找 /usr/lib -name 'libopencv*.so' | xargs readelf -s | egrep "FUNCTION_NAME|libop" find /usr/lib -name 'libopencv*.so' | xargs readelf -s | egrep "cvEigenDecomposite|libop"

文件:./libopencv_legacy.so 680: 00000000000936f0 1046 FUNC GLOBAL DEFAULT 11 cvEigenDecomposite 所以与'libopencv_legacy.so'链接
-lopencv_legacy

于 2013-09-12T19:54:51.327 回答
0

从http://plaza.ufl.edu/tyler727/imdl/Lovelly_FCRAR12.pdf查看参考文献 [3] 和 [4]

于 2014-03-12T03:15:22.203 回答