gpt4 book ai didi

android - 带有OpenCV3.0.0 Android的Camera Flash无法正常工作

转载 作者:行者123 更新时间:2023-12-02 17:46:21 28 4
gpt4 key购买 nike

我正在使用opencv视频流编写代码,我想在第一次打开相机时打开相机闪光灯。我实现了一个从JavaCameraView扩展的新类,但是当我计算以下行时,应用程序崩溃了:

mOpencvCameraView.setEffect(Camera.Parameters.FLASH_MODE_ON);

该类如下:
我的代码
public class CameraCustomize extends JavaCameraView  implements Camera.PictureCallback {
private String mPictureFileName;

public CameraCustomize(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();// here where i get the Error
Camera.Parameters params = mCamera.getParameters();
params.setFlashMode(effect);
mCamera.setParameters(params);

}
public List<Camera.Size> getResolutionList() {
return mCamera.getParameters().getSupportedPreviewSizes();
}
public void setResolution(int w, int h) {
disconnectCamera();
mMaxHeight = h;
mMaxWidth = w;
connectCamera(getWidth(), getHeight());
}

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

请任何人可以帮助我,或建议另一种方式启动相机闪光灯。
谢谢您的进阶。

最佳答案

我通过从此链接Using Camera LED Flash with OpenCV on Android应用此类来找到解决方案

它只是完美地工作:)

这是我实现的类:

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

private Context my reference;

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

}
}
}

}

关于android - 带有OpenCV3.0.0 Android的Camera Flash无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34634425/

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