Front/back camera constants semantic for Android fixed (Bug #2839).
Front/Back camera constants' values changed; Additional camera facing check added for JavaCameraView.
This commit is contained in:
parent
aef8e6ba59
commit
6e8f5ae574
@ -4,8 +4,8 @@
|
|||||||
<attr name="show_fps" format="boolean"/>
|
<attr name="show_fps" format="boolean"/>
|
||||||
<attr name="camera_id" format="integer" >
|
<attr name="camera_id" format="integer" >
|
||||||
<enum name="any" value="-1" />
|
<enum name="any" value="-1" />
|
||||||
<enum name="back" value="0" />
|
<enum name="back" value="99" />
|
||||||
<enum name="front" value="1" />
|
<enum name="front" value="98" />
|
||||||
</attr>
|
</attr>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -47,10 +47,14 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac
|
|||||||
protected int mMaxWidth;
|
protected int mMaxWidth;
|
||||||
protected float mScale = 0;
|
protected float mScale = 0;
|
||||||
protected int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA;
|
protected int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA;
|
||||||
protected int mCameraIndex = -1;
|
protected int mCameraIndex = CAMERA_ID_ANY;
|
||||||
protected boolean mEnabled;
|
protected boolean mEnabled;
|
||||||
protected FpsMeter mFpsMeter = null;
|
protected FpsMeter mFpsMeter = null;
|
||||||
|
|
||||||
|
public static final int CAMERA_ID_ANY = -1;
|
||||||
|
public static final int CAMERA_ID_BACK = 99;
|
||||||
|
public static final int CAMERA_ID_FRONT = 98;
|
||||||
|
|
||||||
public CameraBridgeViewBase(Context context, int cameraId) {
|
public CameraBridgeViewBase(Context context, int cameraId) {
|
||||||
super(context);
|
super(context);
|
||||||
mCameraIndex = cameraId;
|
mCameraIndex = cameraId;
|
||||||
|
@ -6,6 +6,7 @@ import android.content.Context;
|
|||||||
import android.graphics.ImageFormat;
|
import android.graphics.ImageFormat;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
|
import android.hardware.Camera.CameraInfo;
|
||||||
import android.hardware.Camera.PreviewCallback;
|
import android.hardware.Camera.PreviewCallback;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@ -68,7 +69,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
mCamera = null;
|
mCamera = null;
|
||||||
|
|
||||||
if (mCameraIndex == -1) {
|
if (mCameraIndex == CAMERA_ID_ANY) {
|
||||||
Log.d(TAG, "Trying to open camera with old open()");
|
Log.d(TAG, "Trying to open camera with old open()");
|
||||||
try {
|
try {
|
||||||
mCamera = Camera.open();
|
mCamera = Camera.open();
|
||||||
@ -92,11 +93,39 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||||
Log.d(TAG, "Trying to open camera with new open(" + Integer.valueOf(mCameraIndex) + ")");
|
int localCameraIndex = mCameraIndex;
|
||||||
try {
|
if (mCameraIndex == CAMERA_ID_BACK) {
|
||||||
mCamera = Camera.open(mCameraIndex);
|
Log.i(TAG, "Trying to open back camera");
|
||||||
} catch (RuntimeException e) {
|
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
|
||||||
Log.e(TAG, "Camera #" + mCameraIndex + "failed to open: " + e.getLocalizedMessage());
|
for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
|
||||||
|
Camera.getCameraInfo( camIdx, cameraInfo );
|
||||||
|
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
|
||||||
|
localCameraIndex = camIdx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (mCameraIndex == CAMERA_ID_FRONT) {
|
||||||
|
Log.i(TAG, "Trying to open front camera");
|
||||||
|
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
|
||||||
|
for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
|
||||||
|
Camera.getCameraInfo( camIdx, cameraInfo );
|
||||||
|
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
||||||
|
localCameraIndex = camIdx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (localCameraIndex == CAMERA_ID_BACK) {
|
||||||
|
Log.e(TAG, "Back camera not found!");
|
||||||
|
} else if (localCameraIndex == CAMERA_ID_FRONT) {
|
||||||
|
Log.e(TAG, "Front camera not found!");
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Trying to open camera with new open(" + Integer.valueOf(localCameraIndex) + ")");
|
||||||
|
try {
|
||||||
|
mCamera = Camera.open(localCameraIndex);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Log.e(TAG, "Camera #" + localCameraIndex + "failed to open: " + e.getLocalizedMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user