OpenCV + Android - implement flashlight
Hello,
I have a problem with flashlight in my app. I do not know, How can I implement it to my Android app. On frame processing I use a CameraBridgeViewBase and I use a rear mobile camera.
How Can is implement simple camera flashlight ? :O Here is my code. Thanks EVERYONE !
public class MainActivity extends Activity implements CvCameraViewListener2 {
private CameraBridgeViewBase mOpenCvCameraView;
private JavaCameraView cameraView;
private Mat
mRgba,
imgGray,
imgCanny,
mResizedMat,
hierarchy;
private TextView
infoText,
text01,
text02,
text03;
private Button
button01,
button02,
button03;
private boolean
isMode01Active = false,
isMode02Active = false,
isMode03Active = false;
private SeekBar
seekBar01,
seekBar02,
seekBar03;
private int
value01 = 64,
value02 = 80,
value03 = 5;
Camera camera;
Camera.Parameters parameters;
List<MatOfPoint> contours;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
camera = Camera.open(CAMERA_ID_BACK);
parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
mOpenCvCameraView.enableView();
mOpenCvCameraView.enableFpsMeter();
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// - - - > SETTING LAYOUT OF ACTIVITY
setContentView(R.layout.activity_main);
setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE);
// < - - - END
// - - - > SET ORIENTATION OF SCREEN
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// < - - - END
// - - - > DECLARATION OF COMPONENTS
infoText = (TextView)findViewById(R.id.infoText);
text01 = (TextView)findViewById(R.id.text01);
text02 = (TextView)findViewById(R.id.text02);
text03 = (TextView)findViewById(R.id.text03);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.camera_view);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
button01 = (Button) findViewById(R.id.button01);
button02 = (Button) findViewById(R.id.button02);
button03 = (Button) findViewById(R.id.button03);
seekBar01 = (SeekBar) findViewById(R.id.seekBar01);
seekBar02 = (SeekBar) findViewById(R.id.seekBar02);
seekBar03 = (SeekBar) findViewById(R.id.seekBar03);
// < - - - END
isMode01Active = true;
infoText.setText("MODE1: ACTIVE");
button01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mOpenCvCameraView.enableFpsMeter();
infoText.setText("MODE1: ACTIVE");
setModelStatus("mode1");
}
});
button02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mOpenCvCameraView.enableFpsMeter();
infoText.setText("MODE2: ACTIVE");
setModelStatus("mode2");
}
});
button03.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mOpenCvCameraView.enableFpsMeter();
infoText.setText("MODE3: ACTIVE");
setModelStatus("mode3");
}
});
seekBar01.setMax(150);
seekBar02.setMax(150);
seekBar03.setMax(45);
seekBar01.setProgress(value01);
seekBar02.setProgress(value02);
seekBar03.setProgress(value03);
text01.setText(""+value01);
text02.setText(""+value02);
text03.setText(""+value03);
seekBar01.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
value01 = i;
text01.setText(""+value01);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
seekBar02.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
value02 = i;
text02.setText(""+value02);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
seekBar03.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
if(i % 2 != 0)
value03 = i;
text03.setText(""+value03);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
@Override
public void onPause() {
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onResume() {
super.onResume();
if (!OpenCVLoader.initDebug()) {
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback);
} else {
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onCameraViewStarted(int ...
there is no flashlight function in opencv.
Hmmm, thanks for answer. So, How can I implement it, is there any simply solution ?
Finally I have found this CV_CAP_PROP_ANDROID_FLASH_MODE. May it will be solved your problem
All specific android properties are here You can find some samples here
Thanks a lot for your time, but there is a no way how to implement it.