Galaxy Note8, Front camera MeteringPoint for focus/exposure is mirrored/flipped

162 views
Skip to first unread message
Assigned to scot...@google.com by eri...@google.com

mohammad aljammali

unread,
Nov 25, 2021, 5:10:48 AM11/25/21
to Android CameraX Discussion Group
To start with the back camera works fine.
 My activity is locked in portrait.

code for registering  tap :

  // Listen to tap events on the viewfinder and set them as focus regions
cameraPreview.setOnTouchListener(View.OnTouchListener setOnTouchListener@{ view: View, motionEvent: MotionEvent ->
when (motionEvent.action) {
MotionEvent.ACTION_DOWN -> return@setOnTouchListener true
MotionEvent.ACTION_UP -> {

// Get the MeteringPointFactory from PreviewView
val factory = cameraPreview.meteringPointFactory
var y = motionEvent.y
// if(lensFacing == CameraSelector.LENS_FACING_FRONT) {
// y = 
cameraPreview.height - motionEvent.y
// }
// Create a MeteringPoint from the tap coordinates
val point = factory.createPoint(motionEvent.x, y, 0.1f)

val characteristics = cameraManager.getCameraCharacteristics(lensFacing.toString());
if ( characteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF)!! >= 1 )
setFocus(point)

return@setOnTouchListener true
}
else -> return@setOnTouchListener false
}
})

private var focusing = false
@SuppressLint("RestrictedApi")
fun setFocus(point : MeteringPoint){
Log.d(TAG, "setFocus point: ${point.size}.")
Log.d(TAG, "setFocus width: ${point.x}.")
Log.d(TAG, "setFocus height: ${point.y}.")

if(!focusing) {
focusing = true
unlockFocus()
// Create a MeteringAction from the MeteringPoint, you can configure it to specify the metering mode
val action = FocusMeteringAction.Builder(point).build()
val focusListenableFuture = mcameraControl.startFocusAndMetering(action)
focusListenableFuture.addListener({
try {
val result = focusListenableFuture.get()
Log.d(TAG, "setFocus result: ${result.isFocusSuccessful}.")
if (result.isFocusSuccessful) {
// lockFocus()
focusing = false
} else {
focusing = false
}
} catch (e: ExecutionException) // Thrown exceptions
{
e.printStackTrace()
} catch (e: InterruptedException) // Thrown exceptions
{
e.printStackTrace()
}

}, ContextCompat.getMainExecutor(context))
}
}


running the App on Nokia 8 both front and back camera focus correctly.

the Issue is on Galaxy Note8 (back camera works fine) front camera where if I tap the top it will focus at the bottom and vice versa. 

the value of the metering points created from the tap on both phones is in the same range.

for example, taping the bottom will give me around  ( 0.2, 0.5) on both phones that resulting in perfect focus on Nokia 8 while in Galaxy Note8 it will focus on the top. 
this is using the front camera.


on the back camera tapping the bottom ( 0.8, 0.5) both phones will focus correctly. 


now adding this line of code on Samsung phone 

 if(lensFacing == CameraSelector.LENS_FACING_FRONT) {
 y = 
cameraPreview.height - motionEvent.y
}

to mirror the point. will fix it on Samsung but cause it to happen on the Nokia.

I tried to check the rotation of the cameraPreview and it is the same on both phones. 

any help is  appreciated 

Scott Nien

unread,
Nov 25, 2021, 11:22:39 AM11/25/21
to Android CameraX Discussion Group, mohammad....@gmail.com

Hi ,  
Can you help query the SENSOR_ORIENTATION of the front camera ?    

And are you using CameraSelector lensFacing to select the camera or are you intentionally selecting specific camera id ?  (Just want to know which camera id you were using for the front camera). 

mohammad aljammali

unread,
Nov 25, 2021, 6:11:23 PM11/25/21
to Android CameraX Discussion Group, Scott Nien, mohammad aljammali
Hi Scott,

The SENSOR_ORIENTATION is  90 on both phones. 

and I am using CameraSelector lensFacing to select the camera.

and I also used it to get the SENSOR_ORIENTATION because I clud not and I way to get camera ID in CmaraX
val characteristics = cameraManager.getCameraCharacteristics(CameraSelector.LENS_FACING_FRONT .toString());

 (I think I should not ) but both CameraSelector.LENS_FACING_FRONT  and  Camera2  cManager.getCameraIdList() with if statement CameraCharacteristics.LENS_FACING_FRONT will both give '0'



code used to choose and launch the camera 

val screenAspectRatio = AspectRatio.RATIO_4_3

val rotation = cameraPreview.display.rotation

// CameraProvider
val cameraProvider = cameraProvider
?: throw IllegalStateException("Camera initialization failed.")

// CameraSelector
val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()

//lensFacing is either CameraSelector.LENS_FACING_FRONT or CameraSelector.LENS_FACING_BACK

// Preview
preview = Preview.Builder()
.setTargetAspectRatio(screenAspectRatio)
.setTargetRotation(rotation)
.build()

// ImageCapture
imageCapture = ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setTargetAspectRatio(screenAspectRatio)
.setTargetRotation(rotation)
.build()
cameraProvider.unbindAll()

