0

我正在尝试编译为 opencv 编写的 Gall 和 Lempitsky 的 Hough 森林实现。

它可以从他们的网站[mirrors]下载

看起来它在查找 opencv 时遇到了问题。我在 ubuntu 上安装了 opencv 2.3.1(或 2.4.4,我不确定)sudo apt-get install libopencv-dev opencv-doc,我可以编译和运行示例/usr/share/doc/opencv-doc/examples

我更改了make文件路径如下:

# change paths if necessary
# INCLUDES = -I/usr/pack/opencv-1.0.0-dr/amd64-debian-linux4.0/include/opencv
# LIBS = -lcxcore -lcv -lcvaux -lhighgui -lml
# LIBDIRS = -L/usr/pack/opencv-1.0.0-dr/amd64-debian-linux4.0/lib

INCLUDES = -I/usr/include/opencv
LIBS = -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
LIBDIRS = -L/usr/lib

我运行时遇到的错误make all是:

g++ -c -I/usr/include/opencv CRForest-Detector.cpp -O3 -Wno-deprecated
CRForest-Detector.cpp: In function ‘void run_train()’:
CRForest-Detector.cpp:543:27: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
CRForest-Detector.cpp: In function ‘void run_detect()’:
CRForest-Detector.cpp:521:27: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
g++ -c -I/usr/include/opencv CRPatch.cpp -O3 -Wno-deprecated
g++ -c -I/usr/include/opencv HoG.cpp -O3 -Wno-deprecated
g++ -c -I/usr/include/opencv CRForestDetector.cpp -O3 -Wno-deprecated
g++ -c -I/usr/include/opencv CRTree.cpp -O3 -Wno-deprecated
g++ -L/usr/lib -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 -o CRForest-Detector CRForest-Detector.o CRPatch.o HoG.o CRForestDetector.o CRTree.o -O3 -Wno-deprecated
CRForest-Detector.o: In function `detect(CRForestDetector&)':
CRForest-Detector.cpp:(.text+0x3340): undefined reference to `cvLoadImage'
CRForest-Detector.cpp:(.text+0x34a3): undefined reference to `cvCreateImage'
CRForest-Detector.cpp:(.text+0x357b): undefined reference to `cvCreateImage'
CRForest-Detector.cpp:(.text+0x35d9): undefined reference to `cvConvertScale'
CRForest-Detector.cpp:(.text+0x3620): undefined reference to `cvSaveImage'
CRForest-Detector.cpp:(.text+0x3634): undefined reference to `cvReleaseImage'
...

我需要更改什么以便 g++ 看到必要的库?如何检查是否安装了所需的库?


编辑:

这是输出pkg-config --modversion opencv:2.4.4

这是的输出/usr/lib$ ls | grep "opencv"

libopencv_calib3d.a
libopencv_calib3d.so
libopencv_calib3d.so.2.3
libopencv_calib3d.so.2.3.1
libopencv_contrib.a
libopencv_contrib.so
libopencv_contrib.so.2.3
libopencv_contrib.so.2.3.1
libopencv_core.a
libopencv_core.so
libopencv_core.so.2.3
libopencv_core.so.2.3.1
libopencv_features2d.a
libopencv_features2d.so
libopencv_features2d.so.2.3
libopencv_features2d.so.2.3.1
libopencv_flann.a
libopencv_flann.so
libopencv_flann.so.2.3
libopencv_flann.so.2.3.1
libopencv_gpu.a
libopencv_gpu.so
libopencv_gpu.so.2.3
libopencv_gpu.so.2.3.1
libopencv_highgui.a
libopencv_highgui.so
libopencv_highgui.so.2.3
libopencv_highgui.so.2.3.1
libopencv_imgproc.a
libopencv_imgproc.so
libopencv_imgproc.so.2.3
libopencv_imgproc.so.2.3.1
libopencv_legacy.a
libopencv_legacy.so
libopencv_legacy.so.2.3
libopencv_legacy.so.2.3.1
libopencv_ml.a
libopencv_ml.so
libopencv_ml.so.2.3
libopencv_ml.so.2.3.1
libopencv_objdetect.a
libopencv_objdetect.so
libopencv_objdetect.so.2.3
libopencv_objdetect.so.2.3.1
libopencv_video.a
libopencv_video.so
libopencv_video.so.2.3
libopencv_video.so.2.3.1

和输出/usr/include/opencv$ ls | grep ''

cvaux.h
cvaux.hpp
cv.h
cv.hpp
cvwimage.h
cxcore.h
cxcore.hpp
cxeigen.hpp
cxmisc.h
highgui.h
ml.h

是我需要的所有文件还是我遗漏了什么?


编辑2:

按照建议将我的包含和库更改为以下内容:

INCLUDES = -I/usr/include/opencv
LIBS = /usr/lib/libopencv_core.so /usr/lib/libopencv_highgui.so /usr/lib/libopencv_imgproc.so
LIBDIRS = -L/usr/lib

这导致以下输出:

user@user:~/Code/hough_forest$ make clean
rm -f *.o *~ CRForest-Detector
user@user:~/Code/hough_forest$ make all
g++ -c -I/usr/include/opencv CRForest-Detector.cpp -O3 -Wno-deprecated
CRForest-Detector.cpp: In function ‘void run_train()’:
CRForest-Detector.cpp:543:27: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
CRForest-Detector.cpp: In function ‘void run_detect()’:
CRForest-Detector.cpp:521:27: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
g++ -c -I/usr/include/opencv CRPatch.cpp -O3 -Wno-deprecated
g++ -c -I/usr/include/opencv HoG.cpp -O3 -Wno-deprecated
g++ -c -I/usr/include/opencv CRForestDetector.cpp -O3 -Wno-deprecated
g++ -c -I/usr/include/opencv CRTree.cpp -O3 -Wno-deprecated
g++ -L/usr/lib /usr/lib/libopencv_core.so /usr/lib/libopencv_highgui.so /usr/lib/libopencv_imgproc.so -o CRForest-Detector CRForest-Detector.o CRPatch.o HoG.o CRForestDetector.o CRTree.o -O3 -Wno-deprecated
CRForest-Detector.o: In function `detect(CRForestDetector&)':
CRForest-Detector.cpp:(.text+0x3a87): undefined reference to `cvLoadImage'
CRForest-Detector.cpp:(.text+0x3b9e): undefined reference to `cvCreateImage'
CRForest-Detector.cpp:(.text+0x3c61): undefined reference to `cvCreateImage'
CRForest-Detector.cpp:(.text+0x3cae): undefined reference to `cvConvertScale'
CRForest-Detector.cpp:(.text+0x3d03): undefined reference to `cvSaveImage'
CRForest-Detector.cpp:(.text+0x3d12): undefined reference to `cvReleaseImage'
CRForest-Detector.cpp:(.text+0x3d39): undefined reference to `cvReleaseImage'
CRForest-Detector.cpp:(.text+0x3d67): undefined reference to `cvReleaseImage'
...
4

