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
de0997ab
Commit
de0997ab
authored
Mar 02, 2015
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3749 from alalek:fix_android_camera_master
parents
8e37a693
52effe9e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
7 deletions
+24
-7
android+JavaCameraView.java
modules/java/generator/src/java/android+JavaCameraView.java
+24
-7
No files found.
modules/java/generator/src/java/android+JavaCameraView.java
View file @
de0997ab
...
...
@@ -43,11 +43,13 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
public
static
class
JavaCameraSizeAccessor
implements
ListItemAccessor
{
@Override
public
int
getWidth
(
Object
obj
)
{
Camera
.
Size
size
=
(
Camera
.
Size
)
obj
;
return
size
.
width
;
}
@Override
public
int
getHeight
(
Object
obj
)
{
Camera
.
Size
size
=
(
Camera
.
Size
)
obj
;
return
size
.
height
;
...
...
@@ -228,6 +230,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
}
}
private
boolean
mCameraFrameReady
=
false
;
@Override
protected
boolean
connectCamera
(
int
width
,
int
height
)
{
...
...
@@ -239,6 +243,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
if
(!
initializeCamera
(
width
,
height
))
return
false
;
mCameraFrameReady
=
false
;
/* now we can start update thread */
Log
.
d
(
TAG
,
"Starting processing thread"
);
mStopThread
=
false
;
...
...
@@ -248,6 +254,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
return
true
;
}
@Override
protected
void
disconnectCamera
()
{
/* 1. We need to stop thread which updating the frames
* 2. Stop camera and release it
...
...
@@ -270,12 +277,16 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
/* Now release camera */
releaseCamera
();
mCameraFrameReady
=
false
;
}
@Override
public
void
onPreviewFrame
(
byte
[]
frame
,
Camera
arg1
)
{
Log
.
d
(
TAG
,
"Preview Frame received. Frame size: "
+
frame
.
length
);
synchronized
(
this
)
{
mFrameChain
[
1
-
mChainIdx
].
put
(
0
,
0
,
frame
);
mFrameChain
[
mChainIdx
].
put
(
0
,
0
,
frame
);
mCameraFrameReady
=
true
;
this
.
notify
();
}
if
(
mCamera
!=
null
)
...
...
@@ -283,10 +294,12 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
}
private
class
JavaCameraFrame
implements
CvCameraViewFrame
{
@Override
public
Mat
gray
()
{
return
mYuvFrameData
.
submat
(
0
,
mHeight
,
0
,
mWidth
);
}
@Override
public
Mat
rgba
()
{
Imgproc
.
cvtColor
(
mYuvFrameData
,
mRgba
,
Imgproc
.
COLOR_YUV2RGBA_NV21
,
4
);
return
mRgba
;
...
...
@@ -312,21 +325,25 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
private
class
CameraWorker
implements
Runnable
{
@Override
public
void
run
()
{
do
{
synchronized
(
JavaCameraView
.
this
)
{
try
{
JavaCameraView
.
this
.
wait
();
while
(!
mCameraFrameReady
&&
!
mStopThread
)
{
JavaCameraView
.
this
.
wait
();
}
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
if
(
mCameraFrameReady
)
mChainIdx
=
1
-
mChainIdx
;
}
if
(!
mStopThread
)
{
if
(!
mFrameChain
[
mChainIdx
].
empty
())
deliverAndDrawFrame
(
mCameraFrame
[
mChainIdx
]);
mChainIdx
=
1
-
mChainIdx
;
if
(!
mStopThread
&&
mCameraFrameReady
)
{
mCameraFrameReady
=
false
;
if
(!
mFrameChain
[
1
-
mChainIdx
].
empty
())
deliverAndDrawFrame
(
mCameraFrame
[
1
-
mChainIdx
])
;
}
}
while
(!
mStopThread
);
Log
.
d
(
TAG
,
"Finish processing thread"
);
...
...
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