Best way to convert an Image buffer Uint8List
to cv.Mat
#18
Replies: 2 comments 16 replies
-
UPDATE 2024.8.30:Since v1.2.0, the recommended ways are Mat.fromVec and Mat.fromList Original:If I'm not mistaken, the But if the // 2D or 3D raw pix values
final data = ...;
final int rows = ...;
final int cols = ...;
final m = cv.Mat.create(rows, cols, type);
for (int i = 0; i < rows; i++){
for (int j = 0; j < rows; j++){
m.setValue<int>(i, j, data[i][j]);
}
} So, I think the best way is cv.imdecode(), please point it out if I'm wrong. |
Beta Was this translation helpful? Give feedback.
-
@TheoNanu Sorry for the late reply, I am kind of busy recently. I havn't used the camera plugin so not familiar with it, but I will try to provide a camera interaction example in awesome-opencv_dart when having some time, you can also open a PR to https://github.com/rainyl/awesome-opencv_dart if you solved it. Also, although not recommended, you can use the videoio module from opencv too, which alows opening a |
Beta Was this translation helpful? Give feedback.
-
Typically we can access raw image data from other library as an
Uint8List
object. Assuming we know the format of the image (e.g. RGB uint8), what is the best (fast and convenient) way to convert it to OpenCVMat
? Some of the approaches I am thinking of:Mat
with the required size. Iterate overUint8List
and copy data over. For some formats like YUV_420sp, it might be a bit tricky to copy the data correctly.cv.imdecode()
-> seems to be the most convenient, but there is overhead in compression-decompression.Mat
from C pointer. Need to release the memory after use.Beta Was this translation helpful? Give feedback.
All reactions