bytedeco/javacv

Passing OpenCV Mat as Tensorflow input

Open

#2,220 建立於 2024年4月23日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)Java (1,583 fork)batch import
help wantedquestion

倉庫指標

Star
 (6,985 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Firstly, thanks for a great project, it's fun to work with!

I have an org.bytedeco.opencv.opencv_core.Mat object that I have prepared into the correct shape, format & scaling to pass to a tensorflow lite model. I'm having trouble populating the model input tensor correctly.

Mat image = ...; // 300 x 300 x 3 channels, depth=32
FloatPointer input = interpreter.typed_input_tensor_float(0);

I've got it working by iterating over the rows and cols of the image and copying the image pixels one by one into a float[] and calling input.put() on the float array. However, that seems inefficient, and I was hoping that I could do something like input.put(image), but that isn't working, or at least the model outputs aren't correct.

Could you give me any pointers (!) on how to efficiently copy/pass the Mat as a tensorflow input?

Thanks in advance.

貢獻者指南