Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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:

public class test extends Activity implements CvCameraViewListener2 {

private static final String TAG = "test";
private NativeCamResView mOpenCvCameraView;
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) {        
    mOpenCvCameraView.setFocusMode(1);
    mOpenCvCameraView.setFlashMode(4);
    mGrayMat = new Mat(height, width, CvType.CV_8UC1);
}

public void onCameraViewStopped() { 
    mGrayMat.release();
}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    mGrayMat=inputFrame.gray();        
    return mGrayMat;
}

The view can look like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   xmlns:opencv="http://schemas.android.com/apk/res-auto" >

   <org.opencv.samples.test.NativeCamResView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:id="@+id/test_view"
      opencv:show_fps="true" />
</LinearLayout>

And the manifest:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.opencv.samples.test" android:versioncode="21" android:versionname="2.1">

<application
    android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

    <activity android:name="org.opencv.samples.test.test"
              android:label="@string/app_name"
              android:screenOrientation="landscape"
              android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

<supports-screens android:resizeable="true"
                  android:smallScreens="true"
                  android:normalScreens="true"
                  android:largeScreens="true"
                  android:anyDensity="true" />

<uses-sdk android:minSdkVersion="9"/>

<uses-permission android:name="android.permission.CAMERA"/>

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

I know that I could have just uploaded the project somewhere, but someone told me that offsite links are not welcome since they could be down in the future and people looking for help will become deseperate. Make sure that you dont forget to adjust all the folder structures in case you use something else :)

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:

public class test extends Activity implements CvCameraViewListener2 {

private static final String TAG = "test";
private NativeCamResView mOpenCvCameraView;
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) {        
    mOpenCvCameraView.setFocusMode(1);
    mOpenCvCameraView.setFlashMode(4);
    mGrayMat = new Mat(height, width, CvType.CV_8UC1);
}

public void onCameraViewStopped() { 
    mGrayMat.release();
}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    mGrayMat=inputFrame.gray();        
    return mGrayMat;
}

The view can look like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   xmlns:opencv="http://schemas.android.com/apk/res-auto" >

   <org.opencv.samples.test.NativeCamResView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:id="@+id/test_view"
      opencv:show_fps="true" />
</LinearLayout>

And the manifest:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.opencv.samples.test" android:versioncode="21" android:versionname="2.1">

xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.opencv.samples.test"
      android:versionCode="21"
      android:versionName="2.1">

<application
    android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

    <activity android:name="org.opencv.samples.test.test"
              android:label="@string/app_name"
              android:screenOrientation="landscape"
              android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

<supports-screens android:resizeable="true"
                  android:smallScreens="true"
                  android:normalScreens="true"
                  android:largeScreens="true"
                  android:anyDensity="true" />

<uses-sdk android:minSdkVersion="9"/>

<uses-permission android:name="android.permission.CAMERA"/>

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

I know that I could have just uploaded the project somewhere, but someone told me that offsite links are not welcome since they could be down in the future and people looking for help will become deseperate. Make sure that you dont forget to adjust all the folder structures in case you use something else :)

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) {        
    mOpenCvCameraView.setFocusMode(1);
    mOpenCvCameraView.setFlashMode(4);
{

    mGrayMat = new Mat(height, width, CvType.CV_8UC1);
CvType.CV_8UC1);         
}

public void onCameraViewStopped() { 
    mGrayMat.release();
}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
     mGrayMat=inputFrame.gray();        
    return mGrayMat;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    List<String> mFocusList = new LinkedList<String>();
    int idx =0;

    mFocusMenu = menu.addSubMenu("Focus");

    mFocusList.add("Auto");
    mFocusList.add("Continous Video");
    mFocusList.add("EDOF");
    mFocusList.add("Fixed");
    mFocusList.add("Infinity");
    mFocusList.add("Makro");

    mFocusListItems = new MenuItem[mFocusList.size()];

    ListIterator<String> FocusItr = mFocusList.listIterator();
    while(FocusItr.hasNext()){
        // add the element to the mDetectorMenu submenu
        String element = FocusItr.next();
        mFocusListItems[idx] = mFocusMenu.add(2,idx,Menu.NONE,element);
        idx++;
    }



    List<String> mFlashList = new LinkedList<String>();
    idx = 0;

    mFlashMenu = menu.addSubMenu("Flash");

    mFlashList.add("Auto");
    mFlashList.add("Off");
    mFlashList.add("On");
    mFlashList.add("Red-Eye");
    mFlashList.add("Torch");

    mFlashListItems = new MenuItem[mFlashList.size()];

    ListIterator<String> FlashItr = mFlashList.listIterator();
    while(FlashItr.hasNext()){
        // add the element to the mDetectorMenu submenu
        String element = FlashItr.next();
        mFlashListItems[idx] = mFlashMenu.add(3,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(1, idx, Menu.NONE,
                Integer.valueOf((int) element.width).toString() + "x" + Integer.valueOf((int) element.height).toString());
        idx++;
     }

    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    Log.e(TAG, "called onOptionsItemSelected; selected item: " + item);
   if (item.getGroupId() == 1)
    {
        int id = item.getItemId();
        Size resolution = mResolutionList.get(id);
        mOpenCvCameraView.setResolution(resolution);
        resolution = mOpenCvCameraView.getResolution();
        Log.e("test","test");
        String caption = Integer.valueOf((int) resolution.width).toString() + "x" + Integer.valueOf((int) resolution.height).toString();
        Toast.makeText(this, caption, Toast.LENGTH_SHORT).show();
    } 
    else if (item.getGroupId()==2){

       int focusType = item.getItemId();
       String caption = "Focus Mode: "+ (String)item.getTitle();
       Toast.makeText(this, caption, Toast.LENGTH_SHORT).show();

       mOpenCvCameraView.setFocusMode(focusType);
    }
    else if (item.getGroupId()==3){

       int flashType = item.getItemId();
       String caption = "Flash Mode: "+ (String)item.getTitle();
       Toast.makeText(this, caption, Toast.LENGTH_SHORT).show();

       mOpenCvCameraView.setFlashMode(flashType);
    }

    return true;
}   
}

The view can look like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   xmlns:opencv="http://schemas.android.com/apk/res-auto" >

   <org.opencv.samples.test.NativeCamResView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:id="@+id/test_view"
      opencv:show_fps="true" />
</LinearLayout>

And the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.opencv.samples.test"
      android:versionCode="21"
      android:versionName="2.1">

<application
    android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

    <activity android:name="org.opencv.samples.test.test"
              android:label="@string/app_name"
              android:screenOrientation="landscape"
              android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

<supports-screens android:resizeable="true"
                  android:smallScreens="true"
                  android:normalScreens="true"
                  android:largeScreens="true"
                  android:anyDensity="true" />

<uses-sdk android:minSdkVersion="9"/>

<uses-permission android:name="android.permission.CAMERA"/>

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

I know that I could have just uploaded the project somewhere, but someone told me that offsite links are not welcome since they could be down in the future and people looking for help will become deseperate. Make sure that you dont forget to adjust all the folder structures in case you use something else :)