我想裁剪从手机拍摄的图像中检测到的脸部。我正在使用Google视觉API来检测人脸。我看到了一些类似于我的问题,但是他们正在使用openCV。
我尝试添加Bitmap.createBitmap();
,但是它只能接受int值。但是我的值是十进制,所以是浮点数。
这是我的人脸检测代码:
private void scanFaces(){
Bitmap bitmap = BitmapFactory.decodeFile(pathToFile);
if (detector.isOperational() && bitmap != null) {
editedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), bitmap.getConfig());
float scale = getResources().getDisplayMetrics().density;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.rgb(255, 61, 61));
paint.setTextSize((int) (14 * scale));
paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3f);
Canvas canvas = new Canvas(editedBitmap);
canvas.drawBitmap(bitmap, 0, 0, paint);
Frame frame = new Frame.Builder().setBitmap(editedBitmap).build();
SparseArray<Face> faces = detector.detect(frame);
}
if (faces.size() == 0) {
deleteMediaFile();
Intent intent = new Intent(FaceRegistration.this, NoFaceDetected.class);
startActivity(intent);
}
else {
Face face = faces.valueAt(index);
canvas.drawRect(
face.getPosition().x,
face.getPosition().y,
face.getPosition().x + face.getWidth(),
face.getPosition().y + face.getHeight(), paint);
imageView.setImageBitmap(editedBitmap);
}
} else {
Toast.makeText(getApplicationContext(),"could not set up detector!" , Toast.LENGTH_SHORT).show();
}
}