Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7638949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:17:54+00:00 2026-05-31T08:17:54+00:00

So I have code to detect up to 10 faces in any given image

  • 0

So I have code to detect up to 10 faces in any given image file and return to me info like the location of the eyes and other stuff like that. So when i tell it to use an image file that is stored in the drawable folder of resources for my project it works great. But when i have it try to find faces from a bitmap i import from the sd card it wont find any faces. But these are the same exact images. Any ideas? my code is bellow:

Edit:
After further inspection I found that when i insert this line of code System.out.println("Row Bytes: " + sourceImage.getRowBytes());
I get the drawable is 352 and The SD card image is 704. Which I think means that the drawable is being compressed in the .apk file but the SD card image obviously is not. Not sure if this would effect anything.

 public class FaceView extends View {
           private static final int NUM_FACES = 10; // max is 64
           private static final boolean DEBUG = true;

           private FaceDetector arrayFaces;
           private FaceDetector.Face getAllFaces[] = new FaceDetector.Face[NUM_FACES];
           private FaceDetector.Face getFace = null;

           private PointF eyesMidPts[] = new PointF[NUM_FACES];
           private float  eyesDistance[] = new float[NUM_FACES];

           private Bitmap sourceImage;

           private Paint tmpPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
           private Paint pOuterBullsEye = new Paint(Paint.ANTI_ALIAS_FLAG);
           private Paint pInnerBullsEye = new Paint(Paint.ANTI_ALIAS_FLAG);

           private int picWidth, picHeight;
           private float xRatio, yRatio;

           public FaceView(Context context) {
                   super(context);

                   pInnerBullsEye.setStyle(Paint.Style.FILL);
                   pInnerBullsEye.setColor(Color.RED);

                   pOuterBullsEye.setStyle(Paint.Style.STROKE);
                   pOuterBullsEye.setColor(Color.RED);

                   tmpPaint.setStyle(Paint.Style.STROKE);
                   tmpPaint.setTextAlign(Paint.Align.CENTER);

                   BitmapFactory.Options bfo = new BitmapFactory.Options();
                   bfo.inPreferredConfig = Bitmap.Config.RGB_565;

                   //********This code imports the image from the SD card which does not work
                   String imageInSD = Environment.getExternalStorageDirectory()
                        .getAbsolutePath() + "/testfolder/" + "face1" + ".png";

                   Bitmap sourceImage = BitmapFactory.decodeFile(imageInSD,bfo);

                   //**********This code uses an image in the projects drawable folder, this code works.
                   sourceImage = BitmapFactory.decodeResource( getResources() ,R.drawable.face1, bfo);

                   picWidth = sourceImage.getWidth();
                   picHeight = sourceImage.getHeight();

                   arrayFaces = new FaceDetector( picWidth, picHeight, NUM_FACES );
                   arrayFaces.findFaces(sourceImage, getAllFaces);

                   for (int i = 0; i < getAllFaces.length; i++)
                   {
                           getFace = getAllFaces[i];
                           try {
                                   PointF eyesMP = new PointF();
                                   getFace.getMidPoint(eyesMP);
                                   eyesDistance[i] = getFace.eyesDistance();
                                   eyesMidPts[i] = eyesMP;

                                   if (DEBUG)
                                   {
                                           Log.i("Face",
                                                   i +  " " + getFace.confidence() + " " + getFace.eyesDistance() + " "
                                                   + "Pose: ("+ getFace.pose(FaceDetector.Face.EULER_X) + ","
                                                   + getFace.pose(FaceDetector.Face.EULER_Y) + ","
                                                   + getFace.pose(FaceDetector.Face.EULER_Z) + ")"
                                                   + "Eyes Midpoint: ("+eyesMidPts[i].x + "," + eyesMidPts[i].y +")"
                                           );
                                   }
                           }
                           catch (Exception e)
                           {
                                   if (DEBUG) Log.e("Face", i + " is null");
                           }

                   }


           }

           @Override
           protected void onDraw(Canvas canvas)
           {
                   xRatio = getWidth()*1.0f / picWidth;
                   yRatio = getHeight()*1.0f / picHeight;
                   canvas.drawBitmap( sourceImage, null , new Rect(0,0,getWidth(),getHeight()),tmpPaint);
                   for (int i = 0; i < eyesMidPts.length; i++)
                   {
                           if (eyesMidPts[i] != null)
                           {
                                   pOuterBullsEye.setStrokeWidth(eyesDistance[i] /6);
                                   canvas.drawCircle(eyesMidPts[i].x*xRatio, eyesMidPts[i].y*yRatio, eyesDistance[i] / 2 , pOuterBullsEye);
                                   canvas.drawCircle(eyesMidPts[i].x*xRatio, eyesMidPts[i].y*yRatio, eyesDistance[i] / 6 , pInnerBullsEye);
                           }
                   }


           }  

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:17:55+00:00Added an answer on May 31, 2026 at 8:17 am

    Turns out the issue is that the pictures taken by the Camera are saved as PNG files and the face detection can only successfully work from the SD card if it is using JPG files. Simply convert the files to JPG and it works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that references a web service, and I'd like the address of
I have code like this: var newMsg = new Msg { Var1 = var1,
I have code like this: template <typename T, typename U> struct MyStruct { T
I have code like this to move the player in my game left, right,
I have code that looks like the following, which works fine for displaying the
I have a code to detect if I have internet connection or not, and
I have some code running on my website which will detect if a div
How to detect Safari browser using JavaScript? I have tried code below and it
I have code to detect the connection of USB Flash Drives as volumes. The
I have the following code: def causes_exception(lamb): try: lamb() return False except: return True

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.