Closed fingdo closed 3 years ago
里面有工具把bitmap转成byte[],你可以使用里面的工具
试过了,也是无法检测出人脸,view bitmap是正常显示的
工具返回图像时RGBA格式的, AndroidConfig.ImageFormat.RGBA
val bmp = getBitmapByPath(filePath)
if (bmp != null && !bmp.isRecycled) {
KitCore.init(context, AndroidConfig
.create()
.setNormalMode()
.setDefaultFunc()
.setInputImageFormat(AndroidConfig.ImageFormat.RGBA)
.setInputImageSize(bmp.width, bmp.height)
.setOutputImageSize(bmp.width, bmp.height))
val detect = Face.detect(bitmap2Bytes(bmp))
bmp.recycle()
}
代码如上
static private byte[] getPixelsRGBA(Bitmap image) {
// calculate how many bytes our image consists of
int bytes = image.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes); // Create a new buffer
image.copyPixelsToBuffer(buffer); // Move the byte data to the buffer
byte[] temp = buffer.array(); // Get the underlying array containing the
return temp;
}
用这个转byte[]
代码如下 KitCore.init(context, AndroidConfig .create() .setNormalMode() .openFunc(AndroidConfig.Func.Detect) .openFunc(AndroidConfig.Func.Attribution) .setInputImageFormat(AndroidConfig.ImageFormat.RGB)); val detect = Face.detect(bitmap2RGBData(bmp))
或者每次都初始化 KitCore.init(context, AndroidConfig .create() .setNormalMode() .openFunc(AndroidConfig.Func.Detect) .openFunc(AndroidConfig.Func.Attribution) .setInputImageFormat(AndroidConfig.ImageFormat.RGB) .setInputImageSize(bmp.width,bmp.height) .setOutputImageSize(bmp.width,bmp.height)) val detect = Face.detect(bitmap2RGBData(bmp))
最终返回的faceCount都是0