Yes, it is possible to set the focus mode. I have a little test project that does this. Its important that you actually base the whole thing on a NativeCameraView, since that use the VideoCapture class which holds a set function for several camera features. The basic camera class is this:
package org.opencv.samples.test;
import java.util.List;
import org.opencv.android.NativeCameraView;
import org.opencv.core.Size;
import org.opencv.highgui.Highgui;
import android.content.Context;
import android.util.AttributeSet;
public class NativeCamResView extends NativeCameraView {
public NativeCamResView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public List<Size> getResolutionList() {
return mCamera.getSupportedPreviewSizes();
}
public void setResolution(Size resolution) {
disconnectCamera();
connectCamera((int)resolution.width, (int)resolution.height);
}
public void setFocusMode (int type){
switch (type){
case 0:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FOCUS_MODE, Highgui.CV_CAP_ANDROID_FOCUS_MODE_AUTO);
break;
case 1:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FOCUS_MODE, Highgui.CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_VIDEO);
break;
case 2:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FOCUS_MODE, Highgui.CV_CAP_ANDROID_FOCUS_MODE_EDOF);
break;
case 3:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FOCUS_MODE, Highgui.CV_CAP_ANDROID_FOCUS_MODE_FIXED);
break;
case 4:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FOCUS_MODE, Highgui.CV_CAP_ANDROID_FOCUS_MODE_INFINITY);
break;
case 5:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FOCUS_MODE, Highgui.CV_CAP_ANDROID_FOCUS_MODE_MACRO);
break;
}
}
public void setFlashMode (int type){
switch (type){
case 0:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE, Highgui.CV_CAP_ANDROID_FLASH_MODE_AUTO);
break;
case 1:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE, Highgui.CV_CAP_ANDROID_FLASH_MODE_OFF);
break;
case 2:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE, Highgui.CV_CAP_ANDROID_FLASH_MODE_ON);
break;
case 3:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE, Highgui.CV_CAP_ANDROID_FLASH_MODE_RED_EYE);
break;
case 4:
mCamera.set(Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE, Highgui.CV_CAP_ANDROID_FLASH_MODE_TORCH);
break;
}
}
public Size getResolution() {
Size s = new Size(mCamera.get(Highgui.CV_CAP_PROP_FRAME_WIDTH),mCamera.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));
return s;
}
}
Then youractivity should could look like this:
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.WindowManager;
import android.widget.Toast;
public class test extends Activity implements CvCameraViewListener2 {
private static final String TAG = "test";
private NativeCamResView mOpenCvCameraView;
private List<Size> mResolutionList;
private MenuItem[] mResolutionMenuItems;
private MenuItem[] mFocusListItems;
private MenuItem[] mFlashListItems;
private SubMenu mResolutionMenu;
private SubMenu mFocusMenu;
private SubMenu mFlashMenu;
private Mat mGrayMat;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public test() {
Log.i(TAG, "Instantiated new " + this.getClass());
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.native_cam_res_view);
mOpenCvCameraView = (NativeCamResView) findViewById(R.id.test_view);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_5, this, mLoaderCallback);
}
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
public void onCameraViewStarted(int width, int height) {
mGrayMat = new Mat(height, width, CvType.CV_8UC1 ...
(more)