Android:使用 Google Vision API 在面部绘制地标

问题描述

我有当前的代码,可以在实时相机预览中围绕用户的脸部绘制一个边界框。

我还尝试在实时相机预览中绘制面部标志的位置。由于没有比例值,它绘制了它们但不在正确的位置

我在网上找到了这段代码,但我很难计算这个比例值,因为它是实时相机预览而不是位图图像

网上找到的示例代码

 double scale = Math.min( viewWidth / imageWidth,viewHeight / imageHeight );

 for (Landmark landmark : face.getLandmarks()) {
        int cx = (int) (landmark.getPosition().x * scale);
        int cy = (int) (landmark.getPosition().y * scale);
        canvas.drawCircle(cx,cy,10,paint);
    }

我的功能

@Override
   public void draw(Canvas canvas) {
       Face face = mFace;

       if (face == null) {
           return;
       }


       // Draws a circle at the position of the detected face,with the face's track id below.

    
       float x = translateX(face.getPosition().x + face.getWidth() / 2);
       float y = translateY(face.getPosition().y + face.getHeight() / 2);
       canvas.drawCircle(x,y,FACE_POSITION_RADIUS,mFacePositionPaint);
      


       // Draws a bounding box around the face.
       float xOffset = scaleX(face.getWidth() / 2.0f);
       float yOffset = scaleY(face.getHeight() / 2.0f);
       float left = x - xOffset;
       float top = y - yOffset;
       float right = x + xOffset;
       float bottom = y + yOffset;
       canvas.drawRect(left,top,right,bottom,mBoxPaint);

       Paint paint = new Paint();
       paint.setColor( Color.GREEN );
       paint.setStyle( Paint.Style.STROKE );
       paint.setStrokeWidth( 5 );

       for ( Landmark landmark : face.getLandmarks() ) {
           int cx = (int) ( landmark.getPosition().x);
           int cy = (int) ( landmark.getPosition().y);
           canvas.drawCircle( cx,paint );
       }

       }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)