Using LED Flash Camera with OpenCV on Android

I have an application using OpenCV for Android and was wondering if the camera LED can be turned on.

My camera is currently set up using the following code:

camera = new VideoCapture(Highgui.CV_CAP_ANDROID);

All the examples I've seen to enable LED flash require Camera.Parameters

that I don't have access to this camera setup with.

Is there an easy way to turn on the LED without switching to using the base class Camera

for my video stream, as this tends to be much slower.

Thanks for any help in advance.

+3


source to share


4 answers


In OpenCV for Android 2.4, you can do this,

mCamera.set(
  Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE,
  Highgui.CV_CAP_ANDROID_FLASH_MODE_ON
);

      



Other options: CV_CAP_ANDROID_FLASH_MODE_AUTO

, CV_CAP_ANDROID_FLASH_MODE_OFF

, CV_CAP_ANDROID_FLASH_MODE_TORCH

and CV_CAP_ANDROID_FLASH_MODE_REDEYE

.

However, this closes the app automatically on my tablet (Asus TF101). Hope it works for others.

+4


source


You can use JavaCameraView extensions

Public class Tutorial2View extends JavaCameraView {

private static final String TAG = "Sample::Tutorial2View";

private Context myreference;
private static boolean isFlashLightON = false;
public Tutorial2View(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.myreference = context;
}

public List<String> getEffectList() {
    return mCamera.getParameters().getSupportedColorEffects();
}

public boolean isEffectSupported() {
    return (mCamera.getParameters().getColorEffect() != null);
}

public String getEffect() {
    return mCamera.getParameters().getColorEffect();
}

public void setEffect(String effect) {
    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();
}

// Setup the camera
public void setupCameraFlashLight() {
    Camera  camera = mCamera;
    if (camera != null) {
        Parameters params = camera.getParameters();

        if (params != null) {
            if (isFlashLightON) {
                isFlashLightON = false;
                params.setFlashMode(Parameters.FLASH_MODE_OFF);
                camera.setParameters(params);
                camera.startPreview();
            } else {
                isFlashLightON = true;
                params.setFlashMode(Parameters.FLASH_MODE_TORCH);
                camera.setParameters(params);
                camera.startPreview();

            }
        }
    }

}

      



}

Call setupCameraFlashLight (); for ON. OFF. Light-emitting diode

+4


source


There seems to be no easy way to do this. The only option is to use the default Android camera class and make a small performance hit.

+2


source


If you are using JavaCameraView, you can simply add two methods at the end to your JavaCameraView.java class:

public void turnOffTheFlash() {
    Camera.Parameters params = mCamera.getParameters();
    params.setFlashMode(params.FLASH_MODE_OFF);
    mCamera.setParameters(params);
}

public void turnOnTheFlash() {
    Camera.Parameters params = mCamera.getParameters();
    params.setFlashMode(params.FLASH_MODE_TORCH);
    mCamera.setParameters(params);
}

      

You can run them in your activity like this:

private JavaCameraView javaCameraView;

javaCameraView.turnOnTheFlash();

javaCameraView.turnOffTheFlash();

      

Mayby you should be using FLASH_MODE_ON and not FLASH_MODE_TORCH.

It works for me on OpenCV 2.4.9.

+1


source







All Articles