0

I tried adding the FaceRecognition wrapper for Opencv in java after this example. I had some issues since I'm trying to do this on Ubuntu, but I was able to create the .so file in the end.

Still I can't use it since I get the error:

/usr/lib/jvm/java-7-openjdk-amd64/bin/java: symbol lookup error: /home/vlad/workspace/HelloJNI/jni/libRecognizer.so: undefined symbol: _ZN2cv24createLBPHFaceRecognizerEiiiid

My makefile looks like this:

# Define a variable for classpath
CLASS_PATH = ../bin

# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)

all : libRecognizer.so

# $@ matches the target, $< matches the first dependancy
libRecognizer.so : facerec.cpp
    g++ -fPIC -o $@ -shared -Wl,-rpath, -I"/usr/lib/jvm/java-7-openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" $<
    #cc -fPIC -I"/usr/lib/jvm/java-7-openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" -Wl, -shared -o $@ 

# $@ matches the target, $< matches the first dependancy
#HelloJNI.o : HelloJNI.c HelloJNI.h
#   gcc -m64 -I"/usr/lib/jvm/java-7-openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" -c $< -o $@

# $* matches the target filename without the extension
LBPHFaceRecognizer.h : LBPHFaceRecognizer.class
    javah -classpath $(CLASS_PATH):../jni/opencv-249.jar $*

clean :
    rm LBPHFaceRecognizer.h LBPHFaceRecognizer.o libRecognizer.so

I tried "ldd" and "libopencv_java249.so" seems to be there:

vlad@woow-1022:~/workspace/HelloJNI/jni$ ldd libRecognizer.so 
    linux-vdso.so.1 =>  (0x00007fff969fe000)
    /home/vlad/workspace/HelloJNI/jni/libopencv_java249.so (0x00007fb24797a000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb247658000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb247441000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb24723d000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb24701f000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb246e16000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb246b10000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb24674a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fb248ed1000)

So I really don't know what to try next...

UPDATE:

I ended up doing something like this in the terminal:

g++ -L/usr/lib/jni -fPIC -o libRecognizer.so -shared -Wl,-rpath, -I"/usr/lib/jvm/java-7-openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" facerec.cpp -lopencv_java249

so for /usr/lib/jni/libopencv_java249.so I had to add -L/usr/lib/jni and -lopencv_java249

Community
  • 1
  • 1
colegu
  • 370
  • 2
  • 12
  • the method is not exported to the java wrappers at all (known problem). you will have to add jni code for that, and another wrapper class calling it – berak Sep 09 '14 at 06:05
  • FYI, an easy to use wrapper comes prebuilt with the [JavaCPP Presets](https://github.com/bytedeco/javacpp-presets/): http://bytedeco.org/javacpp-presets/opencv/apidocs/org/bytedeco/javacpp/opencv_contrib.FaceRecognizer.html – Samuel Audet Sep 09 '14 at 06:39
  • ^^^ yea, that's javacv, not opencv's own wrappers. – berak Sep 11 '14 at 21:21

1 Answers1

0

I ended up doing something like this in the terminal:

g++ -L/usr/lib/jni -fPIC -o libRecognizer.so -shared -Wl,-rpath, -I"/usr/lib/jvm/java-7-openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" facerec.cpp -lopencv_java249
colegu
  • 370
  • 2
  • 12
  • no it doesn't, after I added -L/usr/lib/jni and -lopencv_java249 it worked, there was no more symbol lookup error, it seems the problem was that I was not linking my .so to libopencv_java249.so – colegu Sep 11 '14 at 21:28