gpt4 book ai didi

android - OpenCV Android-打开相机闪光灯

转载 作者:行者123 更新时间:2023-12-02 16:44:39 36 4
gpt4 key购买 nike

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

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

//此行不起作用。设置方法不存在
mOpenCvCameraView.set(Highgui.CV_CAP_PROP_ANDROID_FLASH_MODE,Highgui.CV_CAP_ANDROID_FLASH_MODE_ON);

最佳答案

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

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();
}
}
}

然后修改您的 Activity (用 Tutorial3View 代替 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);

关于android - OpenCV Android-打开相机闪光灯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27382720/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com