Pergunta

I have following code:

protected void onDraw(Canvas canvas)
        {
            paint.setStyle(Paint.Style.STROKE);
            paint.setColor(Color.RED);

            xRatio = getWidth()*1.0f / picWidth;
            yRatio = getHeight()*1.0f / picHeight;                      
            canvas.drawBitmap( sourceImage, null , new Rect(0,0,getWidth(),getHeight()),paint);

            for (int i = 0; i < eyesMidPts.length; i++)
            {
                if (eyesMidPts[i] != null)
                {
                    // where x and y are eyes mid point coordinates

                    float x = eyesMidPts[i].x*xRatio;
                    float y = eyesMidPts[i].y*yRatio;
                    float radius = (float) (eyesDistance[i]);
                    float left =  x - radius;
                    float right = x + radius;
                    float top = y - radius;
                    // we want to increase the bottom radius by double to get other half of the face.
                    float bottom = (float) (y + radius * 2);                    

                    paint.setStrokeWidth(eyesDistance[i] /20);                  
                    RectF ovalBounds = new RectF();
                    ovalBounds.set(left, top, right, bottom);                                                       
                    canvas.drawOval(ovalBounds, paint);                                     
                }
            }           
        }   

Code encompass full face if face is straight. But does not get complete circle around if face is tilted. I am not sure how euler angels work but am hoping it is to get tilt on the face detection. Can someone please help me with this show me some example code so that circle encompasses whole face.

Foi útil?

Solução

Why do you use RectF to draw a circle? Is it a 'true' circle, or is it really oval / ellipse?

If it's just a circle, why don't you use this.

canvas.drawCircle(x, y, radius, paint);

So you won't need to transform Rectf's points if it's tilted :)

update:

I believe this should work, I don't have an android workflow setup with me to really test it; sorry if it's a miss.

Matrix m = new Matrix(); //creates identity matrix
m.setRotate(tilt_angle); //rotate it by the tilt angle
m.mapRect(ovalBounds); //transform the rect

Outras dicas

// RectF face: face position and dimentions

// Create Bitmap where to draw an oval
Bitmap ovalBmp = Bitmap.createBitmap( face.width(), face.height(), config );
canvasBmp = new Canvas(ovalBmp); // Get a canvas to draw an oval on the Bitmap
canvasBmp.drawOval( new RectF( 0, 0, face.width(), face.height ), paint );

// Create transformation matrix
transforMatrix = new Matrix();
// Rotate around center of oval
transforMatrix.postRotate( tilt_angle, face.width() / 2, face.height() / 2 );
transforMatrix.postTranslate( face.left, face.top );
canvas.drawBitmap( ovalBmp, transforMatrix, null );

ps: I assume by tilt angle you mean roll, where pitch is rotation around X axis, yaw is rotation around Y axis and roll is rotation around Z axis.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top