diff --git a/modules/java/generator/src/java/android+JavaCameraView.java b/modules/java/generator/src/java/android+JavaCameraView.java index a4ab627d0c..e3e80c61ca 100644 --- a/modules/java/generator/src/java/android+JavaCameraView.java +++ b/modules/java/generator/src/java/android+JavaCameraView.java @@ -57,13 +57,16 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb public JavaCameraView(Context context, AttributeSet attrs) { super(context, attrs); + Log.d(TAG, "Java camera view ctor"); } @TargetApi(11) protected boolean initializeCamera(int width, int height) { + Log.d(TAG, "Initialize java camera"); synchronized (this) { mCamera = null; + Log.d(TAG, "Trying to open camera with old open()"); try { mCamera = Camera.open(); } @@ -72,31 +75,30 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb } if(mCamera == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + boolean connected = false; for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); ++camIdx) { + Log.d(TAG, "Trying to open camera with new open(" + Integer.valueOf(camIdx) + ")"); try { mCamera = Camera.open(camIdx); - } - catch (RuntimeException e) { + connected = true; + } catch (RuntimeException e) { Log.e(TAG, "Camera #" + camIdx + "failed to open: " + e.getLocalizedMessage()); } + if (connected) break; } } if (mCamera == null) return false; - mCamera.setPreviewCallbackWithBuffer(this); - - List sizes = mCamera.getParameters().getSupportedPreviewSizes(); - /* Select the size that fits surface considering maximum size allowed */ - Size frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height); - - mFrameWidth = (int)frameSize.width; - mFrameHeight = (int)frameSize.height; - /* Now set camera parameters */ try { Camera.Parameters params = mCamera.getParameters(); + Log.d(TAG, "getSupportedPreviewSizes()"); + List sizes = params.getSupportedPreviewSizes(); + + /* Select the size that fits surface considering maximum size allowed */ + Size frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height); params.setPreviewFormat(ImageFormat.NV21); params.setPreviewSize((int)frameSize.width, (int)frameSize.height); @@ -110,11 +112,15 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb mCamera.setParameters(params); params = mCamera.getParameters(); - int size = params.getPreviewSize().width * params.getPreviewSize().height; + mFrameWidth = params.getPreviewSize().width; + mFrameHeight = params.getPreviewSize().height; + + int size = mFrameWidth * mFrameHeight; size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8; mBuffer = new byte[size]; mCamera.addCallbackBuffer(mBuffer); + mCamera.setPreviewCallbackWithBuffer(this); mBaseMat = new Mat(mFrameHeight + (mFrameHeight/2), mFrameWidth, CvType.CV_8UC1); @@ -131,6 +137,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb } /* Finally we are ready to start the preview */ + Log.d(TAG, "startPreview"); mCamera.startPreview(); } diff --git a/samples/android/15-puzzle/AndroidManifest.xml b/samples/android/15-puzzle/AndroidManifest.xml index ad0e699ac3..184d3d761e 100644 --- a/samples/android/15-puzzle/AndroidManifest.xml +++ b/samples/android/15-puzzle/AndroidManifest.xml @@ -23,6 +23,8 @@ + + diff --git a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java index 293f8d8bf7..19744f9eee 100644 --- a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java +++ b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java @@ -259,6 +259,7 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView } public Mat onCameraFrame(Mat inputFrame) { + inputFrame.copyTo(mRgba); switch (ImageManipulationsActivity.viewMode) { case ImageManipulationsActivity.VIEW_MODE_RGBA: