Я реализую проект, который может быть основан на Обнаружении лиц, и я хочу использовать Firebase Ml Kit для обнаружения лиц. Но когда я выбираю одно изображение и выполняю поиск по камере и галерее изображений, получаю тот же результат изображения объекта. и мой вопрос, как получить два изображения (возможно, они отличаются, а может быть, это то же самое)
объекта то же самое или нет в Android.
Вот код Java для одного изображения Ml, и я не знаю, как сравнить другое изображение ML с первым изображением ML
Ребята, пожалуйста, поделитесь какой-нибудь логикой.
public class MainActivity extends AppCompatActivity {
TextView mText;
Button mButton;
ImageView mImageView;
ProgressBar mBar;
private GraphicOverlay mGraphicOverlay;
private static final String TAG = "FaceTracker";
private CameraSource mCameraSource = null;
private CameraSourcePreview mPreview;
private static final int RC_HANDLE_GMS = 9001;
// permission request codes need to be < 256
private static final int RC_HANDLE_CAMERA_PERM = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PermissionCheck();
}
private void PermissionCheck() {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed; request the permission
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_NETWORK_STATE},
1);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
Initilization();
}
}
private void Initilization() {
mPreview = (CameraSourcePreview) findViewById(R.id.preview);
mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);
mImageView = (ImageView) findViewById(R.id.imageview);
mButton = (Button) findViewById(R.id.detect_buttton);
mText = (TextView) findViewById(R.id.text_view);
mBar = (ProgressBar) findViewById(R.id.progressbar);
mImageView.setImageDrawable(getDrawable(R.drawable.dhoni1));
runFaceDetector(imageView2Bitmap(mImageView));
}
private Bitmap imageView2Bitmap(ImageView view) {
Bitmap bitmap = ((BitmapDrawable) view.getDrawable()).getBitmap();
return bitmap;
}
private void runFaceDetector(Bitmap bitmap) {
mBar.setVisibility(View.VISIBLE);
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
FirebaseVisionFaceDetectorOptions options = new FirebaseVisionFaceDetectorOptions.Builder().build();
FirebaseVisionFaceDetector detector = FirebaseVision.getInstance().getVisionFaceDetector(options);
detector.detectInImage(image).addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionFace>>() {
@Override
public void onSuccess(List<FirebaseVisionFace> firebaseVisionFaces) {
processFaceResult(firebaseVisionFaces);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mBar.setVisibility(View.GONE);
Toast.makeText(MainActivity.this, "Error Face " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void processFaceResult(List<FirebaseVisionFace> firebaseVisionFaces) {
for (FirebaseVisionFace face : firebaseVisionFaces) {
Rect bounds = face.getBoundingBox();
face.getContour(0);
face.getHeadEulerAngleY();
mText.setText(face.getTrackingId() + " || " + face.getHeadEulerAngleY() + " || " + face.getHeadEulerAngleZ()
+ " || " + face.getLeftEyeOpenProbability() + " || " + face.getRightEyeOpenProbability() + " || " + face.getSmilingProbability()
+ " || " + face.getBoundingBox().bottom + " || " + face.getBoundingBox().top + " || " + face.getBoundingBox().right
+ " || " + face.getBoundingBox().left + " || " + face.getLandmark(0));
}
mBar.setVisibility(View.GONE);
}
}
XML-код:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="250dp" />
<Button
android:id="@+id/detect_button"
android:layout_width="match_parent"
android:text="Detect"
android:layout_below="@+id/imageview"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_below="@+id/detect_buttton"
android:id="@+id/text_view"
android:layout_height="wrap_content" />
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:id="@+id/progressbar"/>