2 回答 2

1

我已经设法使用以下路径进行编译:

INCLUDES = -I/usr/local/include/opencv
LIBS = /usr/local/lib/libopencv_core.dylib /usr/local/lib/libopencv_highgui.dylib /usr/local/lib/libopencv_imgproc.dylib
LIBDIRS = -L/usr/local/lib

请注意,我使用的是 OSX,而​​不是 linux,但使用显式库文件的路径有效。请注意,在 osx 上编译的库是 .dylib 文件,而在 linux 上可能是 .so 或 .a 并且路径略有不同,因此您可能想尝试以下操作:

INCLUDES = -I/usr/include/opencv
LIBS = /usr/lib/libopencv_core.so /usr/lib/libopencv_highgui.so /usr/lib/libopencv_imgproc.so
LIBDIRS = -L/usr/lib

更新 我已经在虚拟机上安装了 Ubuntu 12 并从源代码编译了 OpenCV 2.4.4 并注意到了这一点:

  1. OpenCV/usr/local/include在默认情况下安装了头文件和库/usr/local/lib(如在 OSX 上)
  2. 正如您发布的那样,我遇到了确切的错误。我没想到这些类是在核心库中定义的。

主要问题似乎是编译库的链接顺序。我在这个问题和答案中找到了一些方便的细节。使用我更新了makefile的这一部分的信息:

CRForest-Detector: $(OBJS)
        $(CC) $(LIBDIRS) $(LIBS) -o $@ $+ $(OPT)

像这样:

CRForest-Detector: $(OBJS)
        $(CC) -o $@ $+ $(OPT) `pkg-config opencv --cflags --libs`

这很有效,我已经设法在 Ubuntu/Linux 上进行编译。

好消息是:make all工作 坏消息是:我以前从未使用过 pkg-config,但它似乎很好地输出了正确的路径。即便如此,当我运行 ./CRForest-Detector 时,我在查找我不完全理解的 opencv 库时遇到错误。我猜你可以在这里这里找到一些有用的建议

总之:使用pkg-configmake 文件中的选项,因为这将解决这个问题(编译应用程序)。

于 2013-03-19T20:58:02.550 回答
0

我已经在 Ubuntu 机器上运行 CRFOREST 7 个月了。以下是一些建议:

对于 Makefile:

 CRForest-Detector: $(OBJS)
                    $(CC) $(LIBDIRS) -o $@ $+$(OPT) $(LIBS)

注意:请将 $(LIBS) 放在最后,否则,我建议您按照正确的配置指南在 Ubuntu 中重新安装软件包 opencv。

于 2013-04-16T02:21:22.127 回答