I use the guide in this link http://stackoverflow.com/questions/22948553/issue-with-writing-facerecognizer-for-java-with-opencv-2-4-8, I use opencv2.4.11.
When I run the makefile, it reports the error with c code,and here is the error I got? What's wrong with the code I have? Do we have some sample code on OpenCV FaceRecognizer JNI part?
gcc -m64 -I"C:\Program Files\Java\jdk1.8.0_40\include" -I"C:\Program Files\Java\jdk1.8.0_40\include\win32" -I"D:\Project\javacv\opencv\opencv\build\include" -I"D:\Project\javacv\opencv\opencv\build\java\x64" -c LBPHFaceRecognizer.c -o LBPHFaceRecognizer.o LBPHFaceRecognizer.c: In function 'Java_com_test_LBPHFaceRecognizer_n_1createLBPHFaceRecognizer': LBPHFaceRecognizer.c:6:1: error: parameter name omitted JNIEXPORT jlong JNICALL Java_com_test_LBPHFaceRecognizer_n_1createLBPHFaceRecognizer(JNIEnv , jclass){ ^ LBPHFaceRecognizer.c:6:1: error: parameter name omitted LBPHFaceRecognizer.c:7:1: error: 'try' undeclared (first use in this function) try { ^ LBPHFaceRecognizer.c:7:1: note: each undeclared identifier is reported only once for each function it appears in LBPHFaceRecognizer.c:7:5: error: expected ';' before '{' token try { ^ makefile:18: recipe for target 'LBPHFaceRecognizer.o' failed make: ** [LBPHFaceRecognizer.o] Error 1
12:16:19 Build Finished (took 1s.633ms)
For java code I have is, package com.test; import org.opencv.contrib.FaceRecognizer;
public class LBPHFaceRecognizer extends FaceRecognizer {
static {
System.loadLibrary("opencv_java248");
System.loadLibrary("facerec");
}
private static native long n_createLBPHFaceRecognizer();
public LBPHFaceRecognizer() {
super(n_createLBPHFaceRecognizer());
}
FaceRecognizer facerec = new LBPHFaceRecognizer();
}
The generate com_test_LBPHFaceRecognizer.h is "/* DO NOT EDIT THIS FILE - it is machine generated / include <jni.h> / Header for class com_test_LBPHFaceRecognizer */
ifndef _Included_com_test_LBPHFaceRecognizer define _Included_com_test_LBPHFaceRecognizer ifdef __cplusplus extern "C" { endif /* * Class: com_test_LBPHFaceRecognizer * Method: n_createLBPHFaceRecognizer * Signature: ()J */ JNIEXPORT jlong JNICALL Java_com_test_LBPHFaceRecognizer_n_1createLBPHFaceRecognizer (JNIEnv *, jclass);
ifdef __cplusplus } endif endif"
The LBPHFaceRecognizer.c I have is, "// facerec.dll include "jni.h" include "opencv2/contrib/contrib.hpp"
JNIEXPORT jlong JNICALL Java_com_test_LBPHFaceRecognizer_n_1createLBPHFaceRecognizer(JNIEnv *, jclass); JNIEXPORT jlong JNICALL Java_com_test_LBPHFaceRecognizer_n_1createLBPHFaceRecognizer(JNIEnv *, jclass){ try {
cv::Ptr<cv::FaceRecognizer> ptr = cv::createLBPHFaceRecognizer();
cv::FaceRecognizer * pf = ptr.get();
ptr.addref(); //don't let it self-destroy here..
return (jlong) pf;
} catch (...) {
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "Exception occurs to create LBPH face recognizer..");
}
return 0;
}“
The makefile to build c code and dll file, facerec.dll : LBPHFaceRecognizer.o gcc -m64 -Wl,--add-stdcall-alias -shared -o $@ $<
LBPHFaceRecognizer.o : LBPHFaceRecognizer.c LBPHFaceRecognizer.h gcc -m64 -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -I"$(OPENCV_HOME)\build\include" -I"$(OPENCV_HOME)\build\java\x64" -c $< -o $@
I also tried with cpp code, and the error I got is
FisherFaceRecognizer.o:FisherFaceRecognizer.cpp:(.text+0x4c): undefined reference to cv::createFisherFaceRecognizer(int, double)'
FisherFaceRecognizer.o:FisherFaceRecognizer.cpp:(.text+0x101): undefined reference to
cv::createFisherFaceRecognizer(int, double)'
FisherFaceRecognizer.o:FisherFaceRecognizer.cpp:(.text+0x1b5): undefined reference to cv::createFisherFaceRecognizer(int, double)'
C:/Program Files/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: FisherFaceRecognizer.o: bad reloc address 0x0 in section
.pdata$_ZN7JNIEnv_9FindClassEPKc'
Then in the gcc build, I add -LC:$(OPENCV_HOME)/build/x64/vc12/lib -lopencv_contrib2411 -lopencv_core2411 -lopencv_highgui2411
C:/Program Files/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopencv_contrib2411 C:/Program Files/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopencv_core2411 C:/Program Files/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopencv_highgui2411 collect2.exe: error: ld returned 1 exit status makefile:13: recipe for target 'facerec.dll' failed
Anyone can help to give some tips on this issue? Do we have some github project which is already implement this?
BTW, I use the download opencv package, I did not build with mingw again ( I use mingw build my JNI code), is there a need to rebuild all this all?