Hey! I’ve been trying to convert Mat to bitmap but it’s not working.
I’m using the OpenCV’s Utils class to convert it to mat.
fun detectPerson(img: Bitmap, folderName: String) {
val frame = Mat()
val originalMat = Mat()
Utils.bitmapToMat(img, originalMat)
Utils.bitmapToMat(img, frame)
Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2RGB)
val blob = Dnn.blobFromImage(
frame,
0.00392,
Size(416.0, 416.0),
Scalar(0.0, 0.0, 0.0),/*swapRB*/
true, /*crop*/
false
)
writeToFileWithName("blob-file",convertMatToBitMap(blob)!!)
}
private fun convertMatToBitMap(input: Mat): Bitmap? {
var bmp: Bitmap? = null
val rgb = Mat()
// Imgproc.cvtColor(input, rgb, Imgproc.COLOR_BGR2RGB)
try {
bmp = Bitmap.createBitmap(rgb.cols(), rgb.rows(), Bitmap.Config.ARGB_8888)
Utils.matToBitmap(rgb, bmp)
} catch (e: CvException) {
e.printStackTrace()
}
return bmp
}
error received is this
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:1060)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1027)
at android.graphics.Bitmap.createBitmap(Bitmap.java:977)
at android.graphics.Bitmap.createBitmap(Bitmap.java:938)
at com.buttonwillow.app.views.main.camera.SeatBeltDemoActivity.convertMatToBitMap