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
2e5a7284
Commit
2e5a7284
authored
Nov 27, 2012
by
Alexander Smorkalov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code review comments applied.
parent
e95fc274
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
48 deletions
+39
-48
android+CameraBridgeViewBase.java
...java/generator/src/java/android+CameraBridgeViewBase.java
+11
-19
android+FpsMeter.java
modules/java/generator/src/java/android+FpsMeter.java
+28
-29
No files found.
modules/java/generator/src/java/android+CameraBridgeViewBase.java
View file @
2e5a7284
...
...
@@ -28,35 +28,27 @@ import android.view.SurfaceView;
* The clients shall implement CvCameraViewListener.
*/
public
abstract
class
CameraBridgeViewBase
extends
SurfaceView
implements
SurfaceHolder
.
Callback
{
//TODO: add method to control the format in which the frames will be delivered to CvCameraViewListener
private
static
final
String
TAG
=
"CameraBridge"
;
private
static
final
int
MAX_UNSPECIFIED
=
-
1
;
private
static
final
int
STOPPED
=
0
;
private
static
final
int
STARTED
=
1
;
private
static
final
String
TAG
=
"CameraBridge"
;
private
int
mState
=
STOPPED
;
private
Bitmap
mCacheBitmap
;
private
CvCameraViewListener
mListener
;
private
boolean
mSurfaceExist
;
private
Object
mSyncObject
=
new
Object
();
protected
int
mFrameWidth
;
protected
int
mFrameHeight
;
protected
int
mMaxHeight
;
protected
int
mMaxWidth
;
protected
int
mPreviewFormat
=
Highgui
.
CV_CAP_ANDROID_COLOR_FRAME_RGBA
;
protected
int
mCameraIndex
=
-
1
;
private
boolean
mEnabled
;
private
Bitmap
mCacheBitmap
;
protected
boolean
mEnabled
;
protected
FpsMeter
mFpsMeter
=
null
;
private
CvCameraViewListener
mListener
;
private
int
mState
=
STOPPED
;
private
boolean
mSurfaceExist
;
private
Object
mSyncObject
=
new
Object
();
public
CameraBridgeViewBase
(
Context
context
,
int
cameraId
)
{
super
(
context
);
mCameraIndex
=
cameraId
;
...
...
@@ -68,11 +60,11 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
int
count
=
attrs
.
getAttributeCount
();
Log
.
d
(
TAG
,
"Attr count: "
+
Integer
.
valueOf
(
count
));
TypedArray
tmp
=
getContext
().
obtainStyledAttributes
(
attrs
,
R
.
styleable
.
CameraBridgeViewBase
);
if
(
tmp
.
getBoolean
(
R
.
styleable
.
CameraBridgeViewBase_show_fps
,
false
))
TypedArray
styledAttrs
=
getContext
().
obtainStyledAttributes
(
attrs
,
R
.
styleable
.
CameraBridgeViewBase
);
if
(
styledAttrs
.
getBoolean
(
R
.
styleable
.
CameraBridgeViewBase_show_fps
,
false
))
enableFpsMeter
();
mCameraIndex
=
tmp
.
getInt
(
R
.
styleable
.
CameraBridgeViewBase_camera_id
,
-
1
);
mCameraIndex
=
styledAttrs
.
getInt
(
R
.
styleable
.
CameraBridgeViewBase_camera_id
,
-
1
);
getHolder
().
addCallback
(
this
);
mMaxWidth
=
MAX_UNSPECIFIED
;
...
...
@@ -312,7 +304,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
canvas
.
drawBitmap
(
mCacheBitmap
,
(
canvas
.
getWidth
()
-
mCacheBitmap
.
getWidth
())
/
2
,
(
canvas
.
getHeight
()
-
mCacheBitmap
.
getHeight
())
/
2
,
null
);
if
(
mFpsMeter
!=
null
)
{
mFpsMeter
.
measure
();
mFpsMeter
.
draw
(
canvas
,
0
,
0
);
mFpsMeter
.
draw
(
canvas
,
20
,
3
0
);
}
getHolder
().
unlockCanvasAndPost
(
canvas
);
}
...
...
modules/java/generator/src/java/android+FpsMeter.java
View file @
2e5a7284
...
...
@@ -10,46 +10,45 @@ import android.graphics.Paint;
import
android.util.Log
;
public
class
FpsMeter
{
private
static
final
String
TAG
=
"OCVSample::FpsMeter"
;
int
step
;
int
framesCouner
;
double
freq
;
long
prevFrameTime
;
String
strfps
;
DecimalFormat
twoPlaces
=
new
DecimalFormat
(
"0.00"
);
Paint
paint
;
boolean
isInitialized
=
false
;
private
static
final
String
TAG
=
"FpsMeter"
;
private
static
final
int
STEP
=
20
;
private
static
final
DecimalFormat
FPS_FORMAT
=
new
DecimalFormat
(
"0.00"
);
private
int
mFramesCouner
;
private
double
mFrequency
;
private
long
mprevFrameTime
;
private
String
mStrfps
;
Paint
mPaint
;
boolean
mIsInitialized
=
false
;
int
mWidth
=
0
;
int
mHeight
=
0
;
public
void
init
()
{
step
=
20
;
framesCouner
=
0
;
freq
=
Core
.
getTickFrequency
();
prevFrameTime
=
Core
.
getTickCount
();
strfps
=
""
;
mFramesCouner
=
0
;
mFrequency
=
Core
.
getTickFrequency
();
mprevFrameTime
=
Core
.
getTickCount
();
mStrfps
=
""
;
p
aint
=
new
Paint
();
p
aint
.
setColor
(
Color
.
BLUE
);
paint
.
setTextSize
(
5
0
);
mP
aint
=
new
Paint
();
mP
aint
.
setColor
(
Color
.
BLUE
);
mPaint
.
setTextSize
(
2
0
);
}
public
void
measure
()
{
if
(!
i
sInitialized
)
{
if
(!
mI
sInitialized
)
{
init
();
i
sInitialized
=
true
;
mI
sInitialized
=
true
;
}
else
{
f
ramesCouner
++;
if
(
framesCouner
%
step
==
0
)
{
mF
ramesCouner
++;
if
(
mFramesCouner
%
STEP
==
0
)
{
long
time
=
Core
.
getTickCount
();
double
fps
=
step
*
freq
/
(
time
-
prevFrameTime
);
prevFrameTime
=
time
;
DecimalFormat
twoPlaces
=
new
DecimalFormat
(
"0.00"
);
double
fps
=
STEP
*
mFrequency
/
(
time
-
mprevFrameTime
);
mprevFrameTime
=
time
;
if
(
mWidth
!=
0
&&
mHeight
!=
0
)
strfps
=
twoPlaces
.
format
(
fps
)
+
" FPS@"
+
Integer
.
valueOf
(
mWidth
)
+
"x"
+
Integer
.
valueOf
(
mHeight
);
mStrfps
=
FPS_FORMAT
.
format
(
fps
)
+
" FPS@"
+
Integer
.
valueOf
(
mWidth
)
+
"x"
+
Integer
.
valueOf
(
mHeight
);
else
strfps
=
twoPlaces
.
format
(
fps
)
+
" FPS"
;
Log
.
i
(
TAG
,
s
trfps
);
mStrfps
=
FPS_FORMAT
.
format
(
fps
)
+
" FPS"
;
Log
.
i
(
TAG
,
mS
trfps
);
}
}
}
...
...
@@ -60,8 +59,8 @@ public class FpsMeter {
}
public
void
draw
(
Canvas
canvas
,
float
offsetx
,
float
offsety
)
{
Log
.
d
(
TAG
,
s
trfps
);
canvas
.
drawText
(
strfps
,
20
+
offsetx
,
10
+
50
+
offsety
,
p
aint
);
Log
.
d
(
TAG
,
mS
trfps
);
canvas
.
drawText
(
mStrfps
,
offsetx
,
offsety
,
mP
aint
);
}
}
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