How to turn on the flash led continuously using FLASH_MODE_ON? - android

I searched on the web to turn on the flash using this mode but no solution work so far... I want to use this mode because some devices doesn't support the FLASH_MODE_TORCH, so I want to force the focus or another thing to turn on the flash continuously. I tried to restart the "autofocus" when the flash turns off automatically but it takes too much time (the period between two "flashing" is quite long).
So I ask you if you know some way to do it, thanks ! :)
Actually I use :
public static Camera Cam;
public static Parameters CamParams;
Cam = Camera.open();
CamParams = Cam.getParameters();
CamParams.setFlashMod(Parameters.FLASH_MODE_ON);
Cam.setParameters(CamParams);
Cam.startPreview();
Cam.autoFocus(new AutoFocusCallback()
{
public void onAutoFocus(boolean success, Camera camera)
{}
});

Related

How to disable/modify AutoFocus and AutoWhiteBalance on Android Camera using OpenCV

I'm using Android + Opencv(new to opencv) and I'm currently working with real time object detection (the object stays really close to the android device Camera) , and I noticed that the Android camera's autoFocus keeps modifying my frames (kind of 'zoom in' and 'zoom out' effect) which make it harder for me to keep tracking the object.
I need to turn the "AUTO FOCUS" off because in my case the more blurred image input I have, the better, and I also need to turn the AutoWhiteBalance off as well, or maybe set to a different value.
I would like to know how to do it through my OpenCV CameraBridgeViewBase so I could modify the camera's Focus/WhiteBalance settings.
I've trying to find a way to solve it, and I noticed that many people face the same problems.
Here, at Stack Overflow, would be a great place to find someone who have worked with that and found a good way to overcome these problems.
create your own subclass of javacameraview
public class MyJavaCameraView extends JavaCameraView {
where you can have access to mCamera;
add whatever camera access using method you are interested in
for example
// Setup the camera
public void setFlashMode(boolean flashLightON) {
Camera camera = mCamera;
if (camera != null) {
Camera.Parameters params = camera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
and use this new class as part of the main activity
//force java camera
mOpenCvCameraView = (MyJavaCameraView) findViewById(R.id.activity_surface_view);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
mOpenCvCameraView.enableView();

CWAC Camera - Video Recording Flash Torch (Android)

I'm using cwac-camera lib for my android camera application. the purpose for this camera is to record video. this video camera has features like a normal video camera like toggling Flash on/off before video recording. but the problem is, I'm having trouble implementing the FLASH_MODE_TORCH. I want is to turn on FLASH_MODE_TORCH during preview and if i start recording the flash is still present.
here's the code.
#Override
public Camera.Parameters adjustPreviewParameters(Camera.Parameters parameters){
if (vidFlash) {
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
} else {
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
}
return super.adjustPreviewParameters(parameters);
}
this was my first attempt, the FLASH_MODE_TORCH will occur when I start the application all I need is to toggle this on or off so that's why I used the code above
#Override
public Camera.Parameters adjustPreviewParameters(Camera.Parameters parameters) {
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
return super.adjustPreviewParameters(parameters);
}
Sorry, but there is no way with the CWAC-Camera API to accomplish this directly.

AutoExposureLock resetting after calling takePicture()

I'm having a problem with the exposure lock in the Android Camera.Parameters class. I'm able to lock the exposure before taking a picture, but upon calling camera.takePicture(shutterCallback, rawCallback, jpegCallback) the exposure starts auto-adjusting again.
Also, getAutoExposureLock() still returns true even though the preview and the final saved images show adjusted exposure.
The Android documentation says the exposure lock won't be changed by taking a picture: http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setAutoExposureLock(boolean)
What am I missing?
I managed to lock exposure compensation on my Galaxy S4
Camera.Parameters parameters = mCamera.getParameters();
parameters.setAutoExposureLock(true);
mCamera.setParameters(parameters);
mCamera.startPreview();
Then in each takePicture callback I basically reset the lock to true
Camera.Parameters parameters = mCamera.getParameters();
parameters.setAutoExposureLock(true);
mCamera.setParameters(parameters);
This manages to do something. All images captured are almost equally bright. Changing exposureCompensation has no effect, but when changing ISO the exposure time is automagically adjusted.
I'll dig some more into this and update this post accordingly.
I have the same problem. That's because camera.takePicture(shutterCallback, rawCallback, jpegCallback) stops the preview; you must call camera.startPreview(); to continue previewing.
I've come accross this myself, I'm assuming its an API error as it works the same for me as for you. Unless you have managed to fix it in the meantime? Let me know!
Resetting the lock to true in takePicture callback doesn't work well on my Samsung Galaxy Note 3. It makes situation a bit better, but still produces images with quite different brightness. Exif inside those jepgs confirm that exposure time varies from 1/120 sec to 1/400 sec.
I also noticed that some jpegs have similar exposure time (1/120 sec) but different brightness value saved in exif. So, my was guess that the image post-processor is the game breaker.
I've dumped all camera parameters via native_getParameters, found image correction parameters and set them all to 5. Those parameters are:
set("min-brightness", 5);
set("max-brightness", 5);
set("contrast", 5);
set("min-contrast", 5);
set("max-contrast", 5);
set("max-saturation", 5);
set("min-saturation", 5);
set("saturation", 5);
Now output is much better. Images almost equally bright. All of 500 test images have exposure time = 1/120 ± 1 (rarely 1/125) and brightness = 5 ± 0.1.
I had the same issue on S3. I ended putting those line at the begining of the callback:
public void onPictureTaken(byte[] data, Camera camera) {
//Relock the camera for S3 device
camera.startPreview();
UnLockCamera(camera);
LockCamera(camera);
// your code
With the two functions below
public void LockCamera(Camera camera){
//stop auto white balance and auto exposure lock
Camera.Parameters params = camera.getParameters();
if (params.isAutoExposureLockSupported()) {
params.setAutoExposureLock (true);
}
if (params.isAutoWhiteBalanceLockSupported()) {
params.setAutoWhiteBalanceLock(true);
}
camera.setParameters(params);
}
public void UnLockCamera(Camera camera){
//stop auto white balance and auto exposure lock
Camera.Parameters params = camera.getParameters();
if (params.isAutoExposureLockSupported()) {
params.setAutoExposureLock (false);
}
if (params.isAutoWhiteBalanceLockSupported()) {
params.setAutoWhiteBalanceLock(false);
}
camera.setParameters(params);
}

ColorEffect not visible on camera preview

I am trying to get a camera preview with a color effect applied to it, such as for example the NEGATIVE effect. There are no errors, and the preview is visible without problems, but independent of the ColorEffect I set - the camera preview remains unchanged. I tested if the effects I am trying to use are available to my phone by running params.getSupportedColorEffects() (also these effects also work in the built in photo app).
I have no idea what is wrong with the code - I am posting it below. Perhaps someone here has an idea what could make this work? Thanks in advance.
public class CustomCameraView extends SurfaceView{
Camera mCamera;
SurfaceHolder mHolder;
public CustomCameraView(Context context){
super(context);
mHolder = this.getHolder();
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mHolder.addCallback(mSurfaceHolderListener);
}
SurfaceHolder.Callback mSurfaceHolderListener = new SurfaceHolder.Callback() {
public void surfaceCreated(SurfaceHolder holder) {
mCamera=Camera.open();
try {
mCamera.setPreviewDisplay(mHolder);
}
catch (Exception e){ }
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height)
{
Camera.Parameters params = mCamera.getParameters();
params.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
mCamera.setParameters(params);
mCamera.startPreview();
}
public void surfaceDestroyed(SurfaceHolder arg0)
{
mCamera.stopPreview();
mCamera.release();
}
};
}
After some testing it turned out the problem could be related to the HTC Desire I was testing on (or maybe its OS version). The code works correctly on some other Samsung phones. I haven't figured out what could be the problem on the HTC.
UPDATE:
I have managed to get the effects working, but truly by accident, and I still don't understand why. But I will give the answer here - perhaps someone will find it useful, or maybe will be able to explain why it happens this way:
I added the following line to the surfaceChanged method because I was trying to decrease the size of the preview:
previewHolder.setFixedSize(width, height-1);
This had the result of making the selected effect visible.
When I changed this line to:
previewHolder.setFixedSize(width, height);
the effect was not visible any more once again. So odd.... it works for set height being anything less than the received height parameter.
I have been struggling with this as well. I found out that the HTC Desire its camera needs a strange order of executing the setParameters, setPreviewDisplay and startPreview for the color effect to work. The order is:
Camera.Parameters parameters = camera.getParameters();
//set the parameters
camera.setParameters(parameters);
camera.startPreview();
camera.setParameters(parameters);
camera.setPreviewDisplay(surfaceHolder);
Calling startPreview before setPreviewDisplay is documented in the Android SDK as a way of initializing the camera and the surfaceView in parallel.
Regarding your update about getting the effects to work by accident, the same happend to me! I assume for the same reason, some of my code got called twice in quick succesion (in my case due to a changing database object). This caused the method to (re)set the parameters and (re)start the preview to be called twice producing the desired result. After realising this and some more experimenting the above order seemed to work on both my HTC Desire and Acer Iconia A500 and I was quite happy with it.
However I have just received a comment for my application saying it produces corrupted images on the HTC Desire HD so I would recommend not using this order of camera initialization as a default but rather as a fix for the HTC Desire.
After setting new parameters to camera and starting preview invalidate() are calling on your SurfaceView . But it only Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future. So there is no guarantees that onDraw() will be called immediately. But onDraw() are always invoking after calling onMeasure() with size differs from current. So it can be a reason of this odd behavior.
Simple answers use following type :
Camera camera = null;
camera = Camera.open();
if (camera != null) {
try {
Camera.Parameters parameters = camera.getParameters();
// Set all kind of stuffs here..
parameters.setSceneMode(Camera.Parameters.FLASH_MODE_AUTO);
parameters.setColorEffect(Camera.Parameters.EFFECT_SEPIA); // whatever effect you want
camera.setParameters(parameters);
camera.setPreviewDisplay(surface_holder);
camera.startPreview();
} catch (IOException exception) {
camera.release();
camera = null;
}
}

Bad image Quality when using own Camera Activity

We are using an LG Optimus speed and are trying to obtain an image from the camera with our own activity. The Code we are using to do so is:
GetImage(new PictureCallback(){
#Override
public void onPictureTaken(byte[] data, Camera camera) {
camera.startPreview();
bmp = BitmapConversion.convertBmp(data));
}
});
...
public static void GetImage(final PictureCallback jpgCallback) {
GetCamera().autoFocus(new AutoFocusCallback(){
#Override
public void onAutoFocus(boolean success, Camera camera) {
if(success)
GetCamera().takePicture(null, null, jpgCallback);
else
GetImage(jpgCallback);
}
});
}
The images have a considerable worse quality than the images obatained with the native android camera app. Here are 2 example pictures, both taken with a resolution of 640x480 an magnified. As you can see the left picture taken with the native app looks "cleaner" than the right taken with our own application.
Any Ideas?
You don't know what the native app is doing in terms of configuring the camera before taking the image and post-processing after taking the image.
There are many settings available on the camera which are well documented and should be investigated.
You should also be aware that vastly different results exist on using the same method but with the slightest variation in light and focus.
Try looking into the autofocus settings and perhaps do something on autofocus callback.
When comparing the two methods make sure your camera is balanced on something rather than handheld and ensure that the distance and light levels are identical.

Categories

Resources