Pixelated preview when using CameraEffect

39 views
Skip to first unread message

Anton Ivanov

unread,
Oct 17, 2024, 7:54:21 AMOct 17
to Android CameraX Discussion Group
Hey,
I'm trying to build a custom CameraEffect using this as a reference.
Everything works fine except that preview is pixelated when using CameraEffect(it's of much better quality when effect is not added).
I suspect it's because surfaceOutput I get in onOutputSurface is of 864x1920 resolution while the preview is 1920x1440 but I don't get how to change it.

My vertex and fragment shaders are pretty basic: 
uniform mat4 u_TextMatrix;
attribute vec4 a_Position;
attribute vec2 a_TextCoord;
varying vec2 v_TextCoord;

void main() {
v_TextCoord = (u_TextMatrix * vec4(a_TextCoord, 0.0, 1.0)).xy;
gl_Position = a_Position;
}

uniform mat4 u_TextMatrix;
attribute vec4 a_Position;
attribute vec2 a_TextCoord;
varying vec2 v_TextCoord;

void main() {
v_TextCoord = (u_TextMatrix * vec4(a_TextCoord, 0.0, 1.0)).xy;
gl_Position = a_Position;
}
Also I set up CameraX like this:
val previewUseCase = Preview
.Builder()
.setResolutionSelector(
ResolutionSelector
.Builder()
.setResolutionStrategy(
ResolutionStrategy(
Size(1920, 1080),
ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER,
)
).build()
)
.build()
.also { it.setSurfaceProvider(previewView.surfaceProvider) }

val useCaseGroup = UseCaseGroup
.Builder()
.setViewPort(previewView.viewPort!!)
.addUseCase(previewUseCase)
.addEffect(surfaceEffect)
.build()

processCameraProvider.get().bindToLifecycle(
this,
CameraSelector.DEFAULT_FRONT_CAMERA,
useCaseGroup,
)

Setting up of external texture is pretty basic as well - just GL_LINEAR.

What am I doing wrong here? Could you point out please.

Screenshot_20241017_125226.png
Screenshot_20241017_125253.png

Anton Ivanov

unread,
Oct 17, 2024, 8:27:50 AMOct 17
to Android CameraX Discussion Group, Anton Ivanov
Ok, it seems I found the issue.
I forgoyt to do setDefaultBufferSize

Christian Deschenes

unread,
Oct 17, 2024, 9:38:06 AMOct 17
to Anton Ivanov, Android CameraX Discussion Group

https://www.celsoazevedo.com/files/android/google-camera/how-to/


CONFIDENTIAL

This  e-mail  and  any  attachments  are  confidential  and  intended  solely  for  the  addressee  and  may  also  be privileged or exempt from disclosure under applicable law. If you are not the addressee, or have received this e-mail in error, please notify the sender immediately, delete it from your system and do not copy, disclose or otherwise act upon any part of this e-mail or its attachments. Internet communications are not guaranteed to be secure or virus-free. Revolut does not accept responsibility for any loss arising from unauthorised access to, or interference with, any Internet communications by any third party, or from the transmission of any viruses. Replies to this e-mail may be monitored by Revolut for operational or business reasons. Any  opinion  or  other  information  in  this  e-mail  or  its  attachments  that  does  not  relate  to  the  business  of Revolut is personal to the sender and is not given or endorsed by Revolut. Registered  Office: 7  Westferry  Circus,  Canary  Wharf, London,  E14  4HD,  United  Kingdom.  Main  Office: 7 Westferry  Circus,  Canary  Wharf, London,  E14  4HD, United  Kingdom. Revolut  Ltd  is  authorised  and regulated by the Financial Conduct Authority under the Electronic Money Regulations 2011, Firm Reference 900562.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/0cf1d5f7-7236-44ee-8990-a3fad442a184n%40android.com.

Christian Deschenes

unread,
Oct 17, 2024, 9:42:02 AMOct 17
to Anton Ivanov, Android CameraX Discussion Group
Reply all
Reply to author
Forward
0 new messages