Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

❓ Preview stretched in my app but not in the example on same device #2311

Closed
3 of 4 tasks
Flocurry opened this issue Dec 21, 2023 · 19 comments · Fixed by #2519
Closed
3 of 4 tasks

❓ Preview stretched in my app but not in the example on same device #2311

Flocurry opened this issue Dec 21, 2023 · 19 comments · Fixed by #2519
Labels
💭 question Further information is requested

Comments

@Flocurry
Copy link

Question

I don't understand why my camera preview is stretched in my Android app but not with your example on my tablet device...

What I tried

I use the same CameraPage.tsx file in my app like in your example.
The format below props given to the camera component is the same in my app than in your example

{
"format":{
"autoFocusSystem":"contrast-detection",
"fieldOfView":85.2381275912114,
"maxFps":30,
"maxISO":1600,
"maxZoom":4,
"minFps":1,
"minISO":100,
"photoHeight":1600,
"photoWidth":2560,
"pixelFormats":[
"yuv",
"native"
],
"supportsDepthCapture":false,
"supportsPhotoHdr":false,
"supportsVideoHdr":false,
"videoHeight":960,
"videoStabilizationModes":[
"off",
"off"
],
"videoWidth":1440
}
}

VisionCamera Version

3.6.17

Additional information

@Flocurry Flocurry added the 💭 question Further information is requested label Dec 21, 2023
@bglgwyng
Copy link
Contributor

#2142 Maybe the same issue

@Flocurry
Copy link
Author

I found why the preview is stretched on my app.
This is because my app is locked in landscape
I have android:screenOrientation="landscape" in the AndroidManifest.xml file

So How can I solve my problem with the landscape orientation ?

@mrousavy mrousavy closed this as completed Jan 2, 2024
@mrousavy
Copy link
Owner

Hey! Does this fix your issue maybe? #2377 (still testing)

@mrousavy
Copy link
Owner

Hey!

After 8 hours of debugging, I finally found the culprit! I fixed the preview stretching issue in this PR: #2377

If you appreciate my dedication and free support, please consider 💖 sponsoring me on GitHub 💖 so I can keep providing fixes and building out new features for my open-source libraries in my free time.

@Flocurry
Copy link
Author

Flocurry commented Jan 12, 2024

Hello, I've tested the 3.7.1 and i've still the issue.

In the version 3.7.0, I've made a patch.

I've added the below line in PreviewView.kt file

private val aspectRatio: Float get() = size.width.toFloat() / size.height.toFloat()

and replace the method onMeasure by below lines

@SuppressLint("DrawAllocation")
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val viewWidth = MeasureSpec.getSize(widthMeasureSpec)
val viewHeight = MeasureSpec.getSize(heightMeasureSpec)

Log.i(TAG, "PreviewView onMeasure($viewWidth, $viewHeight)")

val newWidth: Int
val newHeight: Int

val actualRatio = if (viewWidth > viewHeight) aspectRatio else 1f / aspectRatio
if (viewWidth < viewHeight * actualRatio) {
    newHeight = viewHeight
    newWidth = (viewHeight * actualRatio).roundToInt()
} else {
    newWidth = viewWidth
    newHeight = (viewWidth / actualRatio).roundToInt()
}

Log.d(TAG, "Measured dimensions set: $newWidth x $newHeight")
setMeasuredDimension(newWidth, newHeight)

}

This patch resolved my issue

@mrousavy
Copy link
Owner

mrousavy commented Feb 6, 2024

Created a PR to fix this issue once and for all: #2519 💪🚀
Thanks to everyone who sponsored me on GitHub to fix this bug!! 💖

Try the PR and see if it works (by checking out that branch and running the example app)

@Flocurry
Copy link
Author

Flocurry commented Feb 7, 2024

Hello @mrousavy, i've tested the 3.9.0-beta.2 and there's still de issue.

You can see below the preview scene

and how the photo taken looks like

@mrousavy
Copy link
Owner

mrousavy commented Feb 8, 2024

This is landscape mode - Orientation is not yet fully supported in VisionCamera. See this issue for details: #1891

@Flocurry
Copy link
Author

Flocurry commented Feb 9, 2024

