Menu and style removed from sample.

This commit is contained in:
Alexander Smorkalov 2012-10-15 11:51:27 +04:00 committed by Andrey Kamaev
parent a32004f90c
commit 5f1339b319
5 changed files with 98 additions and 120 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@ -1,6 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>

View File

@ -1,5 +0,0 @@
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light" />
</resources>

View File

@ -9,34 +9,33 @@ import org.opencv.test.camerawriter.OpenCvCameraBridgeViewBase.CvCameraViewListe
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.util.Log; import android.util.Log;
import android.view.Menu;
public class CameraWriterActivity extends Activity implements CvCameraViewListener { public class CameraWriterActivity extends Activity implements CvCameraViewListener {
protected static final String TAG = "CameraWriterActivity"; protected static final String TAG = "CameraWriterActivity";
private OpenCvCameraBridgeViewBase mCameraView; private OpenCvCameraBridgeViewBase mCameraView;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override @Override
public void onManagerConnected(int status) { public void onManagerConnected(int status) {
switch (status) { switch (status) {
case LoaderCallbackInterface.SUCCESS: case LoaderCallbackInterface.SUCCESS:
Log.i(TAG, "OpenCV loaded successfully"); Log.i(TAG, "OpenCV loaded successfully");
// Create and set View // Create and set View
mCameraView.setMaxFrameSize(640, 480); mCameraView.setMaxFrameSize(640, 480);
mCameraView.enableView(); mCameraView.enableView();
break; break;
default: default:
super.onManagerConnected(status); super.onManagerConnected(status);
break; break;
} }
} }
}; };
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_writer); setContentView(R.layout.activity_camera_writer);
@ -47,26 +46,17 @@ public class CameraWriterActivity extends Activity implements CvCameraViewListen
} }
@Override public void onCameraViewStarted(int width, int height) {
public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.activity_camera_writer, menu);
return true;
} }
@Override public void onCameraViewStopped() {
public void onCameraViewStarted(int width, int height) { // TODO Auto-generated method stub
// TODO Auto-generated method stub
} }
@Override public Mat onCameraFrame(Mat inputFrame) {
public void onCameraViewStopped() { return inputFrame;
// TODO Auto-generated method stub }
}
@Override
public Mat onCameraFrame(Mat inputFrame) {
return inputFrame;
}
} }

View File

@ -19,52 +19,52 @@ import android.util.Log;
*/ */
public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase { public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase {
public static final String TAG = "OpenCvNativeCameraView"; public static final String TAG = "OpenCvNativeCameraView";
private boolean mStopThread; private boolean mStopThread;
private Thread mThread; private Thread mThread;
private VideoCapture mCamera; private VideoCapture mCamera;
public OpenCvNativeCameraView(Context context, AttributeSet attrs) { public OpenCvNativeCameraView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
}
@Override
protected void connectCamera(int width, int height) {
/* 1. We need to instantiate camera
* 2. We need to start thread which will be getting frames
*/
/* First step - initialize camera connection */
initializeCamera(getWidth(), getHeight());
/* now we can start update thread */
mThread = new Thread(new CameraWorker(getWidth(), getHeight()));
mThread.start();
}
@Override
protected void disconnectCamera() {
/* 1. We need to stop thread which updating the frames
* 2. Stop camera and release it
*/
try {
mStopThread = true;
mThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
mThread = null;
mStopThread = false;
} }
/* Now release camera */
releaseCamera();
@Override }
protected void connectCamera(int width, int height) {
/* 1. We need to instantiate camera private void initializeCamera(int width, int height) {
* 2. We need to start thread which will be getting frames
*/
/* First step - initialize camera connection */
initializeCamera(getWidth(), getHeight());
/* now we can start update thread */
mThread = new Thread(new CameraWorker(getWidth(), getHeight()));
mThread.start();
}
@Override
protected void disconnectCamera() {
/* 1. We need to stop thread which updating the frames
* 2. Stop camera and release it
*/
try {
mStopThread = true;
mThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
mThread = null;
mStopThread = false;
}
/* Now release camera */
releaseCamera();
}
private void initializeCamera(int width, int height) {
mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID); mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);
//TODO: improve error handling //TODO: improve error handling
@ -85,42 +85,41 @@ public class OpenCvNativeCameraView extends OpenCvCameraBridgeViewBase {
mFrameHeight = (int)frameHeight; mFrameHeight = (int)frameHeight;
Log.i(TAG, "Selected camera frame size = (" + mFrameWidth + ", " + mFrameHeight + ")"); Log.i(TAG, "Selected camera frame size = (" + mFrameWidth + ", " + mFrameHeight + ")");
}
private void releaseCamera() {
if (mCamera != null) {
mCamera.release();
}
}
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;
} }
private void releaseCamera() { public void run() {
if (mCamera != null) { Mat modified;
mCamera.release();
}
} do {
if (!mCamera.grab()) {
private class CameraWorker implements Runnable { Log.e(TAG, "Camera frame grab failed");
break;
private Mat mRgba = new Mat();
private int mWidth;
private int mHeight;
CameraWorker(int w, int h) {
mWidth = w;
mHeight = h;
}
@Override
public void run() {
Mat modified;
do {
if (!mCamera.grab()) {
Log.e(TAG, "Camera frame grab failed");
break;
}
mCamera.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
deliverAndDrawFrame(mRgba);
} while (!mStopThread);
} }
mCamera.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
deliverAndDrawFrame(mRgba);
} while (!mStopThread);
} }
}
} }