0

I'm trying to compile Gall and Lempitsky's Hough forest implementation written for opencv.

It can be downloaded from their website here [mirrors].

It looks like it's having issues finding opencv. I installed opencv 2.3.1 (or 2.4.4 I'm not sure) on ubuntu using sudo apt-get install libopencv-dev opencv-doc and I can compile and run the examples in /usr/share/doc/opencv-doc/examples

I changed the make file paths as follows:

# 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

and the errors I get when I run make all are:

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

What do I need to change so that g++ sees the necessary libraries? How would I check if the required libraries are installed?


EDIT:

this is the output of pkg-config --modversion opencv: 2.4.4

this is the output of /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

and the output of /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

are all the files I need here or am I missing something?


EDIT 2:

changed my includes and libs to the following as suggested:

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

which results in the following output:

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'
...
waspinator
  • 6,464
  • 11
  • 52
  • 78

2 Answers2

2

I've manged to compile with the following paths:

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

Note that I'm on OSX, not linux, but using the path to the explicit library files worked. Note that on osx the compiled libraries are .dylib files while on linux probably .so or .a and the paths are slightly different so you might want to try something like:

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

UPDATE I've installed Ubuntu 12 on a virtual machine and compiled OpenCV 2.4.4 from source and noticed this:

  1. OpenCV installed headers in /usr/local/include and libs in /usr/local/lib by default (like on OSX)
  2. I ran into the exact errors as you posted. I did not expect that as I though those classes are defined in the core library.

The main problem seems to be the order in which compiled libraries are linked. I found some handy details in this question and answer. Using the information I've updated this part of the makefile:

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

like so:

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

This worked and I've managed to compile on Ubuntu/Linux.

Good news is: make all worked Bad news is: I've never used pkg-config before but it seems to nicely output the right paths. Even so, when I run ./CRForest-Detector I get an error finding the opencv libraries which I don't fully understand. I'm guessing you can find some useful advice here and here

In conclusion: use the pkg-config option in the make file as this will be the solution this problem (compiling the application).

Community
  • 1
  • 1
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • hmm, I tried both .so and .a files and still doesn't want to go. I edited my question with the output of the opencv files I have. Does it look like I have everything I need? Thanks. – waspinator Mar 20 '13 at 01:34
  • 1
    `ls /usr/local/include/opencv` prints `cv.h cvaux.hpp cxcore.hpp highgui.h cv.hpp cvwimage.h cxeigen.hpp ml.h cvaux.h cxcore.h cxmisc.h ` so that's all good. `LIBS = /usr/lib/libopencv_core.so /usr/lib/libopencv_highgui.so /usr/lib/libopencv_imgproc.so` should work. Note that it's the full absolute path and I'm not using `-l`. I presume core would have Mat/IplImage/etc. types, highui utilities like imread/imwrite/imshow/etc. and imgproc masking and other common filters. Did the errors change ? Also.... – George Profenza Mar 20 '13 at 11:54
  • 1
    ...I'm not sure if it will make a difference, but I noticed most errors are from: `cvLoadImage ` etc. which I presume might be in the core library. Can you try to link against libopencv_core.so first ? (Your original link list (`-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`) starts with calib3d, so I'm presuming you grabbed them all alphabetically.) HTH – George Profenza Mar 20 '13 at 11:56
  • 1
    @waspinator any joy compiling on linux ? – George Profenza Mar 24 '13 at 21:20
  • 1
    can you post the make output when you use `LIBS = /usr/lib/libopencv_core.so /usr/lib/libopencv_highgui.so /usr/lib/libopencv_imgproc.so` ? – George Profenza Mar 26 '13 at 15:42
  • I updated my question with the output. it doesn't seem to have changed. Maybe I don't have opencv installed correctly. Is there any easy way to check? – waspinator Mar 26 '13 at 16:28
  • 1
    @waspinator I'm not sure why those cv functions can't be found in the linked libraries. My output looks like so:`hm:forest hm$ make all g++ -c -I/usr/local/include/opencv CRForest-Detector.cpp -O3 -Wno-deprecated g++ -c -I/usr/local/include/opencv CRPatch.cpp -O3 -Wno-deprecated g++ -c -I/usr/local/include/opencv HoG.cpp -O3 -Wno-deprecated g++ -c -I/usr/local/include/opencv CRForestDetector.cpp -O3 -Wno-deprecated g++ -c -I/usr/local/include/opencv CRTree.cpp -O3 -Wno-deprecated -Wno-deprecated `... – George Profenza Mar 30 '13 at 15:58
  • 1
    continued: `g++ -L/usr/local/lib /usr/local/lib/libopencv_core.dylib /usr/local/lib/libopencv_highgui.dylib /usr/local/lib/libopencv_imgproc.dylib -o CRForest-Detector CRForest-Detector.o CRPatch.o HoG.o CRForestDetector.o CRTree.o -O3 -Wno-deprecated echo all: make complete all: make complete` – George Profenza Mar 30 '13 at 15:58
  • 1
    @waspinator Managed to compile on ubuntu, updated answer so for the scope of this question if think this wraps it up. Still, look at the links provided to move forward after compilation. Feel to vote/mark as you see fit ;) Goodluck! – George Profenza Apr 02 '13 at 17:47
  • Thanks for your persistent help. I will try moving on from your explanation, and if that doesn't work, just buy a Mac. They really are easier I guess. – waspinator Apr 03 '13 at 17:02
1

I have been working on running CRFOREST in Ubuntu machine for 7 months. Here are some suggestions:

for Makefile:

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

NOTE: Please put $(LIBS) at the end, otherwise, I would suggest you re-install the package opencv in Ubuntu following a proper configuration guide.

slm
  • 15,396
  • 12
  • 109
  • 124
JoOOoL
  • 11
  • 2