Skip to content

JavaCV Mat to Byfebuffer #1

@akshyasingh-mset

Description

@akshyasingh-mset

hi @MrKnyaz, I am trying to run a custom model which expects input image shape to be : float32[1,3,320,320] and i am converting JavaCV mat to bytebuffer using following code

Mat floatMat = new Mat();
resized.convertTo(floatMat, opencv_core.CV_32FC3);
FloatBuffer floatBuffer = floatMat.createBuffer();
float[] floatArray = new float[floatBuffer.capacity()];
floatBuffer.get(floatArray);

ByteBuffer byteBufferInverted = ByteBuffer.allocateDirect(floatArray.length*4);
byteBufferInverted.order(ByteOrder.nativeOrder());
byteBufferInverted.asFloatBuffer().put(floatArray);
Object[] inputs = new Object[]{byteBufferInverted};
Map<Integer, Object> outputMapOcrCraft = new HashMap<>();
outputMapOcrCraft.put(0, outputOcrCraftY);
outputMapOcrCraft.put(1, outputOcrCraftFeature);
ocrCraftTflite.runForMultipleInputsOutputs(inputs, outputMapOcrCraft);

I am getting the wrong output as floatMat shape is [320,320,3]. I am stuck in how to convert [320,320,3] to [3,320,320], how to achieve the above mentioned?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions