Commit cc3430db authored by Alexander Smorkalov's avatar Alexander Smorkalov Committed by Andrey Kamaev

Naming fixed;

Warnings fixed;
Nexus 7 support added to manifest.
parent cd152c3a
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
android:versionCode="1" android:versionCode="1"
android:versionName="1.0" > android:versionName="1.0" >
<uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.CAMERA" required="false"/>
<uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera" required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" /> <uses-feature android:name="android.hardware.camera.autofocus" required="false"/>
<uses-sdk android:minSdkVersion="8" /> <uses-sdk android:minSdkVersion="8" />
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme" > android:theme="@style/AppTheme" >
<activity <activity
android:name=".CameraWriterActivity" android:name=".PreviewActivity"
android:label="@string/title_activity_camera_writer" > android:label="@string/title_activity_camera_writer" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >
<view class="org.opencv.test.camerawriter.OpenCvNativeCameraView" <view class="org.opencv.test.camerawriter.NativeCameraView"
android:id="@+id/camera_surface_view" android:id="@+id/camera_surface_view"
android:layout_width = "fill_parent" android:layout_width = "fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
......
...@@ -5,8 +5,6 @@ import java.util.List; ...@@ -5,8 +5,6 @@ import java.util.List;
import org.opencv.android.Utils; import org.opencv.android.Utils;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.Size; import org.opencv.core.Size;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
...@@ -23,7 +21,7 @@ import android.view.SurfaceView; ...@@ -23,7 +21,7 @@ import android.view.SurfaceView;
* frame to the screen. * frame to the screen.
* The clients shall implement CvCameraViewListener * The clients shall implement CvCameraViewListener
*/ */
public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements SurfaceHolder.Callback { public abstract class CameraViewBase extends SurfaceView implements SurfaceHolder.Callback {
private static final int MAX_UNSPECIFIED = -1; private static final int MAX_UNSPECIFIED = -1;
...@@ -36,8 +34,9 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements ...@@ -36,8 +34,9 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements
private Bitmap mCacheBitmap; private Bitmap mCacheBitmap;
public OpenCvCameraBridgeViewBase(Context context, AttributeSet attrs) { public CameraViewBase(Context context, AttributeSet attrs) {
super(context,attrs); super(context,attrs);
Log.d(TAG, "call CameraViewBase constructor");
getHolder().addCallback(this); getHolder().addCallback(this);
mMaxWidth = MAX_UNSPECIFIED; mMaxWidth = MAX_UNSPECIFIED;
mMaxHeight = MAX_UNSPECIFIED; mMaxHeight = MAX_UNSPECIFIED;
...@@ -113,7 +112,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements ...@@ -113,7 +112,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements
/** /**
* This method is provided for clients, so they can enable the camera connection. * This method is provided for clients, so they can enable the camera connection.
* The actuall onCameraViewStarted callback will be delivered only after both this method is called and surface is available * The actual onCameraViewStarted callback will be delivered only after both this method is called and surface is available
*/ */
public void enableView() { public void enableView() {
synchronized(mSyncObject) { synchronized(mSyncObject) {
...@@ -124,7 +123,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements ...@@ -124,7 +123,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements
/** /**
* This method is provided for clients, so they can disable camera connection and stop * This method is provided for clients, so they can disable camera connection and stop
* the delivery of frames eventhough the surfaceview itself is not destroyed and still stays on the scren * the delivery of frames even though the surface view itself is not destroyed and still stays on the scren
*/ */
public void disableView() { public void disableView() {
synchronized(mSyncObject) { synchronized(mSyncObject) {
...@@ -143,9 +142,9 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements ...@@ -143,9 +142,9 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements
* size - the biggest size which less or equal the size set will be selected. * size - the biggest size which less or equal the size set will be selected.
* As an example - we set setMaxFrameSize(200,200) and we have 176x152 and 320x240 sizes. The * As an example - we set setMaxFrameSize(200,200) and we have 176x152 and 320x240 sizes. The
* preview frame will be selected with 176x152 size. * preview frame will be selected with 176x152 size.
* This method is usefull when need to restrict the size of preview frame for some reason (for example for video recording) * This method is useful when need to restrict the size of preview frame for some reason (for example for video recording)
* @param maxWidth - the maximum width allowed for camera frame. * @param maxWidth - the maximum width allowed for camera frame.
* @param maxHeight - the maxumum height allowed for camera frame * @param maxHeight - the maximum height allowed for camera frame
*/ */
public void setMaxFrameSize(int maxWidth, int maxHeight) { public void setMaxFrameSize(int maxWidth, int maxHeight) {
mMaxWidth = maxWidth; mMaxWidth = maxWidth;
...@@ -212,7 +211,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements ...@@ -212,7 +211,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements
private void onEnterStartedState() { private void onEnterStartedState() {
connectCamera(getWidth(), getHeight()); connectCamera(getWidth(), getHeight());
/* Now create cahe Bitmap */ /* Now create cache Bitmap */
mCacheBitmap = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888); mCacheBitmap = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888);
} }
...@@ -249,6 +248,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements ...@@ -249,6 +248,7 @@ public abstract class OpenCvCameraBridgeViewBase extends SurfaceView implements
if (mCacheBitmap != null) { if (mCacheBitmap != null) {
Canvas canvas = getHolder().lockCanvas(); Canvas canvas = getHolder().lockCanvas();
if (canvas != null) { if (canvas != null) {
canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
canvas.drawBitmap(mCacheBitmap, (canvas.getWidth() - mCacheBitmap.getWidth()) / 2, (canvas.getHeight() - mCacheBitmap.getHeight()) / 2, null); canvas.drawBitmap(mCacheBitmap, (canvas.getWidth() - mCacheBitmap.getWidth()) / 2, (canvas.getHeight() - mCacheBitmap.getHeight()) / 2, null);
getHolder().unlockCanvasAndPost(canvas); getHolder().unlockCanvasAndPost(canvas);
} }
......
package org.opencv.test.camerawriter; package org.opencv.test.camerawriter;
import org.opencv.android.Utils;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.Size; import org.opencv.core.Size;
import org.opencv.highgui.Highgui; import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture; import org.opencv.highgui.VideoCapture;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
...@@ -17,7 +14,7 @@ import android.util.Log; ...@@ -17,7 +14,7 @@ import android.util.Log;
* Due to the big amount of work done, by the base class this child is only responsible * Due to the big amount of work done, by the base class this child is only responsible
* for creating camera, destroying camera and delivering frames while camera is enabled * for creating camera, destroying camera and delivering frames while camera is enabled
*/ */
public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase { public class NativeCameraView extends CameraViewBase {
public static final String TAG = "OpenCvNativeCameraView"; public static final String TAG = "OpenCvNativeCameraView";
private boolean mStopThread; private boolean mStopThread;
...@@ -25,7 +22,7 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase { ...@@ -25,7 +22,7 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase {
private VideoCapture mCamera; private VideoCapture mCamera;
public OpenCvNativeCameraView(Context context, AttributeSet attrs) { public NativeCameraView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
...@@ -40,7 +37,7 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase { ...@@ -40,7 +37,7 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase {
initializeCamera(getWidth(), getHeight()); initializeCamera(getWidth(), getHeight());
/* now we can start update thread */ /* now we can start update thread */
mThread = new Thread(new CameraWorker(getWidth(), getHeight())); mThread = new Thread(new CameraWorker());
mThread.start(); mThread.start();
} }
...@@ -94,20 +91,7 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase { ...@@ -94,20 +91,7 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase {
} }
private class CameraWorker implements Runnable { private class CameraWorker implements Runnable {
private Mat mRgba = new Mat();
private int mWidth;
private int mHeight;
CameraWorker(int w, int h) {
mWidth = w;
mHeight = h;
}
public void run() { public void run() {
Mat modified;
do { do {
if (!mCamera.grab()) { if (!mCamera.grab()) {
Log.e(TAG, "Camera frame grab failed"); Log.e(TAG, "Camera frame grab failed");
...@@ -118,8 +102,9 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase { ...@@ -118,8 +102,9 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase {
deliverAndDrawFrame(mRgba); deliverAndDrawFrame(mRgba);
} while (!mStopThread); } while (!mStopThread);
} }
private Mat mRgba = new Mat();
} }
} }
...@@ -4,19 +4,17 @@ import org.opencv.android.BaseLoaderCallback; ...@@ -4,19 +4,17 @@ import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader; import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.test.camerawriter.OpenCvCameraBridgeViewBase.CvCameraViewListener; import org.opencv.test.camerawriter.CameraViewBase.CvCameraViewListener;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.util.Log; import android.util.Log;
public class CameraWriterActivity extends Activity implements CvCameraViewListener { public class PreviewActivity extends Activity implements CvCameraViewListener {
protected static final String TAG = "CameraWriterActivity"; protected static final String TAG = "CameraWriterActivity";
private CameraViewBase mCameraView;
private OpenCvCameraBridgeViewBase mCameraView;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override @Override
...@@ -40,7 +38,7 @@ public class CameraWriterActivity extends Activity implements CvCameraViewListen ...@@ -40,7 +38,7 @@ public class CameraWriterActivity extends Activity implements CvCameraViewListen
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_writer); setContentView(R.layout.activity_camera_writer);
mCameraView = (OpenCvCameraBridgeViewBase)findViewById(R.id.camera_surface_view); mCameraView = (CameraViewBase)findViewById(R.id.camera_surface_view);
mCameraView.setCvCameraViewListener(this); mCameraView.setCvCameraViewListener(this);
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mLoaderCallback); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mLoaderCallback);
......
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