Android Studio CameraX Preview - android

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.

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
}

Used the same code as given in Android's Jetpack's CameraX documentation, but PreviewView is not found

I'm trying to integrate camerax into my app. I followed the official documentation given here. In the example code the second line mentions:
val viewFinder: PreviewView = findViewById(R.id.previewView)
But PreviewView is not found. I went to the official class definition documentation here and found that the hierarchy is androidx.camera.view.PreviewView. So I tried adding it explicitly
import androidx.camera.view.PreviewView
But androidx.camera.view is not found.
PreviewView was added to androidx.camera:camera-view starting with version 1.0.0-alpha04. So, make sure
that your CameraX dependencies in Gradle are at 1.0.0-alpha04 and that you have androidx.camera:camera-view as one of those dependencies.

Android CameraX stuck with two use cases

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.

Android PrintHelper Orientation

I am using PrintHelper API provided by android 19 and above for wireless printing, using following code which is supposed to set preview to landscape according to code but actually its showing preview in portrait mode. Any help would be appreciated
Please refer Android code used for printing below
PrintHelper printHelper = new PrintHelper(context);
printHelper.setOrientation(PrintHelper.ORIENTATION_LANDSCAPE);
printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);
printHelper.setColorMode(PrintHelper.COLOR_MODE_MONOCHROME);
printHelper.printBitmap("testPrint", bitmap);

Categories

Resources