|
|
|
@ -41,6 +41,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb |
|
|
|
|
protected Camera mCamera; |
|
|
|
|
protected JavaCameraFrame[] mCameraFrame; |
|
|
|
|
private SurfaceTexture mSurfaceTexture; |
|
|
|
|
private int mPreviewFormat = ImageFormat.NV21; |
|
|
|
|
|
|
|
|
|
public static class JavaCameraSizeAccessor implements ListItemAccessor { |
|
|
|
|
|
|
|
|
@ -145,7 +146,14 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb |
|
|
|
|
/* Select the size that fits surface considering maximum size allowed */ |
|
|
|
|
Size frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height); |
|
|
|
|
|
|
|
|
|
params.setPreviewFormat(ImageFormat.NV21); |
|
|
|
|
/* Image format NV21 causes issues in the Android emulators */ |
|
|
|
|
if (Build.BRAND.equalsIgnoreCase("generic") || Build.BRAND.equalsIgnoreCase("Android")) |
|
|
|
|
params.setPreviewFormat(ImageFormat.YV12); // "generic" or "android" = android emulator
|
|
|
|
|
else |
|
|
|
|
params.setPreviewFormat(ImageFormat.NV21); |
|
|
|
|
|
|
|
|
|
mPreviewFormat = params.getPreviewFormat(); |
|
|
|
|
|
|
|
|
|
Log.d(TAG, "Set preview size to " + Integer.valueOf((int)frameSize.width) + "x" + Integer.valueOf((int)frameSize.height)); |
|
|
|
|
params.setPreviewSize((int)frameSize.width, (int)frameSize.height); |
|
|
|
|
|
|
|
|
@ -303,7 +311,13 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Mat rgba() { |
|
|
|
|
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGBA_NV21, 4); |
|
|
|
|
if (mPreviewFormat == ImageFormat.NV21) |
|
|
|
|
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGBA_NV21, 4); |
|
|
|
|
else if (mPreviewFormat == ImageFormat.YV12) |
|
|
|
|
Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGB_I420, 4); // COLOR_YUV2RGBA_YV12 produces inverted colors
|
|
|
|
|
else |
|
|
|
|
throw new IllegalArgumentException("Preview Format can be NV21 or YV12"); |
|
|
|
|
|
|
|
|
|
return mRgba; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|