mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
Tutorial-5 sample extended.
Application menu reorganized; Resolution control added.
This commit is contained in:
parent
c8b658fdb6
commit
77df8730ef
@ -13,12 +13,14 @@ import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.hardware.Camera.Size;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SubMenu;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
@ -29,7 +31,11 @@ public class Sample5CameraControl extends Activity implements CvCameraViewListen
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
private SampleJavaCameraView mOpenCvCameraView;
|
||||
private List<Size> mResolutionList;
|
||||
private MenuItem[] mEffectMenuItems;
|
||||
private SubMenu mColorEffectsMenu;
|
||||
private MenuItem[] mResolutionMenuItems;
|
||||
private SubMenu mResolutionMenu;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
@ -109,22 +115,50 @@ public class Sample5CameraControl extends Activity implements CvCameraViewListen
|
||||
return true;
|
||||
}
|
||||
|
||||
mColorEffectsMenu = menu.addSubMenu("Color Effect");
|
||||
mEffectMenuItems = new MenuItem[effects.size()];
|
||||
|
||||
int idx = 0;
|
||||
ListIterator<String> itr = effects.listIterator();
|
||||
while(itr.hasNext()) {
|
||||
String element = itr.next();
|
||||
mEffectMenuItems[idx] = menu.add(element);
|
||||
ListIterator<String> effectItr = effects.listIterator();
|
||||
while(effectItr.hasNext()) {
|
||||
String element = effectItr.next();
|
||||
mEffectMenuItems[idx] = mColorEffectsMenu.add(1, idx, Menu.NONE, element);
|
||||
idx++;
|
||||
}
|
||||
|
||||
mResolutionMenu = menu.addSubMenu("Resolution");
|
||||
mResolutionList = mOpenCvCameraView.getResolutionList();
|
||||
mResolutionMenuItems = new MenuItem[mResolutionList.size()];
|
||||
|
||||
ListIterator<Size> resolutionItr = mResolutionList.listIterator();
|
||||
idx = 0;
|
||||
while(resolutionItr.hasNext()) {
|
||||
Size element = resolutionItr.next();
|
||||
mResolutionMenuItems[idx] = mResolutionMenu.add(2, idx, Menu.NONE,
|
||||
Integer.valueOf(element.width).toString() + "x" + Integer.valueOf(element.height).toString());
|
||||
idx++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
|
||||
mOpenCvCameraView.setEffect((String) item.getTitle());
|
||||
Toast.makeText(this, mOpenCvCameraView.getEffect(), Toast.LENGTH_SHORT).show();
|
||||
if (item.getGroupId() == 1)
|
||||
{
|
||||
mOpenCvCameraView.setEffect((String) item.getTitle());
|
||||
Toast.makeText(this, mOpenCvCameraView.getEffect(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (item.getGroupId() == 2)
|
||||
{
|
||||
int id = item.getItemId();
|
||||
Size resolution = mResolutionList.get(id);
|
||||
mOpenCvCameraView.setResolution(resolution);
|
||||
resolution = mOpenCvCameraView.getResolution();
|
||||
String caption = Integer.valueOf(resolution.width).toString() + "x" + Integer.valueOf(resolution.height).toString();
|
||||
Toast.makeText(this, caption, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.hardware.Camera;
|
||||
import android.hardware.Camera.PictureCallback;
|
||||
import android.hardware.Camera.Size;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
@ -34,11 +35,26 @@ public class SampleJavaCameraView extends JavaCameraView {
|
||||
}
|
||||
|
||||
public void setEffect(String effect) {
|
||||
Camera.Parameters params = mCamera.getParameters();
|
||||
Camera.Parameters params = mCamera.getParameters();
|
||||
params.setColorEffect(effect);
|
||||
mCamera.setParameters(params);
|
||||
}
|
||||
|
||||
public List<Size> getResolutionList() {
|
||||
return mCamera.getParameters().getSupportedPreviewSizes();
|
||||
}
|
||||
|
||||
public void setResolution(Size resolution) {
|
||||
disconnectCamera();
|
||||
mMaxHeight = resolution.height;
|
||||
mMaxWidth = resolution.width;
|
||||
connectCamera(getWidth(), getHeight());
|
||||
}
|
||||
|
||||
public Size getResolution() {
|
||||
return mCamera.getParameters().getPreviewSize();
|
||||
}
|
||||
|
||||
public void takePicture(final String fileName) {
|
||||
Log.i(TAG, "Tacking picture");
|
||||
PictureCallback callback = new PictureCallback() {
|
||||
|
Loading…
Reference in New Issue
Block a user