Android CameraX stuck with two use cases - android

I'm novice in Android development (more Python and ML engineer) but wanted to try this example from TensorFlow: TF Lite Transfer Learning.
I succesfully run it on Android Studio but spotted that I cannot do anything with the app as it works extraordinary slow. I was digging through the code to find a root cause a found out this.
In function CameraFragment::startCamera() a preview context is created
PreviewConfig config = new PreviewConfig.Builder()
.setLensFacing(LENS_FACING)
.setTargetAspectRatio(screenAspectRatio)
.setTargetRotation(viewFinder.getDisplay().getRotation())
.build();
Preview preview = new Preview(config);
preview.setOnPreviewOutputUpdateListener(previewOutput -> {
ViewGroup parent = (ViewGroup) viewFinder.getParent();
parent.removeView(viewFinder);
parent.addView(viewFinder, 0);
As well as other use case that we can keep empty:
final ImageAnalysisConfig imageAnalysisConfig =
new ImageAnalysisConfig.Builder()
.setLensFacing(LENS_FACING)
.setTargetResolution(new Size(224, 224))
.setCallbackHandler(new Handler(inferenceThread.getLooper()))
.setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
.build();
final ImageAnalysis imageAnalysis2 = new ImageAnalysis(imageAnalysisConfig);
imageAnalysis2.setAnalyzer((image, rotationDegrees) -> { });
New we have a line to bring them to life:
CameraX.bindToLifecycle(this, preview, imageAnalysis2);
And here is where the problem starts. If we keep them like that the application is unusable. But if we keep only one (either one) we can use the app to the point that all novigation works normally. Do you know what is causing this behaviour?

This build.gradle uses a rather old version; migrate to version 1.0.0-beta01.

Related

CameraX - VideoCaptureConfig.Builder is showing an error

I have the following line in my CameraXFragment and Android Studio is showing me an error:
videoCapture = VideoCaptureConfig.Builder() // <--- Builder is in red
.setTargetRotation(binding.previewView.display.rotation)
.setCameraSelector(cameraSelector)
.setTargetAspectRatio(screenAspectRatio)
.build()
Android Studio does not recognize Builder after updating the camerax version from '1.0.0-beta04' to '1.0.0-beta12'.
Does somebody know how to create a VideoCaptureConfig in the latest version ?
Use VideoCapture.Builder():
videoCapture = VideoCapture.Builder()
.setTargetRotation(binding.previewView.display.rotation)
.setCameraSelector(cameraSelector)
.setTargetAspectRatio(screenAspectRatio)
.build()
You could use this in order to utilize the library's restricted api. That doesn't mean it's gonna work, though.
#SuppressLint("RestrictedApi")

Sceneform - How to make the camera view too autofocus

So, the default camera view in sceneform is in fixed focus settings. But its blur and doesn't feels good. I want to get the camera to show everything clearly (Autofocus mode).
I tried changing the session config. But it is not really working.
override fun getSessionConfiguration(session: Session?): Config {
val config = Config(session)
config.focusMode = Config.FocusMode.AUTO
return config
}

Android Studio CameraX Preview

I am following a tutorial on how to build a cameraX custom camera and i'm stuck.
In the tutorial he uses this:
PreviewConfig previewConfig = new PreviewConfig.Builder().setTargetAspectRatioCustom(aspectRatio).build();
Preview preview = new Preview(previewConfig)
preview.setOnPreviewOutputUpdateListener() {
...
}
I found out that this method changed and now you don't need PreviewConfig so you can just do it like this:
Preview preview = new Preview.Builder().setTargetAspectRatioCustom(aspectRatio).build();
But the setOnPreviewOutputUpdateListener() method does not exist anymore for Preview (Cannot resolve symbol 'setOnPreviewOutputUpdateListener'). How can i handle this?
Thank you very much.

How to optimize viewrenderable in arcore?

I created an application that use viewrenderable to show Gif in ARCore, but after 90-100 or more the app will crash. How to reuse viewrenderable in ARCore?
ViewRenderable.builder()
.setView(fragment.context, gifObject)
.build()
.thenAccept { viewRenderable ->
viewRenderable.view
... //create anchor and node
}
Please help me, I'm using ARCore Android SDK
Maybe you create too many anchors,It's very resource intensive,you could create an anchor,an anchorNode as global,then every frame,you detach last anchor,then create a new anchor,and use anchorNode.setAnchor(anchor). have a try,maybe it works.
Incase you haven't found a solution yet, I recommend debugging and find out any rendering related issues using Graphics API Debugger (GAPID). It comes with an interface that lets you view and inspect frame by frame

AndroidX ExifInterface can read camera make/model but not lens make/model

I'm building an app which reads EXIF data from images and overlays that data on the image so you can share your camera settings with a nice graphic rather than manually typing them out (EG: "F/1.4 at 1/200 ISO400")
I'm using AndroidX ExifInterface 1.1.0-beta01 and the blow code works to get every piece of data except the LensMake and LensModel are always null.
I've tried reverting to ExifInterface 1.0.0 and that made no difference, it still behaves identically.
I note that the documentation for ExifInterface refers to LensMake and LensModel as returning an "ASCII String" which Camera Make and Camera Model just return a "String" so i've tried different variations of getAttribute without success.
These exact files work fine on the iOS version of the app I've previously built and i've tried files from multiple different cameras (Fuji X-T3, Canon 5D III)
var stream: InputStream? = null
try {
stream = contentResolver.openInputStream(uri)
val exifInterface = ExifInterface(stream!!)
FS = exifInterface.getAttribute(ExifInterface.TAG_F_NUMBER)!!
SS = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME)!!
ISO = exifInterface.getAttribute(ExifInterface.TAG_PHOTOGRAPHIC_SENSITIVITY)!!
val LensMake = exifInterface.getAttribute(ExifInterface.TAG_LENS_MAKE) //THIS APPEARS TO BE ALWAYS NULL :(
val LensModel = exifInterface.getAttribute(ExifInterface.TAG_LENS_MODEL) //THIS APPEARS TO BE ALWAYS NULL :(
val CameraMake = exifInterface.getAttribute(ExifInterface.TAG_MAKE)
val CameraModel = exifInterface.getAttribute(ExifInterface.TAG_MODEL)
}
I'd like to be able to read the lens information, I know it's in the file but this library doesn't seem to want to expose it.
There is an open bug filed on the issue tracker, which states, that:
Although the constants are available for LensMake and LensModel, the getter does not return the actual values from the file. It seems like proper support is missing. I think the reason is that ExifTag[] IFD_EXIF_TAGS does not contain an array item for lens make and model. Adding the following lines at the right place of the aforementioned array, seems to fix things:
new ExifTag(TAG_LENS_MAKE, 42035, IFD_FORMAT_STRING),
new ExifTag(TAG_LENS_MODEL, 42036, IFD_FORMAT_STRING),
Not sure how reliable this is, but it is at least a solution approach.

Categories

Resources