Toybrick

标题: Android下Bitmap如何转换为 ImageBufferQueue.ImageBuffer [打印本页]

作者: JackXu9527    时间: 2020-7-23 23:05
标题: Android下Bitmap如何转换为 ImageBufferQueue.ImageBuffer
本帖最后由 JackXu9527 于 2020-7-23 23:07 编辑

在Android下我从视频文件中获得了视频帧bitmap图像,我现在如何才能将bitmap(或者是ByteBuffer)转化为SDK的图像队列中ImageBuffer格式(如下示)然后送给npu识别呢?这个问题困扰了我好多天,请大佬指点一下,万分感谢                           

public class ImageBuffer {
    static public final int STATUS_INVAILD = 0;
    static public final int STATUS_READY = 1;
    static public final int STATUS_USING = 2;

    public int mTextureId;  //textureId
public int mFramebuffer;
    public int mStatus;
    public int mWidth;
    public int mHeight;

    public ImageBuffer(int width, int height) {
        mStatus = STATUS_INVAILD;
        mWidth = width;
        mHeight = height;
        mTextureId = -1;
        prepareFrameBuffer(width, height);
    }

    public void finalize() {
        if (mTextureId >= 0) {
            int[] values = new int[1];
            values[0] = mFramebuffer;
            glDeleteFramebuffers(1, values, 0);
            InferenceWrapper.delete_direct_texture(mTextureId);
        }
    }

    private void prepareFrameBuffer(int width, int height) {
        int[] values = new int[1];

        mTextureId = InferenceWrapper.create_direct_texture(width, height, GL_RGB);

        glBindTexture(GL_TEXTURE_2D, mTextureId);

        // Set parameters.  We're probably using non-power-of-two dimensions, so
        // some values may not be available for use.
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                GL_NEAREST);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                GL_CLAMP_TO_EDGE);
        // Create framebuffer object and bind it.
glGenFramebuffers(1, values, 0);
        mFramebuffer = values[0];    // expected > 0
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);

        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                GL_TEXTURE_2D, mTextureId, 0);

        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
            throw new IllegalStateException();
        }

        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }
}







欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3