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
9e00cc59
Commit
9e00cc59
authored
Jul 19, 2011
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added face datection Android sample
parent
343bba93
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
383 additions
and
1 deletion
+383
-1
.classpath
samples/android/face-detection/.classpath
+8
-0
.project
samples/android/face-detection/.project
+40
-0
org.eclipse.jdt.core.prefs
...droid/face-detection/.settings/org.eclipse.jdt.core.prefs
+5
-0
AndroidManifest.xml
samples/android/face-detection/AndroidManifest.xml
+31
-0
default.properties
samples/android/face-detection/default.properties
+3
-0
icon.png
samples/android/face-detection/res/drawable/icon.png
+0
-0
lbpcascade_frontalface.xml
...android/face-detection/res/raw/lbpcascade_frontalface.xml
+0
-0
strings.xml
samples/android/face-detection/res/values/strings.xml
+4
-0
FdActivity.java
.../face-detection/src/org/opencv/samples/fd/FdActivity.java
+56
-0
FdView.java
...roid/face-detection/src/org/opencv/samples/fd/FdView.java
+110
-0
SampleCvViewBase.java
...detection/src/org/opencv/samples/fd/SampleCvViewBase.java
+109
-0
strings.xml
samples/android/image-manipulations/res/values/strings.xml
+1
-1
ImageManipulationsView.java
...cv/samples/imagemanipulations/ImageManipulationsView.java
+16
-0
No files found.
samples/android/face-detection/.classpath
0 → 100644
View file @
9e00cc59
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"src"
path=
"gen"
/>
<classpathentry
kind=
"con"
path=
"com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"
/>
<classpathentry
kind=
"src"
path=
"OpenCV-2.3.1_src"
/>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
samples/android/face-detection/.project
0 → 100644
View file @
9e00cc59
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
Sample - face-detection
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
com.android.ide.eclipse.adt.ResourceManagerBuilder
</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>
com.android.ide.eclipse.adt.PreCompilerBuilder
</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>
com.android.ide.eclipse.adt.ApkBuilder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
com.android.ide.eclipse.adt.AndroidNature
</nature>
<nature>
org.eclipse.jdt.core.javanature
</nature>
</natures>
<linkedResources>
<link>
<name>
OpenCV-2.3.1_src
</name>
<type>
2
</type>
<locationURI>
_android_OpenCV_2_3_1_df28900a/src
</locationURI>
</link>
</linkedResources>
</projectDescription>
samples/android/face-detection/.settings/org.eclipse.jdt.core.prefs
0 → 100644
View file @
9e00cc59
#Wed Jun 29 04:36:40 MSD 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.source=1.5
samples/android/face-detection/AndroidManifest.xml
0 → 100644
View file @
9e00cc59
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"org.opencv.samples.fd"
android:versionCode=
"1"
android:versionName=
"1.0"
>
<supports-screens
android:resizeable=
"true"
android:smallScreens=
"true"
android:normalScreens=
"true"
android:largeScreens=
"true"
android:anyDensity=
"true"
/>
<application
android:label=
"@string/app_name"
android:icon=
"@drawable/icon"
>
<activity
android:name=
"FdActivity"
android:label=
"@string/app_name"
android:screenOrientation=
"landscape"
android:configChanges=
"keyboardHidden|orientation"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion=
"8"
/>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-feature
android:name=
"android.hardware.camera"
/>
<uses-feature
android:name=
"android.hardware.camera.autofocus"
/>
</manifest>
samples/android/face-detection/default.properties
0 → 100644
View file @
9e00cc59
android.library.reference.1
=
../../OpenCV-2.3.1
# Project target.
target
=
android-8
samples/android/face-detection/res/drawable/icon.png
0 → 100644
View file @
9e00cc59
5.63 KB
samples/android/face-detection/res/raw/lbpcascade_frontalface.xml
0 → 100644
View file @
9e00cc59
This diff is collapsed.
Click to expand it.
samples/android/face-detection/res/values/strings.xml
0 → 100644
View file @
9e00cc59
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"app_name"
>
OpenCV Sample - face-detection
</string>
</resources>
samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java
0 → 100644
View file @
9e00cc59
package
org
.
opencv
.
samples
.
fd
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.view.Window
;
public
class
FdActivity
extends
Activity
{
private
static
final
String
TAG
=
"Sample::Activity"
;
private
MenuItem
mItemFace50
;
private
MenuItem
mItemFace40
;
private
MenuItem
mItemFace30
;
private
MenuItem
mItemFace20
;
public
static
float
minFaceSize
=
0.5f
;
public
FdActivity
()
{
Log
.
i
(
TAG
,
"Instantiated new "
+
this
.
getClass
());
}
/** Called when the activity is first created. */
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
Log
.
i
(
TAG
,
"onCreate"
);
super
.
onCreate
(
savedInstanceState
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
setContentView
(
new
FdView
(
this
));
}
@Override
public
boolean
onCreateOptionsMenu
(
Menu
menu
)
{
Log
.
i
(
TAG
,
"onCreateOptionsMenu"
);
mItemFace50
=
menu
.
add
(
"Face size 50%"
);
mItemFace40
=
menu
.
add
(
"Face size 40%"
);
mItemFace30
=
menu
.
add
(
"Face size 30%"
);
mItemFace20
=
menu
.
add
(
"Face size 20%"
);
return
true
;
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
Log
.
i
(
TAG
,
"Menu Item selected "
+
item
);
if
(
item
==
mItemFace50
)
minFaceSize
=
0.5f
;
else
if
(
item
==
mItemFace40
)
minFaceSize
=
0.4f
;
else
if
(
item
==
mItemFace30
)
minFaceSize
=
0.3f
;
else
if
(
item
==
mItemFace20
)
minFaceSize
=
0.2f
;
return
true
;
}
}
samples/android/face-detection/src/org/opencv/samples/fd/FdView.java
0 → 100644
View file @
9e00cc59
package
org
.
opencv
.
samples
.
fd
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.opencv.*
;
import
org.opencv.objdetect.CascadeClassifier
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.util.Log
;
import
android.view.SurfaceHolder
;
class
FdView
extends
SampleCvViewBase
{
private
static
final
String
TAG
=
"Sample::FdView"
;
private
Mat
mRgba
;
private
Mat
mGray
;
private
CascadeClassifier
mCascade
;
public
FdView
(
Context
context
)
{
super
(
context
);
try
{
InputStream
is
=
context
.
getResources
().
openRawResource
(
R
.
raw
.
lbpcascade_frontalface
);
File
cascadeDir
=
context
.
getDir
(
"cascade"
,
Context
.
MODE_PRIVATE
);
File
cascadeFile
=
new
File
(
cascadeDir
,
"lbpcascade_frontalface.xml"
);
FileOutputStream
os
=
new
FileOutputStream
(
cascadeFile
);
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
;
while
((
bytesRead
=
is
.
read
(
buffer
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
}
is
.
close
();
os
.
close
();
mCascade
=
new
CascadeClassifier
(
cascadeFile
.
getAbsolutePath
());
if
(
mCascade
.
empty
())
{
Log
.
e
(
TAG
,
"Failed to load cascade classifier"
);
mCascade
=
null
;
}
else
Log
.
i
(
TAG
,
"Loaded cascade classifier from "
+
cascadeFile
.
getAbsolutePath
());
cascadeFile
.
delete
();
cascadeDir
.
delete
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"Failed to load cascade. Exception thrown: "
+
e
);
}
}
@Override
public
void
surfaceChanged
(
SurfaceHolder
_holder
,
int
format
,
int
width
,
int
height
)
{
super
.
surfaceChanged
(
_holder
,
format
,
width
,
height
);
synchronized
(
this
)
{
// initialize Mats before usage
mGray
=
new
Mat
();
mRgba
=
new
Mat
();
}
}
@Override
protected
Bitmap
processFrame
(
VideoCapture
capture
)
{
capture
.
retrieve
(
mRgba
,
highgui
.
CV_CAP_ANDROID_COLOR_FRAME_RGBA
);
capture
.
retrieve
(
mGray
,
highgui
.
CV_CAP_ANDROID_GREY_FRAME
);
if
(
mCascade
!=
null
)
{
int
height
=
mGray
.
rows
();
int
faceSize
=
Math
.
round
(
height
*
FdActivity
.
minFaceSize
);
List
<
Rect
>
faces
=
new
LinkedList
<
Rect
>();
mCascade
.
detectMultiScale
(
mGray
,
faces
,
1.1
,
2
,
2
// TODO: objdetect.CV_HAAR_SCALE_IMAGE
,
new
Size
(
faceSize
,
faceSize
));
for
(
Rect
r
:
faces
)
core
.
rectangle
(
mRgba
,
r
.
tl
(),
r
.
br
(),
new
Scalar
(
0
,
255
,
0
,
255
),
3
);
}
Bitmap
bmp
=
Bitmap
.
createBitmap
(
mRgba
.
cols
(),
mRgba
.
rows
(),
Bitmap
.
Config
.
ARGB_8888
);
if
(
android
.
MatToBitmap
(
mRgba
,
bmp
))
return
bmp
;
bmp
.
recycle
();
return
null
;
}
@Override
public
void
run
()
{
super
.
run
();
synchronized
(
this
)
{
// Explicitly deallocate Mats
if
(
mRgba
!=
null
)
mRgba
.
dispose
();
if
(
mGray
!=
null
)
mGray
.
dispose
();
mRgba
=
null
;
mGray
=
null
;
}
}
}
\ No newline at end of file
samples/android/face-detection/src/org/opencv/samples/fd/SampleCvViewBase.java
0 → 100644
View file @
9e00cc59
package
org
.
opencv
.
samples
.
fd
;
import
java.util.List
;
import
org.opencv.*
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.util.Log
;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceView
;
public
abstract
class
SampleCvViewBase
extends
SurfaceView
implements
SurfaceHolder
.
Callback
,
Runnable
{
private
static
final
String
TAG
=
"Sample::SurfaceView"
;
private
SurfaceHolder
mHolder
;
private
VideoCapture
mCamera
;
public
SampleCvViewBase
(
Context
context
)
{
super
(
context
);
mHolder
=
getHolder
();
mHolder
.
addCallback
(
this
);
Log
.
i
(
TAG
,
"Instantiated new "
+
this
.
getClass
());
}
public
void
surfaceChanged
(
SurfaceHolder
_holder
,
int
format
,
int
width
,
int
height
)
{
Log
.
i
(
TAG
,
"surfaceCreated"
);
synchronized
(
this
)
{
if
(
mCamera
!=
null
&&
mCamera
.
isOpened
())
{
Log
.
i
(
TAG
,
"before mCamera.getSupportedPreviewSizes()"
);
List
<
Size
>
sizes
=
mCamera
.
getSupportedPreviewSizes
();
Log
.
i
(
TAG
,
"after mCamera.getSupportedPreviewSizes()"
);
int
mFrameWidth
=
width
;
int
mFrameHeight
=
height
;
// selecting optimal camera preview size
{
double
minDiff
=
Double
.
MAX_VALUE
;
for
(
Size
size
:
sizes
)
{
if
(
Math
.
abs
(
size
.
height
-
height
)
<
minDiff
)
{
mFrameWidth
=
(
int
)
size
.
width
;
mFrameHeight
=
(
int
)
size
.
height
;
minDiff
=
Math
.
abs
(
size
.
height
-
height
);
}
}
}
mCamera
.
set
(
highgui
.
CV_CAP_PROP_FRAME_WIDTH
,
mFrameWidth
);
mCamera
.
set
(
highgui
.
CV_CAP_PROP_FRAME_HEIGHT
,
mFrameHeight
);
}
}
}
public
void
surfaceCreated
(
SurfaceHolder
holder
)
{
Log
.
i
(
TAG
,
"surfaceCreated"
);
mCamera
=
new
VideoCapture
(
highgui
.
CV_CAP_ANDROID
);
if
(
mCamera
.
isOpened
())
{
(
new
Thread
(
this
)).
start
();
}
else
{
mCamera
.
release
();
mCamera
=
null
;
Log
.
e
(
TAG
,
"Failed to open native camera"
);
}
}
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
Log
.
i
(
TAG
,
"surfaceDestroyed"
);
if
(
mCamera
!=
null
)
{
synchronized
(
this
)
{
mCamera
.
release
();
mCamera
=
null
;
}
}
}
protected
abstract
Bitmap
processFrame
(
VideoCapture
capture
);
public
void
run
()
{
Log
.
i
(
TAG
,
"Starting processing thread"
);
while
(
true
)
{
Bitmap
bmp
=
null
;
synchronized
(
this
)
{
if
(
mCamera
==
null
)
break
;
if
(!
mCamera
.
grab
())
{
Log
.
e
(
TAG
,
"mCamera.grab() failed"
);
break
;
}
bmp
=
processFrame
(
mCamera
);
}
if
(
bmp
!=
null
)
{
Canvas
canvas
=
mHolder
.
lockCanvas
();
if
(
canvas
!=
null
)
{
canvas
.
drawBitmap
(
bmp
,
(
canvas
.
getWidth
()
-
bmp
.
getWidth
())
/
2
,
(
canvas
.
getHeight
()
-
bmp
.
getHeight
())
/
2
,
null
);
mHolder
.
unlockCanvasAndPost
(
canvas
);
}
bmp
.
recycle
();
}
}
Log
.
i
(
TAG
,
"Finishing processing thread"
);
}
}
\ No newline at end of file
samples/android/image-manipulations/res/values/strings.xml
View file @
9e00cc59
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"app_name"
>
OpenCV
s
ample - image-manipulations
</string>
<string
name=
"app_name"
>
OpenCV
S
ample - image-manipulations
</string>
</resources>
samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java
View file @
9e00cc59
...
...
@@ -139,6 +139,16 @@ class ImageManipulationsView extends SampleCvViewBase {
synchronized
(
this
)
{
// Explicitly deallocate Mats
if
(
mZoomWindow
!=
null
)
mZoomWindow
.
dispose
();
if
(
mZoomCorner
!=
null
)
mZoomCorner
.
dispose
();
if
(
mBlurWindow
!=
null
)
mBlurWindow
.
dispose
();
if
(
mGrayInnerWindow
!=
null
)
mGrayInnerWindow
.
dispose
();
if
(
mRgbaInnerWindow
!=
null
)
mRgbaInnerWindow
.
dispose
();
if
(
mRgba
!=
null
)
mRgba
.
dispose
();
if
(
mGray
!=
null
)
...
...
@@ -149,6 +159,11 @@ class ImageManipulationsView extends SampleCvViewBase {
mRgba
=
null
;
mGray
=
null
;
mIntermediateMat
=
null
;
mRgbaInnerWindow
=
null
;
mGrayInnerWindow
=
null
;
mBlurWindow
=
null
;
mZoomCorner
=
null
;
mZoomWindow
=
null
;
}
}
}
\ No newline at end of file
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