Is there a release planned soon that fixes this issue ?

@mrousavy
Copy link
Owner

mrousavy commented Feb 9, 2024

What? I just liked the orientation issue

@Flocurry
Copy link
Author

Flocurry commented Feb 16, 2024

Hello @mrousavy, i've tested the 3.9.0-beta.6 version, i have these log in my Logcat

Screenshot 2024-02-16 155147

I suppose this is why my preview view is zoomed... I hope it can help you to fix the issue.

@mrousavy
Copy link
Owner

@Flocurry are you in landscape mode or portrait

@Flocurry
Copy link
Author

I'm in landscape mode

@mrousavy
Copy link
Owner

Yea okay, only portrait works atm. See #1891 for more details.

@Flocurry
Copy link
Author

Flocurry commented Mar 4, 2024

Hello @mrousavy .

Is it normal that the 4.0.0-beta.4 fix the landscape mode issue for the camera preview ?

With this version, sometimes I have the below error when I open the camera

'Camera.onError(session/invalid-output-configuration): Failed to configure the Camera Session because the output/stream configurations are invalid!', { [session/invalid-output-configuration: Failed to configure the Camera Session because the output/stream configurations are invalid!]
name: 'session/invalid-output-configuration',
_code: 'session/invalid-output-configuration',
_message: 'Failed to configure the Camera Session because the output/stream configurations are invalid!',
_cause:
{ stacktrace: 'java.util.concurrent.TimeoutException: Future[androidx.camera.core.impl.utils.futures.ListFuture@1f7eb6a] is not done within 5000 ms.\n\tat androidx.camera.core.impl.utils.futures.Futures.lambda$makeTimeoutFuture$1(Futures.java:439)\n\tat androidx.camera.core.impl.utils.futures.Futures$$ExternalSyntheticLambda0.call(Unknown Source:6)\n\tat androidx.camera.core.impl.utils.executor.HandlerScheduledExecutorService$HandlerScheduledFuture.run(HandlerScheduledExecutorService.java:245)\n\tat android.os.Handler.handleCallback(Handler.java:938)\n\tat android.os.Handler.dispatchMessage(Handler.java:99)\n\tat android.os.Looper.loopOnce(Looper.java:226)\n\tat android.os.Looper.loop(Looper.java:313)\n\tat android.os.HandlerThread.run(HandlerThread.java:67)\n',
message: 'Future[androidx.camera.core.impl.utils.futures.ListFuture@1f7eb6a] is not done within 5000 ms.' } }
2024-03-04 16:52:20.201 1374-26404 Camera2-Fr...cessorBase cameraserver E FrameProcessorBase: Error waiting for new frames: Connection timed out (-110)

and this error disappear if i go back and reopen the camera.

@Flocurry
Copy link
Author

Hello @mrousavy, the above issue persists with the 4.0.0-beta.6 version

@mrousavy
Copy link
Owner

Which issue? Preview stretching or output configuration error?

I cannot reproduce the output configuration error anymore in the latest beta.

@Flocurry
Copy link
Author

Flocurry commented Mar 14, 2024

I reproduce the output configuration error.

When I run your example (tag v4.0.0-beta.6 ) on my Galaxy Tab Active4 Pro, the preview is black and I have the log

[ERROR][MEMMGR ] camximagebuffer.h:668 IsInValidUsageState() [RealTimeFeatureZSLPreviewRawYUV_com.qti.node.memcpy6_OutputPortId0_ ][0xb40000706466d500] Client trying to use after releasing the ImageBuffer
2024-03-14 15:05:24.097 1143-1747 CamX ven...amera.provider@4.0-service_64 E [ERROR][META ] camxmetadatapool.cpp:1272 SetMetadataByTagInternal() Invalid size for tag 0 type 0 maxSize 1 unitsize 1 count 2 pool 3 tagName MainColorCorrectionMode client RealTimeFeatureZSLPreviewRawYUV_Stats0 pipeline RealTimeFeatureZSLPreviewRawYUV_0 cameraId -1

@Flocurry
Copy link
Author

Hello @mrousavy

I've tested the v4.0.0-beta.7 and it fixes the output configuration issue

Many thx ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💭 question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants