Ask Your Question
0

How to compile old OpenCV code using 2.4.9

asked 2014-07-07 14:13:49 -0600

adin gravatar image

updated 2014-07-08 11:29:26 -0600

I'm trying to compile some old code of OpenCV that I found here.

However, the code seems quite old. I was able to compile it by adding the new headers

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

to the files global.h and IntImage.h, with addition of

#include <opencv/cv.h>

to the IntImage.h.

Note that I don't want to port all the code to OpenCV 2.4.9 right now, but rather to make it work. Thus, once that compile I still obtain the error:

UIUCscene.o: In function IntImage<double>::Load(std::string const&)': UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x20): undefined reference tocvLoadImage' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x53): undefined reference to cvCreateImage' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x6b): undefined reference tocvCvtColor' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x78): undefined reference to cvReleaseImage' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x73c): undefined reference to cvReleaseImage' collect2: error: ld returned 1 exit status make: * [place] Error 1

It seems to me that the problem is linking. However, I'm not sure where the problem is. In the Makefile the flags are set using pkg-config --cflags opencv, and the same for retrieving the libraries. The result of running pkg-config --libs opencv is

/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -ltbb -lrt -lpthread -lm -ldl

as you can see, the legacy library is there.

What am I missing? Any help or pointers are appreciated.

edit retag flag offensive close merge delete

Comments

1

These are all linking errors. You need to specify the legacy linking libraries. Somehow, they are not being picked.

unxnut gravatar imageunxnut ( 2014-07-07 17:30:51 -0600 )edit
2

Actually before you go and dig deeper into fixing all these problems with temporary solutions, try defining how long it would take to replace stuff to the new C++ interface. That will guarantee future working of the complete code. There are like 8 sourcecode files, it should be possible to fix the code to the new interface in a day or so!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-08 04:35:09 -0600 )edit

As to solving your problem, make sure your include directories know the opencv/ and the opencv2/ header file location!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-08 04:35:58 -0600 )edit

For the linking I'm using pkg-config --cflags opencv and pkg-config --libs opencv. The latter includes the legacy libopencv_legacy.so. But still gives me error. I build OpenCV myself, should I need some special flag to build legacy?

adin gravatar imageadin ( 2014-07-08 08:30:53 -0600 )edit

Just a thought. sos are shared objects and the way you have them specified, the code should compile. But do you also happen to have static libraries (extension lib)? If so, can you try to manually link against those?

unxnut gravatar imageunxnut ( 2014-07-08 12:40:51 -0600 )edit

@unxnut I don't have other libraries. Just the ones I posted using the pkg-config. I don't understand why is not finding the symbols. Searching the web I found that there were some errors with the pkg-config of previous OpenCV releases. Not sure if that is the problem though.

adin gravatar imageadin ( 2014-07-08 13:00:57 -0600 )edit
1

How about trying to link manually against the shared objects?

unxnut gravatar imageunxnut ( 2014-07-08 13:14:01 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-07-09 14:23:09 -0600

adin gravatar image

Ok, finally the error was two fold in order to compile for the old OpenCV functions.

First, the problem is the use of old headers, so I changed the #include <opencv/cv.h> and use

#include <opencv2/legacy/legacy.hpp>
#include "opencv2/legacy/compat.hpp"

in my header files that included old headers.

Then, the makefile was wrong. It seems that to compile and link the linking libraries can only be in the last parameters of the call.

That is, g++ <flags> -o <target> <sources> <libs>, after fixing that order the files compile. I made a newer makefile, just in case someone stumble upon the same or similar problem.

CC=g++
CFLAGS=-Wall $(shell pkg-config --cflags opencv)
LDLIBS=$(shell pkg-config --libs opencv) 

all: main

# the main program, it uses the .o objects to rebuild
main: main.o global.o IntImage.h util.o mdarray.h
    $(CC) $(CFLAGS) -o main main.o global.o util.o $(LDLIBS)

# a target for all the objects
# it doesn't link (-c option)
%.o: %.cpp
    $(CC) $(CFLAGS) -c -o $@ $<

clean:
    rm -rf *.o main
edit flag offensive delete link more

Comments

could you accept your own answer ?

berak gravatar imageberak ( 2014-07-10 00:29:15 -0600 )edit

Question Tools

Stats

Asked: 2014-07-07 14:13:49 -0600

Seen: 3,412 times

Last updated: Jul 09 '14