Video camera auto focus - android

I developed a small video camera application. It all works fine except focus.
I understand I need to call camera.autofocus, but I don't really know where is the right place to put the call it.
Anyone ever succeeded in autofocusing a video camera on android?
Thank
Eli

It's probably a matter of preference based on how you think users will use your app.
I think a common convention is to do an auto-focus when the user touches the scene in the preview. Most OEM camera apps seem to do this.
Doing auto-focus after zooming is also a common thing.
Finally, you might want to have a look at the zxing project (bar code scanner app) which has a nifty continuous auto focus approach that might be of use, though since youre capturing video, it might not be ideal as the focus transitions might be too noticeable.
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/camera/AutoFocusCallback.java?r=1698

Related

How to keep focus of android camera2?

I am trying to take 6 photos by rotating my phone for each 60 degree using camera2 api.
First time I need to take first photo using autofocus when focus area is the center of my screen.
And I have to keep this focus for the next 5 photos, it should not try to get new focus.
I have been trying to make it for a week. But the results are not as expected. I tried many ways and I faced few problems: images are blurry, the camera tries to find new focus for each photos, and so on.
It would be great if someone shows me direction :)
i don't know exact answer of your question..but i will try to tell you something's about your Question.
How to use flash without stopping camera feed?
above is link of my Answer.check that
i think ,in your App you have to put some condition for that.
Set your Flash mode regarding Rotation or whatever as you want..Like whenever Your Rotation is this, then Your Flash will this.
Like [On,Auto,Flash].
Hope this will help you...(:

Record entire screen, including front camera preview

I wrote a small game. It has a front facing cam preview implemented. I want to be able to record the entire screen to a mp4. How would I do that? Anyone know a nice tutorial for recording the entire screen to mp4 (in code, so not just screenshots.. I want to enable the user to make a recording, while playing the game).
Indeed, as #Michael stated, directly accessing the screenshot and framebuffer mechanisms is not possible. That doesn't mean you're completely out of luck, though, if you want to record gaming sessions. It's just more work.
If you generate a perfect record of the various actions in your game, save that record. You can then build a service (web service, local, whatever) that accepts the record as an input. In effect, it would replay the game. You'd then reconstruct the game in such a manner that you could generate a video.
You could also replay in the Android emulator and create a video from that. Not as easily deployable, but it depends on what you want to do with it.
Apps aren't allowed to grab the screen contents (see this discussion).
[L]etting applications grab the screen's content liberally is a serious security risk, which is why the platform prevents it (taking a snapshot requires either direct physical manipulation from the user, or using a debugging tool).
And as #CommonsWare mentioned in his comment you can't use the getDrawingCache method either to grab a Bitmap of the View if you're using a SurfaceView or one of its children (e.g. VideoView). More details about that here.

Taking a picture in Background Service

I am searching for a method to take a picture with the Camera of my phone without showing the User a Preview.
I know, that this is designed not to work, because its a security issue, but I am developing a "Get My Phone Back" app, that should be able to identify the thief, that has stolen my phone (in future^^).
So it has to be stealth.
My phone is rooted, so I think there should be a way to do this.
Any suggestions?
Just an idea:
You could start the camera just as described inside the docs, but set the underlying SurfaceView visibility to (View.GONE or View.INVISIBLE). After that, you can try to take pictures...
Not really shure, if this will work, but I think its worth a try

Camera on Android Example

I want to write an activity that:
Shows the camera preview (viewfinder), and has a "capture" button.
When the "capture" button is pressed, takes a picture and returns it to the calling activity (setResult() & finish()).
Are there any complete examples out there that works on every device? A link to a simple open source application that takes pictures would be the ideal answer.
My research so far:
This is a common scenario, and there are many questions and tutorials on this.
There are two main approaches:
Use the android.provider.MediaStore.ACTION_IMAGE_CAPTURE event. See this question
Use the Camera API directly. See this example or this question (with lots of references).
Approach 1 would have been perfect, but the issue is that the intent is implemented differently on each device. On some devices it works well. However, on some devices you can take a picture but it is never returned to your app. On some devices nothing happens when you launch the intent. Typically it also saves the picture to the SD card, and requires the SD card to be present. The user interaction is also different on every device.
With approach 2 the issues is stability. I tried some examples, but I've managed to stop the camera from working (until a restart) on some devices and completely freeze another device. On another device the capture worked, but the preview stayed black.
I would have used ZXing as an example application (I work with it a lot), but it only uses the preview (viewfinder), and doesn't take any pictures. I also found that on some devices, ZXing did not automatically adjust the white balance when the lighting conditions changed, while the native camera app did it properly (not sure if this can be fixed).
Update:
For a while I used the camera API directly. This gives more control (custom UI, etc), but I would not recommend it to anyone. I would work on 90% of devices, but every now and again a new device would be released, with a different problem.
Some of the problems I've encountered:
Handling autofocus
Handling flash
Supporting devices with a front camera, back camera or both
Each device has a different combination of screen resolution, preview resolutions (doesn't always match the screen resolution) and picture resolutions.
So in general, I'd not recommend going this route at all, unless there is no other way. After two years I dumped by custom code and switched back to the Intent-based approach. Since then I've had much less trouble. The issues I've had with the Intent-based approach in the past was probably just my own incompetence.
If you really need to go this route, I've heard it's much easier if you only support devices with Android 4.0+.
With approach 2 the issues is stability. I tried some examples, but I've managed to stop the camera from working (until a restart) on some devices and completely freeze another device. On another device the capture worked, but the preview stayed black.
Either there is a bug in the examples or there is a compatibility issue with the devices.
The example that CommonsWare gave works well. The example works when using it as-is, but here are the issues I ran into when modifying it for my use case:
Never take a second picture before the first picture has completed, in other words PictureCallback.onPictureTaken() has been called. The CommonsWare example uses the inPreview flag for this purpose.
Make sure that your SurfaceView is full-screen. If you want a smaller preview you might need to change the preview size selection logic, otherwise the preview might not fit into the SurfaceView on some devices. Some devices only support a full-screen preview size, so keeping it full-screen is the simplest solution.
To add more components to the preview screen, FrameLayout works well in my experience. I started by using a LinearLayout to add text above the preview, but that broke rule #2. When using a FrameLayout to add components on top of the preview, you don't have any issues with the preview resolution.
I also posted a minor issue relating to Camera.open() on GitHub.
"the recommended way to access the camera is to open Camera on a separate thread". Otherwise, Camera.open() can take a while and might bog down the UI thread.
"Callbacks will be invoked on the event thread open(int) was called from". That's why to achieve best performance with camera preview callbacks (e.g. to encode them in a low-latency video for live communication), I recommend to open camera in a new HandlerThread, as shown here.

Android Camera continuous focus

I need to implement an app on android which uses the camera and it needs to keep the focus continuously on objects. Whenever user changes the camera position, it should autofocus itself for that position (very much like Google Goggles).
Right now I am using the following code:
camera.requestautofocus(autofocuscallbak);
This works well but it's not continuous...
You can use the option: http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FOCUS_MODE_CONTINUOUS_VIDEO
Or you can take a look a the Zxing library http://code.google.com/p/zxing/ (barcode scanner app) which has a loop of events build which comes close to continuous autofocus.
It is heavier on your device than you would want to though.
Probably a nicer solution would be to write a function yourself using the accelerometer, and triggering the autofocus when the phone has moved (too much) in a certain direction.

Categories

Resources