0
I need to capture the image of the Android camera and detect if the user puts his finger on top (dark). Is there a library that does it simply?
Thank you,
0
I need to capture the image of the Android camera and detect if the user puts his finger on top (dark). Is there a library that does it simply?
Thank you,
1
I’ve never heard of such a library, I believe only by performing a direct check on the captured image to find out. And performing this check "manually" is not so difficult if it doesn’t depend on a lot of precision.
For example I would do something like this:
public static boolean ImagemEscura(Bitmap img)
{
float totalpixel = img.getWidth() * img.getHeight();
float totalpixelescuro = 0;
for(int x = 0; x < img.getWidth(); x++)
{
for(int y = 0; y < img.getHeight(); y++)
{
int cor = img.getPixel(x, y);
//supondo que o valor como sendo escuro significa que a soma dos
//valores RGB não podem ultrapassar 90
if(SomaRGB(cor) > 90)
{
totalpixelescuro++;
}
}
}
//se existir mais de 75% dos pixels escuro ele entende que o dedo esta na frente
return totalpixelescuro/totalpixel > 0.75f;
}
public static int SomaRGB(int cor)
{
return getRed(cor) + getGreen(cor) + getBlue(cor);
}
public static int getRed(int argb)
{
return argb >> 16 & 0xFF;
}
public static int getGreen(int argb)
{
return argb >> 8 & 0xFF;
}
public static int getBlue(int argb)
{
return argb & 0xFF;
}
You may need to put it to run on a Thread outside the UI to avoid some crash in the App and make some adjustments to the parameters to more accurately meet your needs, but I imagine this is already a north for you.
Browser other questions tagged android android-camera
You are not signed in. Login or sign up in order to post.