Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fingdo opened this issue Dec 4, 2020 · 5 comments
Closed

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

fingdo opened this issue Dec 4, 2020 · 5 comments

Comments

@fingdo
Copy link

fingdo commented Dec 4, 2020

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

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

@fingdo
Copy link
Author

fingdo commented Dec 7, 2020

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

@Crusoekid
Copy link
Collaborator

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

@fingdo
Copy link
Author

fingdo commented Dec 7, 2020

        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
Copy link
Collaborator

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[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants