I'm trying to use some API from someone on github: https://github.com/LintraMax/SourceAFIS-Android to compare 2 fingerprints on my attendance project, basically I convert from bytes[] to bitmap then I save to local storage and generate a uri to call the method to compare 2 fingerprints. I get this exception, every time, it looks like in android method "Paths.get()))))" is unable to get the image.
private double compareFingerPrints(Bitmap bitmapProbe, Bitmap bitmapCandidate){
boolean matches = false;
double score = 0;
Uri uriProbe = saveReceivedImage(bitmapProbe);
Uri uriCandidate = saveReceivedImage(bitmapCandidate);
FingerprintTemplate probe = null, candidate = null;
try {
probe = new FingerprintTemplate(
new FingerprintImage()
.dpi(500)
.decode(Files.readAllBytes(Paths.get(String.valueOf(uriProbe)))));
candidate = new FingerprintTemplate(
new FingerprintImage()
.dpi(500)
.decode(Files.readAllBytes(Paths.get(String.valueOf(uriCandidate)))));
} catch (Exception e) {
e.printStackTrace();
}
assert probe != null;
assert candidate != null;
score = new FingerprintMatcher().index(probe).match(candidate);
matches = score >= 40;
return score;
}
private Uri saveReceivedImage(Bitmap bitmap) {
String filePath = null;
Uri uri = null;
try {
String imageName = "FingerPrint_" + Timestamp.now().getSeconds();
File path = new File(getContext().getFilesDir(), "FingerPrints" + File.separator);
if (!path.exists()) {
path.mkdirs();
}
File outFile = new File(path, imageName + ".jpeg");
FileOutputStream outputStream = new FileOutputStream(outFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
uri = Uri.fromFile(outFile);
outputStream.close();
} catch (FileNotFoundException e) {
Log.e(TAG_SAVE_LOCAL, "Saving received message failed with", e);
} catch (IOException e) {
Log.e(TAG_SAVE_LOCAL, "Saving received message failed with", e);
}
return uri;
}
error
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.andrushka.schoolattendance, PID: 6255 java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at com.machinezoo.sourceafis.FingerprintMatcher.index(FingerprintMatcher.java:84) at com.andrushka.studentattendance.fragments.AttendanceFragment.compareFingerPrints(AttendanceFragment.java:552) at com.andrushka.studentattendance.fragments.AttendanceFragment.createPopupAttendanceScanFingerPrint(AttendanceFragment.java:454) at com.andrushka.studentattendance.fragments.AttendanceFragment.access$200(AttendanceFragment.java:69) at com.andrushka.studentattendance.fragments.AttendanceFragment$3.onClick(AttendanceFragment.java:183)
The bitmap images, coming from an arrayList of bytes[], which has 2 fingerprints arrays that are legit and work, cause I exported them .jpg in local android data app folder, where u can see them in device explorer, so the bytes[] arrays are good. U can check the pic down below (proof).
private void createPopupAttendanceScanFingerPrint(View view) throws IOException {
builder = new AlertDialog.Builder(view.getContext());
final View viewDialog = getLayoutInflater().inflate(R.layout.attendance_maker, null);
tvMessage = viewDialog.findViewById(R.id.tvMessage);
tvError = viewDialog.findViewById(R.id.tvError);
tvStatus = viewDialog.findViewById(R.id.tvStatus);
ivFinger = viewDialog.findViewById(R.id.ivFingerDisplay);
fingerPrintImageDisplay = viewDialog.findViewById(R.id.displayFingerPrintDB);
fingerPrintTextViewState = viewDialog.findViewById(R.id.fingerPrintMatchState);
buttonScan = viewDialog.findViewById(R.id.buttonScan);
buttonScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fingerprint.scan(viewDialog.getContext(), printHandler, updateHandler);
}
});
if (!bytesArrayList.isEmpty()) {
BitmapFactory.decodeByteArray(betterImageByteArray, 0,betterImageByteArray.length);
Bitmap bitmap = BitmapFactory.decodeByteArray(bytesArrayList.get(0), 0, bytesArrayList.get(0).length);
Bitmap bitmapDb = BitmapFactory.decodeByteArray(bytesArrayList.get(1), 0, bytesArrayList.get(1).length);
fingerPrintImageDisplay.setImageBitmap(bitmap);
double comparisionScore = compareFingerPrints(bitmap, bitmapDb);
Toast.makeText(view.getContext(), "Comparision score : " + comparisionScore, Toast.LENGTH_LONG).show();
fingerPrintTextViewState.setText("Attendance status");
} else {
Toast.makeText(view.getContext(), "Bytes not dehashed, byteArrayList empty", Toast.LENGTH_LONG).show();
}
builder.setView(viewDialog);
dialog = builder.create();
dialog.show();
}