Umar Ghaffar
Umar Ghaffar

Reputation: 131

How to draw Flag on Face Or Paint Or Overlay Image on Face or another Image in Android pragmatically

I am developing a project in Android to Draw/Overlay/Paint flag or other image on Face. Or Draw/Overlay/Paint an Image with another image i.e. embed image into other. But the second image should be exact on the face. Take a close look below

See this picture

I am using the Face Detection Vision Api of Google, and get the Landmarks and even whole face and draw a simple rectangle around using An Introduction to Face Detection on Android

But the Question is:

Please give me some sample code that how to start with or give me some github libs if available. Thanks.

Upvotes: 0

Views: 232

Answers (1)

Aousaf Rashid
Aousaf Rashid

Reputation: 5738

This could've been a comment, but i felt like sharing this idea as an answer.

Note that this is just an idea

I have used Google's Vision API but that was quite some time ago. As far as i remember, you can draw a rectangle over a face and get it's positions aka landmarks. You can make use of that.

Instead of writing a complicated paint function where you have to draw a Bitmap, rather construct a new ImageView. Set it's height and width by calculating the position/landmark of the rectangle and also position the new ImageView over the rectangle. Positioning the ImageView might be relatively easier as you have the rectangles XY coordinates(i guess). Then simply set it's source as the flag image or anything you want. You can set the opacity(alpha value) of the ImageView to a lower value to make it blend it.

If you want to only paint the face and not create an overlay, that's a different topic. You will need to take a few pixels from the face, get their color values, then paint the other image over that. It's not gonna be easy, but i guess this is the way to go.

Guidelines :

Getting color of pixels

Drawing images pixel by pixel

Upvotes: 1

Related Questions