Hey,
I need to write a face recognition program in java but I can't seem to succesfully create the facerec.dll.
I already wrote the Java class:
public class EigenFaceRecognizer extends FaceRecognizer
{
static {
System.loadLibrary("facerec");
}
private static native long createEigenFaceRecognizer_0();
private static native long createEigenFaceRecognizer_1(int num_components);
private static native long createEigenFaceRecognizer_2(int num_components, double threshold);
public EigenFaceRecognizer () {
super(createEigenFaceRecognizer_0());
}
public EigenFaceRecognizer (int num_components) {
super(createEigenFaceRecognizer_1(num_components));
}
public EigenFaceRecognizer (int num_components, double threshold) {
super(createEigenFaceRecognizer_2(num_components, threshold));
}
}
But, as I said earlier, I can't create the facerec.dll for it and I'm trying for a couple of days and nothing is working.
I have opencv 2.4.8 extracted (C:\opencv), jdk 8_11 (C:\Program Files\Java\jdk1.8.0_11), mingw for windows 64 bits, windows 8 64 bits as operating system and netbeans 8.
Thx
If I try:
g++ facerec.cpp -I"C:\opencv\build\include" -I"C:\Program Files\Java\jdk1.8.0_11\include" -I"C:\Program Files\Java\jdk1.8.0_11\include\win32" -L"C:\opencv\build\x64\vc11\lib" -lopencv_contrib248 -lopencv_core248 -lopencv_ml248 -o facerec.dll
I get:
C:\Users\Robert\AppData\Local\Temp\ccVvdrS9.o:facerec.cpp:(.text+0x4c): undefine
d reference to cv::createFisherFaceRecognizer(int, double)'
C:\Users\Robert\AppData\Local\Temp\ccVvdrS9.o:facerec.cpp:(.text+0x101): undefin
ed reference to
cv::createFisherFaceRecognizer(int, double)'
C:\Users\Robert\AppData\Local\Temp\ccVvdrS9.o:facerec.cpp:(.text+0x1b5): undefin
ed reference to cv::createFisherFaceRecognizer(int, double)'
C:/Program Files/mingw-w64/x86_64-4.9.1-win32-seh-rt_v3-rev0/mingw64/bin/../lib/
gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users
\Robert\AppData\Local\Temp\ccVvdrS9.o: bad reloc address 0x0 in section
.pdata$
_ZN7JNIEnv_9FindClassEPKc'
collect2.exe: error: ld returned 1 exit status
This is my .cpp file:
include "jni.h"
include "opencv2/contrib/contrib.hpp"
ifdef __cplusplus
extern "C" {
endif
JNIEXPORT jlong JNICALL Java_EigenFaceRecognizer_createEigenFaceRecognizer_10(JNIEnv* env, jclass);
JNIEXPORT jlong JNICALL Java_EigenFaceRecognizer_createEigenFaceRecognizer_10(JNIEnv* env, jclass) {
try {
cv::Ptr<cv::facerecognizer> pfr = cv::createEigenFaceRecognizer();
pfr.addref(); // this is for the 2.4 branch, 3.0 would need a different treatment here
return (jlong) pfr.obj;
} catch (...) {
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "sorry, dave..");
}
return 0;
}
JNIEXPORT jlong JNICALL Java_EigenFaceRecognizer_createEigenFaceRecognizer_11(JNIEnv* env, jclass, jint num_components);
JNIEXPORT jlong JNICALL Java_EigenFaceRecognizer_createEigenFaceRecognizer_11(JNIEnv* env, jclass, jint num_components) {
try {
cv::Ptr<cv::facerecognizer> pfr = cv::createEigenFaceRecognizer(num_components);
pfr.addref();
return (jlong) pfr.obj;
} catch (...) {
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "sorry, dave..");
}
return 0;
}
JNIEXPORT jlong JNICALL Java_EigenFaceRecognizer_createEigenFaceRecognizer_12(JNIEnv* env, jclass, jint num_components, jdouble threshold);
JNIEXPORT jlong JNICALL Java_EigenFaceRecognizer_createEigenFaceRecognizer_12(JNIEnv* env, jclass, jint num_components, jdouble threshold) {
try {
cv::Ptr<cv::facerecognizer> pfr = cv::createEigenFaceRecognizer(num_components,threshold);
pfr.addref();
return (jlong) pfr.obj;
} catch (...) {
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "sorry, dave..");
}
return 0;
}
ifdef __cplusplus
}
endif