Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Camera2 Basics API

I am reading the code about Android Camera2 APIs from here: https://github.com/googlesamples/android-Camera2Basic

And it is confusing in this lines: https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java#L570-L574

that the previewRequest builder only add surface, which is the TextureView to show, as target. But the following line actually add both as the targets. As I understand, this should not fire the "OnImageAvailable" Lisenter during preview, no? So why this add the imagereader's surface here?

I tried to removed this imagereader's surface here but got error when I really want to capture an image.....

SOOO CONFUSING!!!

like image 375
Coderzelf Avatar asked Aug 20 '15 01:08

Coderzelf


People also ask

What is Camera2 API Android?

Camera2 is the latest low-level Android camera package and replaces the deprecated Camera class. Camera2 provides in-depth controls for complex use cases, but requires you to manage device-specific configurations.

How do I get Camera2 API?

prop in the /system partition of your Android device, you can enable the Camera2 API functionality. First you'll need a rooted phone, and a method of editing your build. prop file. You can either use a root file explorer app (like ES Explorer) to navigate to the /system partition on your phone and open build.

What is Level 3 Camera2 API?

Full: These devices support all of the major capabilities of Camera API2 and must use Camera HAL 3.2 or higher and Android 5.0 or higher. Level_3: These devices support YUV reprocessing and RAW image capture, along with additional output stream configurations on top of full Camera2 API support.

How do I know if my Camera2 supports API?

Now the question arises – how can you check if your Android device supports Camera2 API? Well, all you need to do is download a simple app called 'Camera2 API probe' from the Google Play Store and run it. The app gives detailed info about both the rear and front camera sensors of your Android phone.


1 Answers

You need to declare all output Surfaces that image data might be sent to at the time you create a CameraCaptureSession. This is just the way the framework is designed.

Whenever you create a CaptureRequest, you add a (list of) target output Surface(s). This is where the image data from the captured frame will go- it may be a Surface associated with a TextureView for displaying, or with an ImageReader for saving, or with an Allocation for processing, etc. (A Surface is really just a buffer which can take the data output by the camera. The type of object that buffer is associated with determines how you can access/work with the data.)

You don't have to send the data from each frame to all registered Surfaces, but it has to be sent to a subset of them. You can't add a Surface as a target to a CaptureRequest if it wasn't registered with the CameraCaptureSession when it was created. Well, you can, but passing it to the session will cause a crash, so don't.

like image 74
rcsumner Avatar answered Oct 07 '22 03:10

rcsumner