簡體   English   中英

如何在Android中裁剪僅圖像中的面孔?

[英]How to Crop only face from an image in android?

我要求只顯示圖像中的臉部。 但是,我試圖僅使用android native方法來實現這一點。

我已經通過以下鏈接

在Android中使用面部檢測裁剪圖像

但是,上面鏈接中提到的代碼不適用於所有圖像。

如果有人已經有相同的要求,請指導我。

謝謝。

人臉檢測算法永遠不會(也永遠不會)准確。 即使是人類,有時也會在烤面包片中看到耶穌的臉。 即使參考實現(人腦)也包含錯誤,您如何期望計算機能夠100%正確地檢測到面部。

當未檢測到(或多個)面部時,應包括一個后備方案。 或者在使用圖片之前對它們進行質量檢查。

您可以使用具有較大拐角半徑的此圓角矩形代碼來實現一個圓( Romain Guy的食譜 ):

BitmapShader shader;
shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);

RectF rect = new RectF(0.0f, 0.0f, width, height);

// rect contains the bounds of the shape
// radius is the radius in pixels of the rounded corners
// paint contains the shader that will texture the shape
canvas.drawRoundRect(rect, radius, radius, paint);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM