OAID / TengineKit

TengineKit - Free, Fast, Easy, Real-Time Face Detection & Face Landmarks & Face Attributes & Hand Detection & Hand Landmarks & Body Detection & Body Landmarks & Iris Landmarks & Yolov5 SDK On Mobile.
Other
2.38k stars 318 forks source link

是否支持对bitmap检测人脸? #20

Closed fingdo closed 3 years ago

fingdo commented 3 years ago

代码如下 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

Crusoekid commented 3 years ago

里面有工具把bitmap转成byte[],你可以使用里面的工具

fingdo commented 3 years ago

试过了,也是无法检测出人脸,view bitmap是正常显示的

Crusoekid commented 3 years ago

工具返回图像时RGBA格式的, AndroidConfig.ImageFormat.RGBA

fingdo commented 3 years ago
        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()
        }

代码如上

Crusoekid commented 3 years ago
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[]