The perfect realization of real-time autofocus for Android camera

Source: Internet
Author: User

Https://zhidao.baidu.com/question/873328177698804372.html

The perfect implementation of real-time autofocus for Android camera http://blog.csdn.net/huweigoodboy/article/details/51378751

How to achieve the AF http://www.open-open.com/lib/view/open1406536473812.html of Android phone camera


Android front camera can be autofocus method:
First: The most common implementation---the use of keys or a one-time auto-focus before taking photos declare the variable private in the activity
Autofocuscallback myautofocuscallback = null;
Auto Focus Variable Callback

Myautofocuscallback = new Autofocuscallback ()
{

public void Onautofocus (Boolean success, Camera
Camera) {

TODO auto-generated Method Stub

if (success)//success indicates a successful focus

{

LOG.I (Tag, "Myautofocuscallback:
Success ... ");

Mycamera.setoneshotpreviewcallback (NULL);

}

Else

{

No focus succeeded

LOG.I (Tag, "Myautofocuscallback: Failed ...");

}

}

};

After Camera.startpreview (), take a picture of camera.takepicture ()
Before calling Mycamera.autofocus (Myautofocuscallback).

Second:
Use TimerTask to set a timer to loop, calling Mycamera.autofocus (Myautofocuscallback) at a certain time. The result is that the camera has been focusing on itself, repeating clarity-blurring----clear---blurred process.

Third: Open a thread for auto-focus via handler and thread. The essence is the same as the second. Later I will write a demo to send up.

Fourth:
The autofocus is triggered by a monitoring sensor. An angle sensor or accelerometer is commonly used, triggering when the value of the listener exceeds a certain threshold. This is also a common idea used by foreign programmers.

Five: Set the focus mode to Myparam.setfocusmode (Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
Continuous auto focus mode intended for video
Recording. The camera continuously tries to focus. The best
Choice for video recording because the focus changes smoothly.
Applications still can call Takepicture (Camera.shuttercallback,
Camera.picturecallback,
Camera.picturecallback) in this mode
But the subject is not being in focus. Auto Focus starts when the
parameter is set.
Since API level, applications can
Call AutoFocus (Autofocuscallback) in
This mode. The focus callback'll immediately return with a
Boolean that indicates whether the focus was sharp or not. The focus
Position is locked under AutoFocus call. If applications want to
Resume the continuous focus, cancelautofocus must be called.
Restarting the preview would not resume the continuous autofocus. To
Stop continuous focus, applications should change the focus mode to
Other modes.
This means that the focus is called when the video is recorded, which may not be successful in the case of a photograph.
After setting Myparam.set ("Rotation",
90);
The setting of this sentence does not work. The photos and previews taken are 90 degrees in the wrong direction. After you need to get bitmap, use the matrix to rotate yourself.
Example of rotation: Mbitmap = bitmapfactory.decodebytearray (data, 0,
Data.length);//data is a byte data that resolves it to a bitmap mycamera.stoppreview (); ispreview = false;
After setting Focus_mode_continuous_video), Myparam.set ("Rotation",
90) failure. The picture can't be rotated, so it's going to spin down here.
Matrix matrix = new Matrix ();
Matrix.postrotate ((float) 90.0);
Bitmap Rotabitmap = Bitmap.createbitmap (Mbitmap,
0, 0, mbitmap.getwidth (), Mbitmap.getheight (), Matrix,
FALSE);
Once set to Focus_mode_continuous_video, calling Camera.autofocus () will focus on failure.

Sixth: It is through analysis Onpreviewframe get preview frame video, analyze brightness change, to touch Camera.autofocus (). If the brightness changes, there must be a relative movement between the camera and the object being photographed, which needs to trigger the autofocus (). Some of the phone's own
This is probably the way the camera software is used.

The perfect realization of real-time autofocus for Android camera

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.