开发者

Auto-Focus: select focus point

The camera app that comes with the HTC Desire HD allows the user to touch the screen at the point they wish focus on; a bounding indicator comes up around the area and the auto-focus does its magic. Thus a captured image can have a far point in the top right and a near point in the bottom left, with the user able to select which of these is in focus before taking the picture.

I've been asked to create an app that allows the user to select the region of interest after a picture is taken, obviously it would be good for this region to be in focus before taking the picture as described above.

My app so far does the auto-focus thing on开发者_C百科 the centre of the image but I can find no reference to selecting the region to focus on in any documentation. Any ideas.


What you are requesting is manual focusing.

To do this with the help of Android SDK's alone is not possible as of today. You will need to set the focal length on the camera. But if you see the Camera SDK for android then you would have noticed there is an API to get the focal point but not to set it.

All the market apps that tell it is performing manual focus is not true, you can run your simple experiment to check this. Keep a far and near object in the camera preview and sequentially try to focus the far and near object, when the focus is on the far object then the near object should be blurred and when the focus is on the near object then the far object should be blurred.. which will not happen with the market apps. (I have tried a couple, if you find one which truly does this then do let me know :) )

But if you are doing an OEM app (Where you have the buildable BSP with you for the device) then yes it is possible to do this (As the app that you have mentioned does). And this is how they do it (Note - These steps might not be comprehensive but it will give you idea..)

  • When the user taps the preview surface the coordinates are obtained (The box area.)
  • This is then feed to a focusing algo which basically does
    • Takes the box area and preview data
    • Tries to find the edges within the preview data
    • Adjusts the focal length to get sharper edges (This is when you can see in the preview that some zoom is happening)
    • It figures out the best focal length which gives it sharp edges in the box and returns
  • Now the app says it is focused and voila the manual focus has been achieved.


Starting in API version 14 there appears to be a method for this:

public void setFocusAreas (List focusAreas)

Android Developer Documentation: setFocusAreas


Cyanogenmod just added this to their camera app - you may want to look at the changes they made there. Relevant patch: http://review.cyanogenmod.com/#change,6487

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