moving crop window before live preview of camera

112 views
Skip to first unread message

Suisse

unread,
Dec 30, 2020, 12:36:00 PM12/30/20
to Android CameraX Discussion Group
I am looking for this for a long time. Any suggestion will be appreciated. 

I am detecting the face of a person in the camera preview with google MLKit.
It means I have for each frame of the camera the boundaries and scale of the face.
face_found = [x,y,w,h]; 

I now want to only display the face of the user, since I have every argument I need to crop the face out of the frame and only show this region of interest (ROI). 

How can I achieve this goal? And if its not possible with CameraX, is there something else I can use for this? How is snapchat doing such tasks? 

Charcoal Chen

unread,
Dec 31, 2020, 2:51:35 AM12/31/20
to Android CameraX Discussion Group, Suisse
To achieve the goal, you may need to render the camera preview with opengl processing. CameraX has a coretestapp sample project implemented in that way. Maybe you can try to add an updateFaceRect() function in OpenGLRenderer.java and call it when a new face location rectangle is found to make the preview output result only show target rectangle area:

// Update  the face location rectangle
void updateFaceRect(RectF faceRect) {
    // Update the preview crop rectangle to be the found face location rectangle
    mPreviewCropRect = faceRect;
    // Trigger to update transformations to only show the face location rectangle area
    mMvpDirty = true;

Xi Zhang (张熹)

unread,
Jan 5, 2021, 5:35:55 PM1/5/21
to Charcoal Chen, Android CameraX Discussion Group, Suisse
If you prefer not to use OpenGL, you can also achieve cropping by calling setTranslationX/setTranslationY/setScaleX/setScaleY/setRotation on the view finder. You just need to make sure a TextureView is used to display the preview. 

However if you are already using OpenGL, or if you need a skew or non-affine transformation, then please see Charcoal's solution.

--
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/2a8aad71-4dfd-4995-9a38-072504edd5b7n%40android.com.
Reply all
Reply to author
Forward
0 new messages