如何编译由Gall和Lempitsky实现的opencv Hough森林实现

时间:2013-03-19 17:33:06

标签: linux opencv

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

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

看起来它在查找opencv时遇到了问题。我使用sudo apt-get install libopencv-dev opencv-doc在ubuntu上安装了opencv 2.3.1(或者我不确定2.4.4),我可以编译并运行/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:

根据建议将我的include和libs更改为以下内容:

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'
...

2 个答案:

答案 0 :(得分: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中安装了libs(如在OSX上)
  2. 我遇到了您发布的确切错误。我没想到,因为我虽然这些类是在核心库中定义的。
  3. 主要问题似乎是编译库链接的顺序。我在this question and answer找到了一些方便的细节。使用这些信息我已经更新了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库时出错。我猜你可以找到一些有用的建议herehere

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

答案 1 :(得分:0)

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

for Makefile:

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

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