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
2faa2ada
Commit
2faa2ada
authored
May 07, 2013
by
Andrey Pavlenko
Committed by
OpenCV Buildbot
May 07, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #846 from smart-mobile-software:tuto_crash
parents
48a8aefd
7dda8e2c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
25 deletions
+34
-25
android+JavaCameraView.java
modules/java/generator/src/java/android+JavaCameraView.java
+2
-0
Tutorial3View.java
...ntrol/src/org/opencv/samples/tutorial3/Tutorial3View.java
+32
-25
No files found.
modules/java/generator/src/java/android+JavaCameraView.java
View file @
2faa2ada
...
...
@@ -208,6 +208,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
synchronized
(
this
)
{
if
(
mCamera
!=
null
)
{
mCamera
.
stopPreview
();
mCamera
.
setPreviewCallback
(
null
);
mCamera
.
release
();
}
mCamera
=
null
;
...
...
samples/android/tutorial-3-cameracontrol/src/org/opencv/samples/tutorial3/Tutorial3View.java
View file @
2faa2ada
...
...
@@ -6,17 +6,16 @@ import java.util.List;
import
org.opencv.android.JavaCameraView
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.hardware.Camera
;
import
android.hardware.Camera.PictureCallback
;
import
android.hardware.Camera.Size
;
import
android.util.AttributeSet
;
import
android.util.Log
;
public
class
Tutorial3View
extends
JavaCameraView
{
public
class
Tutorial3View
extends
JavaCameraView
implements
PictureCallback
{
private
static
final
String
TAG
=
"Sample::Tutorial3View"
;
private
String
mPictureFileName
;
public
Tutorial3View
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
...
...
@@ -56,26 +55,33 @@ public class Tutorial3View extends JavaCameraView {
}
public
void
takePicture
(
final
String
fileName
)
{
Log
.
i
(
TAG
,
"Tacking picture"
);
PictureCallback
callback
=
new
PictureCallback
()
{
private
String
mPictureFileName
=
fileName
;
@Override
public
void
onPictureTaken
(
byte
[]
data
,
Camera
camera
)
{
Log
.
i
(
TAG
,
"Saving a bitmap to file"
);
Bitmap
picture
=
BitmapFactory
.
decodeByteArray
(
data
,
0
,
data
.
length
);
try
{
FileOutputStream
out
=
new
FileOutputStream
(
mPictureFileName
);
picture
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
90
,
out
);
picture
.
recycle
();
mCamera
.
startPreview
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
};
mCamera
.
takePicture
(
null
,
null
,
callback
);
Log
.
i
(
TAG
,
"Taking picture"
);
this
.
mPictureFileName
=
fileName
;
// Postview and jpeg are sent in the same buffers if the queue is not empty when performing a capture.
// Clear up buffers to avoid mCamera.takePicture to be stuck because of a memory issue
mCamera
.
setPreviewCallback
(
null
);
// PictureCallback is implemented by the current class
mCamera
.
takePicture
(
null
,
null
,
this
);
}
}
@Override
public
void
onPictureTaken
(
byte
[]
data
,
Camera
camera
)
{
Log
.
i
(
TAG
,
"Saving a bitmap to file"
);
// The camera preview was automatically stopped. Start it again.
mCamera
.
startPreview
();
mCamera
.
setPreviewCallback
(
this
);
// Write the image in a file (in jpeg format)
try
{
FileOutputStream
fos
=
new
FileOutputStream
(
mPictureFileName
);
fos
.
write
(
data
);
fos
.
close
();
}
catch
(
java
.
io
.
IOException
e
)
{
Log
.
e
(
"PictureDemo"
,
"Exception in photoCallback"
,
e
);
}
}
}
\ 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