Closed michealChin closed 1 year ago
@michealChin Could you try using the abs
function in BitmapUtils.kt
like,
fun cropRectFromBitmap(source: Bitmap, rect: Rect ): Bitmap {
var width = rect.width()
var height = rect.height()
rect.left = if( rect.left > 0 ) rect.left else 0
rect.top = if( rect.top > 0 ) rect.top else 0
if ( (rect.left + width) > source.width ){
width = abs( source.width - rect.left )
}
if ( (rect.top + height ) > source.height ){
height = abs( source.height - rect.top )
}
val croppedBitmap = Bitmap.createBitmap( source , rect.left , rect.top , width , height )
// Uncomment the below line if you want to save the input image.
// BitmapUtils.saveBitmap( context , croppedBitmap , "source" )
return croppedBitmap
}
I call cropRectFromBitmap and pass in the image that located in the image folder and simply choose the Rect (0,0,100,100) and it successfully return me a crop bitmap without any exception. However Is this related to the apps crash with the error message I share in the post?
In some cases, source.width
< rect.left
which produces a negative number to be stored in width
.
I got two folder actually, each folder with one image. I remove one of the folder and the apps no longer crash, may I know what is the specification for the bitmap to be read correctly by this project? Image Size (width and height)? Image Type?
Another question, you mention that Facenet is not very accurate, but according to https://paperswithcode.com/sota/face-verification-on-labeled-faces-in-the Facenet rank number 2 with 99.63% accuracy.
Anyway, you did a great job! Really appreciate your effort!
@michealChin There is no such specification on the input images. If the images have their natural orientation, you are good to go. Image resizing and parsing are handled by the app, so you need not worry for that. Also, every ML model is prone to errors, hence it is important to mention that inaccuracies may be observed.
@michealChin There is no such specification on the input images. If the images have their natural orientation, you are good to go. Image resizing and parsing are handled by the app, so you need not worry for that. Also, every ML model is prone to errors, hence it is important to mention that inaccuracies may be observed.
Great! I will spend some time to play around with the code. Have a nice day!
Hi,
I try to build the project and debug it after press USE THIS FOLDER button, suddenly the apps crash and here is the error message
` detectFacesImageByteArray.start() Access denied finding property "ro.mediatek.platform" detectFacesImageByteArray.end() FATAL EXCEPTION: main Process: com.ml.quaterion.facenetdetection, PID: 5566 java.lang.IllegalArgumentException: x must be >= 0 at android.graphics.Bitmap.checkXYSign(Bitmap.java:432) at android.graphics.Bitmap.createBitmap(Bitmap.java:862) at android.graphics.Bitmap.createBitmap(Bitmap.java:825) at com.ml.quaterion.facenetdetection.BitmapUtils$Companion.cropRectFromBitmap(BitmapUtils.kt:46) at com.ml.quaterion.facenetdetection.FileReader$getEmbedding$2.invokeSuspend(FileReader.kt:109) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@4a30289, Dispatchers.Main]
Please help!