Closed DavDag closed 2 weeks ago
Hi @DavDag, thanks for this issue. There was a gap in the library related to the inability to convert to selected types. In v.0.2.12
I've added more types in matToBuffer
function, this is a definition:
matToBuffer<T extends keyof BufferType>(
mat: Mat,
type: T
): {
cols: number;
rows: number;
channels: number;
buffer: BufferType[T];
};
where BufferType is:
type BufferType = {
uint8: Uint8Array;
uint16: Uint16Array;
uint32: Uint32Array;
int8: Int8Array;
int16: Int16Array;
int32: Int32Array;
float32: Float32Array;
float64: Float64Array;
};
So for example, for your case, when you want to get stats data (which is CV_32S Mat) you need to convert it to 32-bit signed value:
const statsData = OpenCV.matToBuffer(stats, 'int32');
The result will be in Int32Array
type.
Similar for centroids
(which is CV_64F), it will be 64-bit floating value, and the result will be in Float64Array
type:
const statsData = OpenCV.matToBuffer(centroids, 'float64');
Hi @lukaszkurantdev, thank you very much! I'll try it asap and close the issue. Thanks again for the speed, really appreciate your efforts 🚀
It works like magic! Thanks again!
Hi :)
How can I access the result of
connectedComponentsWithStats
?Here's the code (that do not work):
I get:
If I try using the other conversion (uint8):
I get wrong results:
The same goes for extracting centroids. Am I missing something? Thanks!