OpenCV Android-打开相机闪光灯 [英] OpenCV Android - Open camera flash

查看:177
本文介绍了OpenCV Android-打开相机闪光灯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序openCV打开后,我想在相机中打开Flash Led,但我无法访问相机:

I want to open the Flash Led in camera once app openCV opens but I have no access to camera :

mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_native_surface_view);

//此行不起作用.设置方法不存在

//This line not working. set method not there

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

推荐答案

如果您使用的是openCV v3.0.0,则可以创建新类(通过带有一些修改的示例tutorial3):

If you using openCV v3.0.0 you can create new class (from samples tutorial3 with some modyfications):

public class Tutorial3View extends JavaCameraView implements PictureCallback {
    private String mPictureFileName;

    public Tutorial3View(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public List<String> getEffectList() {
        return mCamera.getParameters().getSupportedFlashModes();
    }
    public boolean isEffectSupported() {
        return (mCamera.getParameters().getFlashMode() != null);
    }
    public String getEffect() {
        return mCamera.getParameters().getFlashMode();
    }
    public void setEffect(String effect) {
        mCamera.getParameters();
        Camera.Parameters params = mCamera.getParameters();
        params.setFlashMode(effect);
        mCamera.setParameters(params);
    }
    public List<Size> getResolutionList() {
        return mCamera.getParameters().getSupportedPreviewSizes();
    }
    public void setResolution(int w, int h) {
        disconnectCamera();
        mMaxHeight = h;
        mMaxWidth = w;
        connectCamera(getWidth(), getHeight());
    }

    public Size getResolution() {
        return mCamera.getParameters().getPreviewSize();
    }

    public void takePicture(final String fileName) {
        this.mPictureFileName = fileName;
        // Postview and jpeg are sent in the same buffers if the queue is not empty when performing a capture.
        // Clear up buffers to avoid mCamera.takePicture to be stuck because of a memory issue
        mCamera.setPreviewCallback(null);

        // PictureCallback is implemented by the current class
        mCamera.takePicture(null, null, this);
    }

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        // The camera preview was automatically stopped. Start it again.
        mCamera.startPreview();
        mCamera.setPreviewCallback(this);

        // Write the image in a file (in jpeg format)
        try {
            FileOutputStream fos = new FileOutputStream(mPictureFileName);
            fos.write(data);
            fos.close();
        } catch (java.io.IOException e) {
            Log.e("PictureDemo", "Exception in photoCallback", e);
        }

    }

    public void cameraRelease() {
        if(mCamera != null){
            mCamera.release();
        }
    }
}

,然后修改您的活动( Tutorial3View 代替 CameraBridgeViewBase ):

and then modify your activity (Tutorial3View instead CameraBridgeViewBase):

private Tutorial3View mOpenCVCameraView;   

mOpenCVCameraView = (Tutorial3View) findViewById(R.id.camera_surface_view);
mOpenCVCameraView.setCvCameraViewListener(this);
mOpenCVCameraView.setOnTouchListener(MainActivity.this);

//then you can set effect, for example torch:
mOpenCVCameraView.setEffect(Camera.Parameters.FLASH_MODE_TORCH);

这篇关于OpenCV Android-打开相机闪光灯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