代码之家  ›  专栏  ›  技术社区  ›  Sergey Rokitskiy

如何在实时图像上绘制地标点

  •  0
  • Sergey Rokitskiy  · 技术社区  · 7 年前

    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
            rgba = inputFrame.rgba();
           try {
                Bitmap bmp = matToBitmap(rgba);
               points = getLandmark(bmp, this, predictorPath); // getting 68 points
    
              drawPoints(bmp, points);
    
            } catch (Exception e) {
                Log.i(TAG, "bitmap error! " + e.getMessage());
            }
            return rgba;
        }
    

    编辑: 添加了此方法,但什么都没有发生

    public void drawPoints(Bitmap bitmap, List<Point> points) {
    
            Canvas canvas = new Canvas(bitmap);
    
            Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint.setColor(Color.RED);
            float radius = 4f;
    
            // draw points
            for(Point point : points) {
                canvas.drawCircle(point.x, point.y, radius, paint);
            }
        }
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   RobCo    7 年前

    可以在Canvas类的帮助下在位图上绘制点。例如:

    public void drawPoints(Bitmap bitmap, List<Point> points) {
        // a canvas for drawing on the bitmap
        Canvas canvas = new Canvas(bitmap);
        // a paint to describe how points are drawn
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.RED);
        float radius = 4f;
    
        // draw points
        for(Point point : points) {
            canvas.drawCircle(point.x, point.y, radius, paint);
        }
        // the bitmap has now been updated
    }
    

    这可以根据您接收点的方式和希望点的显示方式(大小、颜色、形状等)进行更改。
    对于实时绘制,您可能需要缓存绘制对象。

        2
  •  0
  •   Anton Potapov    7 年前

    Here 您将找到有关此的更多信息。