parent
9bddac1099
commit
b422d078f8
8 changed files with 281 additions and 25 deletions
@ -1,6 +1,14 @@ |
|||||||
set(sample example-face-detection) |
set(sample example-face-detection) |
||||||
|
|
||||||
add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET}) |
if(BUILD_FAT_JAVA_LIB) |
||||||
|
set(native_deps opencv_java) |
||||||
|
ocv_include_modules(opencv_contrib) |
||||||
|
else() |
||||||
|
set(native_deps opencv_contrib) |
||||||
|
endif() |
||||||
|
|
||||||
|
add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS ${native_deps}) |
||||||
if(TARGET ${sample}) |
if(TARGET ${sample}) |
||||||
add_dependencies(opencv_android_examples ${sample}) |
add_dependencies(opencv_android_examples ${sample}) |
||||||
endif() |
endif() |
||||||
|
|
||||||
|
@ -0,0 +1,21 @@ |
|||||||
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS) |
||||||
|
|
||||||
|
OPENCV_CAMERA_MODULES:=off
|
||||||
|
|
||||||
|
include ../includeOpenCV.mk |
||||||
|
ifeq ("$(wildcard $(OPENCV_MK_PATH))","") |
||||||
|
#try to load OpenCV.mk from default install location
|
||||||
|
include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk
|
||||||
|
else |
||||||
|
include $(OPENCV_MK_PATH)
|
||||||
|
endif |
||||||
|
|
||||||
|
LOCAL_SRC_FILES := DetectionBaseTracker.cpp
|
||||||
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)
|
||||||
|
LOCAL_LDLIBS += -llog -ldl
|
||||||
|
|
||||||
|
LOCAL_MODULE := detection_base_tacker
|
||||||
|
|
||||||
|
include $(BUILD_SHARED_LIBRARY) |
@ -0,0 +1,3 @@ |
|||||||
|
APP_STL := gnustl_static
|
||||||
|
APP_CPPFLAGS := -frtti -fexceptions
|
||||||
|
APP_ABI := armeabi-v7a
|
@ -0,0 +1,53 @@ |
|||||||
|
#include <DetectionBaseTracker.h> |
||||||
|
#include <opencv2/core/core.hpp> |
||||||
|
#include <opencv2/contrib/detection_based_tracker.hpp> |
||||||
|
|
||||||
|
#include <string> |
||||||
|
#include <vector> |
||||||
|
|
||||||
|
using namespace std; |
||||||
|
using namespace cv; |
||||||
|
|
||||||
|
vector<Rect> RectFaces; |
||||||
|
|
||||||
|
inline void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat) |
||||||
|
{ |
||||||
|
mat = Mat(v_rect, true); |
||||||
|
} |
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeCreateObject |
||||||
|
(JNIEnv * jenv, jclass jobj, jstring jFileName, jint faceSize) |
||||||
|
{ |
||||||
|
const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL); |
||||||
|
string stdFileName(jnamestr); |
||||||
|
DetectionBasedTracker::Parameters DetectorParams; |
||||||
|
if (faceSize > 0) |
||||||
|
DetectorParams.minObjectSize = faceSize; |
||||||
|
return (jlong)new DetectionBasedTracker(stdFileName, DetectorParams); |
||||||
|
} |
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeDestroyObject |
||||||
|
(JNIEnv * jenv, jclass jobj, jlong thiz) |
||||||
|
{ |
||||||
|
delete (DetectionBasedTracker*)thiz; |
||||||
|
} |
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeStart |
||||||
|
(JNIEnv * jenv, jclass jobj, jlong thiz) |
||||||
|
{ |
||||||
|
((DetectionBasedTracker*)thiz)->run(); |
||||||
|
} |
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeStop |
||||||
|
(JNIEnv * jenv, jclass jobj, jlong thiz) |
||||||
|
{ |
||||||
|
((DetectionBasedTracker*)thiz)->stop(); |
||||||
|
} |
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeDetect |
||||||
|
(JNIEnv * jenv, jclass jobj, jlong thiz, jlong imageGray, jlong faces) |
||||||
|
{ |
||||||
|
((DetectionBasedTracker*)thiz)->process(*((Mat*)imageGray)); |
||||||
|
((DetectionBasedTracker*)thiz)->getObjects(RectFaces); |
||||||
|
vector_Rect_to_Mat(RectFaces, *((Mat*)faces)); |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
/* DO NOT EDIT THIS FILE - it is machine generated */ |
||||||
|
#include <jni.h> |
||||||
|
/* Header for class org_opencv_samples_fd_DetectionBaseTracker */ |
||||||
|
|
||||||
|
#ifndef _Included_org_opencv_samples_fd_DetectionBaseTracker |
||||||
|
#define _Included_org_opencv_samples_fd_DetectionBaseTracker |
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
/*
|
||||||
|
* Class: org_opencv_samples_fd_DetectionBaseTracker |
||||||
|
* Method: nativeCreateObject |
||||||
|
* Signature: (Ljava/lang/String;F)J |
||||||
|
*/ |
||||||
|
JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeCreateObject |
||||||
|
(JNIEnv *, jclass, jstring, jint); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_opencv_samples_fd_DetectionBaseTracker |
||||||
|
* Method: nativeDestroyObject |
||||||
|
* Signature: (J)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeDestroyObject |
||||||
|
(JNIEnv *, jclass, jlong); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_opencv_samples_fd_DetectionBaseTracker |
||||||
|
* Method: nativeStart |
||||||
|
* Signature: (J)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeStart |
||||||
|
(JNIEnv *, jclass, jlong); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_opencv_samples_fd_DetectionBaseTracker |
||||||
|
* Method: nativeStop |
||||||
|
* Signature: (J)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeStop |
||||||
|
(JNIEnv *, jclass, jlong); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_opencv_samples_fd_DetectionBaseTracker |
||||||
|
* Method: nativeDetect |
||||||
|
* Signature: (JJJ)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBaseTracker_nativeDetect |
||||||
|
(JNIEnv *, jclass, jlong, jlong, jlong); |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
#endif |
@ -0,0 +1,47 @@ |
|||||||
|
package org.opencv.samples.fd; |
||||||
|
|
||||||
|
import org.opencv.core.Mat; |
||||||
|
import org.opencv.core.MatOfRect; |
||||||
|
|
||||||
|
public class DetectionBaseTracker |
||||||
|
{ |
||||||
|
public DetectionBaseTracker(String filename, int faceSize) |
||||||
|
{ |
||||||
|
mNativeObj = nativeCreateObject(filename, faceSize); |
||||||
|
} |
||||||
|
|
||||||
|
public void start() |
||||||
|
{ |
||||||
|
nativeStart(mNativeObj); |
||||||
|
} |
||||||
|
|
||||||
|
public void stop() |
||||||
|
{ |
||||||
|
nativeStop(mNativeObj); |
||||||
|
} |
||||||
|
|
||||||
|
public void detect(Mat imageGray, MatOfRect faces) |
||||||
|
{ |
||||||
|
nativeDetect(mNativeObj, imageGray.getNativeObjAddr(), faces.getNativeObjAddr()); |
||||||
|
} |
||||||
|
|
||||||
|
public void release() |
||||||
|
{ |
||||||
|
nativeStop(mNativeObj); |
||||||
|
nativeDestroyObject(mNativeObj); |
||||||
|
mNativeObj = 0; |
||||||
|
} |
||||||
|
|
||||||
|
protected long mNativeObj; |
||||||
|
|
||||||
|
protected static native long nativeCreateObject(String filename, int faceSize); |
||||||
|
protected static native void nativeDestroyObject(long thiz); |
||||||
|
protected static native void nativeStart(long thiz); |
||||||
|
protected static native void nativeStop(long thiz); |
||||||
|
protected static native void nativeDetect(long thiz, long inputImage, long resultMat); |
||||||
|
|
||||||
|
static |
||||||
|
{ |
||||||
|
System.loadLibrary("detection_base_tacker"); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue