Commit 15db8243 authored by Andrey Pavlenko's avatar Andrey Pavlenko

refactored; added Camera2, notify callbacks, front/back maxCamera sizes; disable…

refactored; added Camera2, notify callbacks, front/back maxCamera sizes; disable new stuff if target API < 21
parent 8e088d38
...@@ -181,6 +181,17 @@ else() ...@@ -181,6 +181,17 @@ else()
list(REMOVE_ITEM handwrittren_lib_project_files_rel "${ANDROID_MANIFEST_FILE}") list(REMOVE_ITEM handwrittren_lib_project_files_rel "${ANDROID_MANIFEST_FILE}")
endif() endif()
# Calc default SDK Target
android_get_compatible_target(android_sdk_target ${ANDROID_NATIVE_API_LEVEL} ${ANDROID_SDK_TARGET} 11)
string(REGEX REPLACE "android-" "" android_sdk_target_num ${android_sdk_target})
if( (ANDROID_SDK_TARGET AND ANDROID_SDK_TARGET LESS 21) OR (android_sdk_target_num LESS 21) )
message(STATUS "[OpenCV for Android SDK]: A new OpenGL Camera Bridge (CameraGLSurfaceView, CameraGLRendererBase, CameraRenderer, Camera2Renderer) is disabled, because ANDROID_SDK_TARGET (${android_sdk_target_num}) < 21")
ocv_list_filterout(handwritten_java_sources "android\\\\+CameraGL")
ocv_list_filterout(handwritten_java_sources "android\\\\+Camera.?Renderer")
endif()
# IMPORTANT: add dependencies to cmake (we should rerun cmake if any of these files is modified) # IMPORTANT: add dependencies to cmake (we should rerun cmake if any of these files is modified)
add_cmake_dependencies(${scripts_gen_java} ${scripts_hdr_parser} ${opencv_public_headers}) add_cmake_dependencies(${scripts_gen_java} ${scripts_hdr_parser} ${opencv_public_headers})
......
This diff is collapsed.
package org.opencv.android; package org.opencv.android;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; import org.opencv.R;
import org.opencv.core.Mat;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.widget.TextView;
public class CameraGLSurfaceView extends GLSurfaceView { public class CameraGLSurfaceView extends GLSurfaceView {
private static final String LOGTAG = "CameraGLSurfaceView";
public interface CameraTextureListener { public interface CameraTextureListener {
/** /**
* This method is invoked when camera preview has started. After this method is invoked * This method is invoked when camera preview has started. After this method is invoked
...@@ -29,24 +29,33 @@ public class CameraGLSurfaceView extends GLSurfaceView { ...@@ -29,24 +29,33 @@ public class CameraGLSurfaceView extends GLSurfaceView {
public void onCameraViewStopped(); public void onCameraViewStopped();
/** /**
* This method is invoked when delivery of the frame needs to be done. * This method is invoked when a new preview frame from Camera is ready.
* The returned values - is a modified frame which needs to be displayed on the screen. * @param texIn - the OpenGL texture ID that contains frame in RGBA format
* TODO: pass the parameters specifying the format of the frame (BPP, YUV or RGB and etc) * @param texOut - the OpenGL texture ID that can be used to store modified frame image t display
* @param width - the width of the frame
* @param height - the height of the frame
* @return `true` if `texOut` should be displayed, `false` - to show `texIn`
*/ */
public boolean onCameraFrame(int texIn, int texOut, int width, int height); public boolean onCameraTexture(int texIn, int texOut, int width, int height);
}; };
private CameraTextureListener mTexListener; private CameraTextureListener mTexListener;
private CameraRenderer mRenderer; private CameraGLRendererBase mRenderer;
public CameraGLSurfaceView(Context context, AttributeSet attrs) { public CameraGLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
/*if(android.os.Build.VERSION.SDK_INT >= 21) TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
int cameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);
styledAttrs.recycle();
if(android.os.Build.VERSION.SDK_INT >= 21)
mRenderer = new Camera2Renderer(this); mRenderer = new Camera2Renderer(this);
else*/ else
mRenderer = new CameraRenderer(this); mRenderer = new CameraRenderer(this);
setCameraIndex(cameraIndex);
setEGLContextClientVersion(2); setEGLContextClientVersion(2);
setRenderer(mRenderer); setRenderer(mRenderer);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
...@@ -62,6 +71,14 @@ public class CameraGLSurfaceView extends GLSurfaceView { ...@@ -62,6 +71,14 @@ public class CameraGLSurfaceView extends GLSurfaceView {
return mTexListener; return mTexListener;
} }
public void setCameraIndex(int cameraIndex) {
mRenderer.setCameraIndex(cameraIndex);
}
public void setMaxCameraPreviewSize(int maxWidth, int maxHeight) {
mRenderer.setMaxCameraPreviewSize(maxWidth, maxHeight);
}
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
super.surfaceCreated(holder); super.surfaceCreated(holder);
...@@ -69,6 +86,7 @@ public class CameraGLSurfaceView extends GLSurfaceView { ...@@ -69,6 +86,7 @@ public class CameraGLSurfaceView extends GLSurfaceView {
@Override @Override
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
mRenderer.mHaveSurface = false;
super.surfaceDestroyed(holder); super.surfaceDestroyed(holder);
} }
...@@ -79,20 +97,23 @@ public class CameraGLSurfaceView extends GLSurfaceView { ...@@ -79,20 +97,23 @@ public class CameraGLSurfaceView extends GLSurfaceView {
@Override @Override
public void onResume() { public void onResume() {
Log.i(LOGTAG, "onResume");
super.onResume(); super.onResume();
mRenderer.onResume(); mRenderer.onResume();
} }
@Override @Override
public void onPause() { public void onPause() {
Log.i(LOGTAG, "onPause");
mRenderer.onPause(); mRenderer.onPause();
super.onPause(); super.onPause();
} }
@Override public void enableView() {
public boolean onTouchEvent(MotionEvent e) { mRenderer.enableView();
if(e.getAction() == MotionEvent.ACTION_DOWN) }
((Activity)getContext()).openOptionsMenu();
return true; public void disableView() {
mRenderer.disableView();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment