Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
b422d078
Commit
b422d078
authored
May 22, 2012
by
Alexander Smorkalov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Face detection example updated. Dtetection base tracker mode added.
parent
9bddac10
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
283 additions
and
25 deletions
+283
-25
CMakeLists.txt
samples/android/face-detection/CMakeLists.txt
+9
-1
Android.mk
samples/android/face-detection/jni/Android.mk
+22
-0
Application.mk
samples/android/face-detection/jni/Application.mk
+3
-0
DetectionBaseTracker.cpp
samples/android/face-detection/jni/DetectionBaseTracker.cpp
+54
-0
DetectionBaseTracker.h
samples/android/face-detection/jni/DetectionBaseTracker.h
+53
-0
DetectionBaseTracker.java
...ction/src/org/opencv/samples/fd/DetectionBaseTracker.java
+47
-0
FdActivity.java
.../face-detection/src/org/opencv/samples/fd/FdActivity.java
+20
-6
FdView.java
...roid/face-detection/src/org/opencv/samples/fd/FdView.java
+75
-18
No files found.
samples/android/face-detection/CMakeLists.txt
View file @
b422d078
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
()
samples/android/face-detection/jni/Android.mk
0 → 100644
View file @
b422d078
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)
\ No newline at end of file
samples/android/face-detection/jni/Application.mk
0 → 100644
View file @
b422d078
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
samples/android/face-detection/jni/DetectionBaseTracker.cpp
0 → 100644
View file @
b422d078
#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
));
}
\ No newline at end of file
samples/android/face-detection/jni/DetectionBaseTracker.h
0 → 100644
View file @
b422d078
/* 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
samples/android/face-detection/src/org/opencv/samples/fd/DetectionBaseTracker.java
0 → 100644
View file @
b422d078
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"
);
}
}
samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java
View file @
b422d078
...
@@ -16,13 +16,18 @@ public class FdActivity extends Activity {
...
@@ -16,13 +16,18 @@ public class FdActivity extends Activity {
private
MenuItem
mItemFace40
;
private
MenuItem
mItemFace40
;
private
MenuItem
mItemFace30
;
private
MenuItem
mItemFace30
;
private
MenuItem
mItemFace20
;
private
MenuItem
mItemFace20
;
private
MenuItem
mItemType
;
private
FdView
mView
;
private
FdView
mView
;
public
static
float
minFaceSize
=
0.5f
;
private
int
mDetectorType
=
0
;
private
String
[]
mDetectorName
;
public
FdActivity
()
{
public
FdActivity
()
{
Log
.
i
(
TAG
,
"Instantiated new "
+
this
.
getClass
());
Log
.
i
(
TAG
,
"Instantiated new "
+
this
.
getClass
());
mDetectorName
=
new
String
[
2
];
mDetectorName
[
0
]
=
"Cascade"
;
mDetectorName
[
1
]
=
"DBT"
;
}
}
@Override
@Override
...
@@ -57,6 +62,7 @@ public class FdActivity extends Activity {
...
@@ -57,6 +62,7 @@ public class FdActivity extends Activity {
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
mView
=
new
FdView
(
this
);
mView
=
new
FdView
(
this
);
mView
.
setDtetectorType
(
mDetectorType
);
setContentView
(
mView
);
setContentView
(
mView
);
}
}
...
@@ -67,6 +73,8 @@ public class FdActivity extends Activity {
...
@@ -67,6 +73,8 @@ public class FdActivity extends Activity {
mItemFace40
=
menu
.
add
(
"Face size 40%"
);
mItemFace40
=
menu
.
add
(
"Face size 40%"
);
mItemFace30
=
menu
.
add
(
"Face size 30%"
);
mItemFace30
=
menu
.
add
(
"Face size 30%"
);
mItemFace20
=
menu
.
add
(
"Face size 20%"
);
mItemFace20
=
menu
.
add
(
"Face size 20%"
);
mItemType
=
menu
.
add
(
mDetectorName
[
mDetectorType
]);
return
true
;
return
true
;
}
}
...
@@ -74,13 +82,19 @@ public class FdActivity extends Activity {
...
@@ -74,13 +82,19 @@ public class FdActivity extends Activity {
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
Log
.
i
(
TAG
,
"Menu Item selected "
+
item
);
Log
.
i
(
TAG
,
"Menu Item selected "
+
item
);
if
(
item
==
mItemFace50
)
if
(
item
==
mItemFace50
)
m
inFaceSize
=
0.5f
;
m
View
.
setMinFaceSize
(
0.5f
)
;
else
if
(
item
==
mItemFace40
)
else
if
(
item
==
mItemFace40
)
minFaceSize
=
0.4f
;
mView
.
setMinFaceSize
(
0.4f
)
;
else
if
(
item
==
mItemFace30
)
else
if
(
item
==
mItemFace30
)
minFaceSize
=
0.3f
;
mView
.
setMinFaceSize
(
0.3f
)
;
else
if
(
item
==
mItemFace20
)
else
if
(
item
==
mItemFace20
)
minFaceSize
=
0.2f
;
mView
.
setMinFaceSize
(
0.2f
);
else
if
(
item
==
mItemType
)
{
mDetectorType
=
(
mDetectorType
+
1
)
%
mDetectorName
.
length
;
item
.
setTitle
(
mDetectorName
[
mDetectorType
]);
mView
.
setDtetectorType
(
mDetectorType
);
}
return
true
;
return
true
;
}
}
}
}
samples/android/face-detection/src/org/opencv/samples/fd/FdView.java
View file @
b422d078
...
@@ -23,10 +23,48 @@ import android.view.SurfaceHolder;
...
@@ -23,10 +23,48 @@ import android.view.SurfaceHolder;
class
FdView
extends
SampleCvViewBase
{
class
FdView
extends
SampleCvViewBase
{
private
static
final
String
TAG
=
"Sample::FdView"
;
private
static
final
String
TAG
=
"Sample::FdView"
;
private
Mat
mRgba
;
private
Mat
mRgba
;
private
Mat
mGray
;
private
Mat
mGray
;
private
File
mCascadeFile
;
private
CascadeClassifier
mCascade
;
private
CascadeClassifier
mCascade
;
private
DetectionBaseTracker
mTracker
;
public
final
int
CASCADE_DETECTOR
=
0
;
public
final
int
DBT_DETECTOR
=
1
;
private
int
mDetectorType
=
CASCADE_DETECTOR
;
public
static
int
mFaceSize
=
200
;
public
void
setMinFaceSize
(
float
faceSize
)
{
int
height
=
mGray
.
rows
();
if
(
Math
.
round
(
height
*
faceSize
)
>
0
);
{
mFaceSize
=
Math
.
round
(
height
*
faceSize
);
}
mTracker
.
release
();
mTracker
=
new
DetectionBaseTracker
(
mCascadeFile
.
getAbsolutePath
(),
mFaceSize
);
}
public
void
setDtetectorType
(
int
type
)
{
if
(
mDetectorType
!=
type
)
{
mDetectorType
=
type
;
if
(
type
==
DBT_DETECTOR
)
{
Log
.
i
(
TAG
,
"Detection Base Tracker enabled"
);
mTracker
.
start
();
}
else
{
Log
.
i
(
TAG
,
"Cascade detectior enabled"
);
mTracker
.
stop
();
}
}
}
public
FdView
(
Context
context
)
{
public
FdView
(
Context
context
)
{
super
(
context
);
super
(
context
);
...
@@ -34,8 +72,8 @@ class FdView extends SampleCvViewBase {
...
@@ -34,8 +72,8 @@ class FdView extends SampleCvViewBase {
try
{
try
{
InputStream
is
=
context
.
getResources
().
openRawResource
(
R
.
raw
.
lbpcascade_frontalface
);
InputStream
is
=
context
.
getResources
().
openRawResource
(
R
.
raw
.
lbpcascade_frontalface
);
File
cascadeDir
=
context
.
getDir
(
"cascade"
,
Context
.
MODE_PRIVATE
);
File
cascadeDir
=
context
.
getDir
(
"cascade"
,
Context
.
MODE_PRIVATE
);
File
c
ascadeFile
=
new
File
(
cascadeDir
,
"lbpcascade_frontalface.xml"
);
mC
ascadeFile
=
new
File
(
cascadeDir
,
"lbpcascade_frontalface.xml"
);
FileOutputStream
os
=
new
FileOutputStream
(
c
ascadeFile
);
FileOutputStream
os
=
new
FileOutputStream
(
mC
ascadeFile
);
byte
[]
buffer
=
new
byte
[
4096
];
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
;
int
bytesRead
;
...
@@ -45,14 +83,15 @@ class FdView extends SampleCvViewBase {
...
@@ -45,14 +83,15 @@ class FdView extends SampleCvViewBase {
is
.
close
();
is
.
close
();
os
.
close
();
os
.
close
();
mCascade
=
new
CascadeClassifier
(
c
ascadeFile
.
getAbsolutePath
());
mCascade
=
new
CascadeClassifier
(
mC
ascadeFile
.
getAbsolutePath
());
if
(
mCascade
.
empty
())
{
if
(
mCascade
.
empty
())
{
Log
.
e
(
TAG
,
"Failed to load cascade classifier"
);
Log
.
e
(
TAG
,
"Failed to load cascade classifier"
);
mCascade
=
null
;
mCascade
=
null
;
}
else
}
else
Log
.
i
(
TAG
,
"Loaded cascade classifier from "
+
c
ascadeFile
.
getAbsolutePath
());
Log
.
i
(
TAG
,
"Loaded cascade classifier from "
+
mC
ascadeFile
.
getAbsolutePath
());
cascadeFile
.
delete
();
mTracker
=
new
DetectionBaseTracker
(
mCascadeFile
.
getAbsolutePath
(),
0
);
cascadeDir
.
delete
();
cascadeDir
.
delete
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -77,16 +116,29 @@ class FdView extends SampleCvViewBase {
...
@@ -77,16 +116,29 @@ class FdView extends SampleCvViewBase {
capture
.
retrieve
(
mRgba
,
Highgui
.
CV_CAP_ANDROID_COLOR_FRAME_RGBA
);
capture
.
retrieve
(
mRgba
,
Highgui
.
CV_CAP_ANDROID_COLOR_FRAME_RGBA
);
capture
.
retrieve
(
mGray
,
Highgui
.
CV_CAP_ANDROID_GREY_FRAME
);
capture
.
retrieve
(
mGray
,
Highgui
.
CV_CAP_ANDROID_GREY_FRAME
);
if
(
mCascade
!=
null
)
{
MatOfRect
faces
=
new
MatOfRect
();
int
height
=
mGray
.
rows
();
int
faceSize
=
Math
.
round
(
height
*
FdActivity
.
minFaceSize
);
if
(
mDetectorType
==
CASCADE_DETECTOR
)
MatOfRect
faces
=
new
MatOfRect
();
{
mCascade
.
detectMultiScale
(
mGray
,
faces
,
1.1
,
2
,
2
// TODO: objdetect.CV_HAAR_SCALE_IMAGE
if
(
mCascade
!=
null
)
{
,
new
Size
(
faceSize
,
faceSize
),
new
Size
());
mCascade
.
detectMultiScale
(
mGray
,
faces
,
1.1
,
2
,
2
// TODO: objdetect.CV_HAAR_SCALE_IMAGE
,
new
Size
(
mFaceSize
,
mFaceSize
),
new
Size
());
for
(
Rect
r
:
faces
.
toArray
())
}
Core
.
rectangle
(
mRgba
,
r
.
tl
(),
r
.
br
(),
new
Scalar
(
0
,
255
,
0
,
255
),
3
);
}
else
if
(
mDetectorType
==
DBT_DETECTOR
)
{
if
(
mTracker
!=
null
)
{
mTracker
.
detect
(
mGray
,
faces
);
}
}
else
{
Log
.
e
(
TAG
,
"Detection method is not selected!"
);
}
}
for
(
Rect
r
:
faces
.
toArray
())
Core
.
rectangle
(
mRgba
,
r
.
tl
(),
r
.
br
(),
new
Scalar
(
0
,
255
,
0
,
255
),
3
);
Bitmap
bmp
=
Bitmap
.
createBitmap
(
mRgba
.
cols
(),
mRgba
.
rows
(),
Bitmap
.
Config
.
RGB_565
/*.ARGB_8888*/
);
Bitmap
bmp
=
Bitmap
.
createBitmap
(
mRgba
.
cols
(),
mRgba
.
rows
(),
Bitmap
.
Config
.
RGB_565
/*.ARGB_8888*/
);
...
@@ -110,9 +162,14 @@ class FdView extends SampleCvViewBase {
...
@@ -110,9 +162,14 @@ class FdView extends SampleCvViewBase {
mRgba
.
release
();
mRgba
.
release
();
if
(
mGray
!=
null
)
if
(
mGray
!=
null
)
mGray
.
release
();
mGray
.
release
();
if
(
mCascadeFile
!=
null
)
mCascadeFile
.
delete
();
if
(
mTracker
!=
null
)
mTracker
.
release
();
mRgba
=
null
;
mRgba
=
null
;
mGray
=
null
;
mGray
=
null
;
mCascadeFile
=
null
;
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment