2017-08-03 64 views
0

需要幫助! 我有這個代碼。我如何繪製68並在相機預覽中看到它們?如何通過實時圖像繪製地標點

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); 
     } 
    } 
+0

https://stackoverflow.com/a/24038899/1848157請參閱此。 – Radhey

回答

0

您可以藉助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 
} 

這取決於你如何接收點,你想怎麼點出現(大小,顏色,形狀等)來改變。
對於實時繪圖,您可能需要緩存Paint對象。

+0

我需要實時繪圖。你能幫助我,並向我解釋我如何緩存Paint對象。現在我添加你的方法在我的代碼中,但沒有... –

+0

嗯,是的,你正在繪製它的位圖,但沒有做任何事情。它將不得不在例如預覽表面頂部的ImageView中呈現。 – RobCo

+0

或者,您可以直接在OpenCV的Mat對象中繪製。也許應該在Java api的某個地方使用[circle](http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#circle)方法(我不確定哪個類確切地說,但它是一些靜態方法)。那麼你可以放下整個Bitmap,但這也取決於你如何渲染它。 – RobCo

0

嘗試使用畫布上繪製位圖的東西。 Here你會找到更多關於這方面的信息。