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
d015a50d
Commit
d015a50d
authored
Apr 27, 2012
by
Alexander Smorkalov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Base classes for sample added.
parent
c78d056e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
246 additions
and
11 deletions
+246
-11
.classpath
samples/android/color-blob-detection/.classpath
+0
-1
.project
samples/android/color-blob-detection/.project
+1
-2
AndroidManifest.xml
samples/android/color-blob-detection/AndroidManifest.xml
+15
-6
project.properties
samples/android/color-blob-detection/project.properties
+1
-0
strings.xml
samples/android/color-blob-detection/res/values/strings.xml
+3
-2
ColorBlobDetectionActivity.java
...v/samples/colorblobdetect/ColorBlobDetectionActivity.java
+28
-0
ColorBlobDetectionView.java
...pencv/samples/colorblobdetect/ColorBlobDetectionView.java
+87
-0
SampleCvViewBase.java
.../org/opencv/samples/colorblobdetect/SampleCvViewBase.java
+111
-0
No files found.
samples/android/color-blob-detection/.classpath
View file @
d015a50d
...
...
@@ -2,7 +2,6 @@
<classpath>
<classpathentry
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"src"
path=
"gen"
/>
<classpathentry
combineaccessrules=
"false"
kind=
"src"
path=
"/ColorBlobDetection"
/>
<classpathentry
kind=
"con"
path=
"com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"
/>
<classpathentry
kind=
"con"
path=
"com.android.ide.eclipse.adt.LIBRARIES"
/>
<classpathentry
kind=
"output"
path=
"bin/classes"
/>
...
...
samples/android/color-blob-detection/.project
View file @
d015a50d
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
ColorBlobDetection
Test
</name>
<name>
ColorBlobDetection
</name>
<comment></comment>
<projects>
<project>
ColorBlobDetection
</project>
</projects>
<buildSpec>
<buildCommand>
...
...
samples/android/color-blob-detection/AndroidManifest.xml
View file @
d015a50d
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"org.opencv.example.colorblobdetect
.test
"
package=
"org.opencv.example.colorblobdetect"
android:versionCode=
"1"
android:versionName=
"1.0"
>
<uses-sdk
android:minSdkVersion=
"8"
/>
<instrumentation
android:name=
"android.test.InstrumentationTestRunner"
android:targetPackage=
"org.opencv.example.colorblobdetect"
/>
<application
android:icon=
"@drawable/ic_launcher"
android:label=
"@string/app_name"
>
<uses-library
android:name=
"android.test.runner"
/>
<activity
android:name=
"org.opencv.samples.colorblobdetect.ColorBlobDetectionActivity"
android:label=
"@string/app_name"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-feature
android:name=
"android.hardware.camera"
/>
<uses-feature
android:name=
"android.hardware.camera.autofocus"
/>
</manifest>
\ No newline at end of file
samples/android/color-blob-detection/project.properties
View file @
d015a50d
...
...
@@ -12,3 +12,4 @@
# Project target.
target
=
android-8
android.library.reference.1
=
../../../android/build
samples/android/color-blob-detection/res/values/strings.xml
View file @
d015a50d
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"hello"
>
Hello World!
</string>
<string
name=
"app_name"
>
ColorBlobDetection
Test
</string>
<string
name=
"hello"
>
Hello World
, ColorBlobDetectionActivity
!
</string>
<string
name=
"app_name"
>
ColorBlobDetection
</string>
</resources>
\ No newline at end of file
samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java
0 → 100644
View file @
d015a50d
package
org
.
opencv
.
samples
.
colorblobdetect
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.Window
;
public
class
ColorBlobDetectionActivity
extends
Activity
{
private
static
final
String
TAG
=
"Example/CollorBlobDetection"
;
private
ColorBlobDetectionView
mView
;
public
ColorBlobDetectionActivity
()
{
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
);
mView
=
new
ColorBlobDetectionView
(
this
);
setContentView
(
mView
);
}
}
\ No newline at end of file
samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionView.java
0 → 100644
View file @
d015a50d
package
org
.
opencv
.
samples
.
colorblobdetect
;
import
org.opencv.android.Utils
;
import
org.opencv.core.Mat
;
import
org.opencv.highgui.Highgui
;
import
org.opencv.highgui.VideoCapture
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.util.Log
;
import
android.view.MotionEvent
;
import
android.view.SurfaceHolder
;
import
android.view.View
;
import
android.view.View.OnTouchListener
;
public
class
ColorBlobDetectionView
extends
SampleCvViewBase
implements
OnTouchListener
{
private
Mat
mRgba
;
private
static
final
String
TAG
=
"Example/CollorBlobDetection"
;
public
ColorBlobDetectionView
(
Context
context
)
{
super
(
context
);
setOnTouchListener
(
this
);
}
@Override
public
void
surfaceChanged
(
SurfaceHolder
_holder
,
int
format
,
int
width
,
int
height
)
{
super
.
surfaceChanged
(
_holder
,
format
,
width
,
height
);
synchronized
(
this
)
{
// initialize Mat before usage
mRgba
=
new
Mat
();
}
}
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
// TODO Auto-generated method stub
int
cols
=
mRgba
.
cols
();
int
rows
=
mRgba
.
rows
();
int
xoffset
=
(
getWidth
()
-
cols
)
/
2
;
int
yoffset
=
(
getHeight
()
-
rows
)
/
2
;
int
x
=
(
int
)
event
.
getX
()
-
xoffset
;
int
y
=
(
int
)
event
.
getY
()
-
yoffset
;
double
TouchedColor
[]
=
mRgba
.
get
(
x
,
y
);
Log
.
i
(
TAG
,
"Touch coordinates: ("
+
x
+
", "
+
y
+
")"
);
Log
.
i
(
TAG
,
"Touched rgba color: ("
+
TouchedColor
[
0
]
+
", "
+
TouchedColor
[
1
]
+
", "
+
TouchedColor
[
2
]
+
", "
+
TouchedColor
[
0
]
+
",)"
);
return
false
;
// don't need subsequent touch events
}
@Override
protected
Bitmap
processFrame
(
VideoCapture
capture
)
{
// TODO Auto-generated method stub
capture
.
retrieve
(
mRgba
,
Highgui
.
CV_CAP_ANDROID_COLOR_FRAME_RGBA
);
Bitmap
bmp
=
Bitmap
.
createBitmap
(
mRgba
.
cols
(),
mRgba
.
rows
(),
Bitmap
.
Config
.
ARGB_8888
);
try
{
Utils
.
matToBitmap
(
mRgba
,
bmp
);
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Utils.matToBitmap() throws an exception: "
+
e
.
getMessage
());
bmp
.
recycle
();
bmp
=
null
;
}
return
bmp
;
}
@Override
public
void
run
()
{
super
.
run
();
synchronized
(
this
)
{
// Explicitly deallocate Mats
if
(
mRgba
!=
null
)
mRgba
.
release
();
mRgba
=
null
;
}
}
}
samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/SampleCvViewBase.java
0 → 100644
View file @
d015a50d
package
org
.
opencv
.
samples
.
colorblobdetect
;
import
java.util.List
;
import
org.opencv.core.Size
;
import
org.opencv.highgui.VideoCapture
;
import
org.opencv.highgui.Highgui
;
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
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