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
cd59cf3a
Commit
cd59cf3a
authored
Aug 28, 2012
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed java camera release in Android tutorial-0 sample
parent
4d6730dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
Sample0View.java
...dcamera/src/org/opencv/samples/tutorial0/Sample0View.java
+1
-1
SampleViewBase.java
...mera/src/org/opencv/samples/tutorial0/SampleViewBase.java
+21
-5
No files found.
samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/Sample0View.java
View file @
cd59cf3a
...
...
@@ -6,7 +6,7 @@ import android.util.Log;
class
Sample0View
extends
SampleViewBase
{
private
static
final
String
TAG
=
"Sample
0
View"
;
private
static
final
String
TAG
=
"Sample
::
View"
;
int
mSize
;
int
[]
mRGBA
;
private
Bitmap
mBitmap
;
...
...
samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java
View file @
cd59cf3a
...
...
@@ -23,7 +23,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
private
int
mFrameWidth
;
private
int
mFrameHeight
;
private
byte
[]
mFrame
;
private
boolean
mThreadRun
;
private
volatile
boolean
mThreadRun
;
private
byte
[]
mBuffer
;
private
SurfaceTexture
mSf
;
...
...
@@ -55,9 +55,16 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
public
boolean
openCamera
()
{
Log
.
i
(
TAG
,
"openCamera"
);
mCamera
=
Camera
.
open
();
mCamera
=
null
;
try
{
mCamera
=
Camera
.
open
();
}
catch
(
Exception
e
){
Log
.
e
(
TAG
,
"Camera is not available (in use or does not exist)"
);
e
.
printStackTrace
();
}
if
(
mCamera
==
null
)
{
Log
.
e
(
TAG
,
"
Can't open camera!
"
);
Log
.
e
(
TAG
,
"
Failed to open camera
"
);
return
false
;
}
...
...
@@ -79,7 +86,6 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
synchronized
(
this
)
{
if
(
mCamera
!=
null
)
{
mCamera
.
stopPreview
();
mCamera
.
setPreviewCallback
(
null
);
mCamera
.
release
();
mCamera
=
null
;
}
...
...
@@ -91,6 +97,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
Log
.
i
(
TAG
,
"setupCamera"
);
synchronized
(
this
)
{
if
(
mCamera
!=
null
)
{
Log
.
i
(
TAG
,
"setupCamera - "
+
width
+
"x"
+
height
);
Camera
.
Parameters
params
=
mCamera
.
getParameters
();
List
<
Camera
.
Size
>
sizes
=
params
.
getSupportedPreviewSizes
();
mFrameWidth
=
width
;
...
...
@@ -144,6 +151,14 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
public
void
surfaceChanged
(
SurfaceHolder
_holder
,
int
format
,
int
width
,
int
height
)
{
Log
.
i
(
TAG
,
"surfaceChanged"
);
// stop preview before making changes
try
{
mCamera
.
stopPreview
();
}
catch
(
Exception
e
){
// ignore: tried to stop a non-existent preview
}
// start preview with new settings
setupCamera
(
width
,
height
);
}
...
...
@@ -154,7 +169,6 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
Log
.
i
(
TAG
,
"surfaceDestroyed"
);
releaseCamera
();
}
/* The bitmap returned by this method shall be owned by the child and released in onPreviewStopped() */
...
...
@@ -184,6 +198,8 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
synchronized
(
this
)
{
try
{
this
.
wait
();
if
(!
mThreadRun
)
break
;
bmp
=
processFrame
(
mFrame
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
...
...
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