try {
camera = cameraProvider.bindToLifecycle(
this, cameraSelector, preview, imageCapture)
mcameraControl = camera!!.cameraControl
mCamera2CameraControl = Camera2CameraControl.from(mcameraControl)
preview?.setSurfaceProvider(cameraPreview.surfaceProvider)
} catch (exc: Exception) {
Log.e(TAG, "Use case binding failed", exc)

Scott Nien

unread,
Nov 28, 2021, 5:34:24 AM11/28/21
to mohammad aljammali, Android CameraX Discussion Group
val characteristics = cameraManager.getCameraCharacteristics(CameraSelector.LENS_FACING_FRONT .toString());
This doesn't seem to work.  You need to pass the camera id here which is normally "0" for the primary back camera and "1" for the front camera. 

Can you get the SENSOR_ORIENTATION again ?  I think it should be 270 degrees for the front camera (camera id "1"). 

And can you compare it with the system camera app ?  Some front cameras don't have AF but only AE capability but it is sometimes not easy to see the difference.  
Comparing it with the system camera app will have more ideas on what should be expected when tapping on the preview. 



mohammad aljammali

unread,
Nov 28, 2021, 8:58:50 PM11/28/21
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, mohammad aljammali
Hi Scott, 
thanks for the replay. 

I am got SENSOR_ORIENTATION for both cameras using both camera IDs and camera selector. 

D/TAG: SENSOR_ORIENTATION camerasId:0
D/TAG: LENS_FACING_FRONT SENSOR_ORIENTATION: 90.
D/TAG: SENSOR_ORIENTATION camerasId:1
D/TAG: LENS_FACING_BACK SENSOR_ORIENTATION: 270.
D/TAG: CameraSelector.LENS_FACING_FRONT.toString() SENSOR_ORIENTATION: 90.
D/TAG: CameraSelector.LENS_FACING_BACK.toString() SENSOR_ORIENTATION: 270.

code used to get the SENSOR_ORIENTATION values: 
2021-11-29_12-33.png


regarding the system camera App, it seems it has AF also, I do check before trying to focus.

2021-11-29_12-47.png


I attached screen recordings for both the system camera App and mine showing the tap location and the result of focusing. 

https://drive.google.com/drive/folders/1NyZK6oCGjOaNNqQ8QEztTiSvQ5IoR4JD?usp=sharing
it is in google drive link because it exceeds the size limit. 

thanks for the help.

Scott Nien

unread,
Nov 29, 2021, 10:46:17 AM11/29/21
to mohammad aljammali, Android CameraX Discussion Group
Hi Mohammad, 
I shared an APK with you on your gmail account.  Can you test it on Note 8 ? 

mohammad aljammali

unread,
Nov 29, 2021, 8:05:37 PM11/29/21
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, mohammad aljammali
Hi Scott,


I tested it, the focus issue is present.

There is a discrepancy between my app and yours regarding the camera ID and SENSOR_ORIENTATION  but the flipped Y axis is still there when tap to focus. 

please see the screen recording.

https://drive.google.com/drive/folders/1PpND9gH2Vz74Dlp_cGrRpT50nDSx5o00?usp=sharing

mohammad aljammali

unread,
Nov 29, 2021, 8:15:02 PM11/29/21
to Android CameraX Discussion Group, mohammad aljammali, Scott Nien, Android CameraX Discussion Group
for a sanity check,  I also tested your apk on Nokia 8  and it works as expected. 

I can provide a screen recording if you wish. 

so the Issue is present on Samsung note 8 and I suspect Samsung note 9 ( based on a report of my colleague to who I sent my app, I do not have the device hands-on )  

Scott Nien

unread,
Nov 29, 2021, 8:22:03 PM11/29/21
to mohammad aljammali, Android CameraX Discussion Group
Thanks for the test !  
Now it seems certain that there are definitely some issues on note 8. We will try to find one to investigate further.  
Can you share the exact model name of your note 8 ?    

mohammad aljammali

unread,
Nov 29, 2021, 8:43:04 PM11/29/21
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, mohammad aljammali
you're welcome.

Model number: SM-N950F

BTW as I mentioned I won't be surprised if it is present in all Samsung devices at least released at the same time.  

Scott Nien

unread,
Dec 13, 2021, 11:26:54 PM12/13/21
to mohammad aljammali, Android CameraX Discussion Group
Hi Mohammad, 
Bug (https://issuetracker.google.com/210548792) filed for tracking this issue.  Already cc'ed you. 

mohammad aljammali

unread,
Nov 2, 2022, 2:30:41 AM11/2/22
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, mohammad aljammali

I can confirm it is fixed in CameraX Version 1.2.0-rc01

thanks, Scott

Scott Nien

unread,
Nov 2, 2022, 10:54:00 AM11/2/22
to mohammad aljammali, Android CameraX Discussion Group
Thank you for letting me know !  It's great to see it working. 

--
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/00338ba3-aa47-42f4-9baa-2fbbf540a743n%40android.com.
Reply all
Reply to author
Forward
0 new messages