Skip to content

Commit

Permalink
Bug opencv#3391 org.opencv.android.NativeCameraView crashes after lat…
Browse files Browse the repository at this point in the history
…est OpenCV Manager update fixed.

The crash was cased by massive Mat objects leak in NativeCameraView class.
  • Loading branch information
asmorkalov committed Feb 25, 2014
1 parent 5142109 commit c78142a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/java/generator/src/java/android+NativeCameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class NativeCameraView extends CameraBridgeViewBase {
private Thread mThread;

protected VideoCapture mCamera;
protected NativeCameraFrame mFrame;

public NativeCameraView(Context context, int cameraId) {
super(context, cameraId);
Expand Down Expand Up @@ -97,6 +98,8 @@ private boolean initializeCamera(int width, int height) {
if (mCamera.isOpened() == false)
return false;

mFrame = new NativeCameraFrame(mCamera);

java.util.List<Size> sizes = mCamera.getSupportedPreviewSizes();

/* Select the size that fits surface considering maximum size allowed */
Expand Down Expand Up @@ -127,9 +130,8 @@ private boolean initializeCamera(int width, int height) {

private void releaseCamera() {
synchronized (this) {
if (mCamera != null) {
mCamera.release();
}
if (mFrame != null) mFrame.release();
if (mCamera != null) mCamera.release();
}
}

Expand All @@ -153,6 +155,11 @@ public NativeCameraFrame(VideoCapture capture) {
mRgba = new Mat();
}

public void release() {
if (mGray != null) mGray.release();
if (mRgba != null) mRgba.release();
}

private VideoCapture mCapture;
private Mat mRgba;
private Mat mGray;
Expand All @@ -167,7 +174,7 @@ public void run() {
break;
}

deliverAndDrawFrame(new NativeCameraFrame(mCamera));
deliverAndDrawFrame(mFrame);

} while (!mStopThread);
}
Expand Down

0 comments on commit c78142a

Please sign in to comment.