I need to capture the image from the Android camera and detect if the user places their finger on top (dark). Is there a library that does this simply?
Thanks,
I need to capture the image from the Android camera and detect if the user places their finger on top (dark). Is there a library that does this simply?
Thanks,
I've never heard of such a library, I believe just doing a direct check on the captured image to find out. And doing this "manually" checking is not so hard if it does not depend on too much accuracy.
For example, you could 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;
}
It may be necessary 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 precisely meet your needs, but I imagine this is already a north for you. >