How to send OpenCV JS Mat data to server

Viewed 18

I'm currently working with OpenCV JS to do some video processing from the browser. The processing involves contour approximation. After approximation, the result is stored in a Mat object. I've added a code snippet for reference:

let perimeter = cv.arcLength(biggestContour, true);
let perimeter_approx= new cv.Mat();
cv.approxPolyDP(biggestContour, perimeter_approx, 0.01 * perimeter, true);
console.log(perimeter_approx) // an opencv Mat object

perimeter_approx is a Mat object with 4 rows and 1 column (along with a bunch of other attributes I don't understand). Below is what the console log looks like:

Mat {$$: {…}}
$$: {ptrType: RegisteredPointer, ptr: 6573800, count: {…}}
cols: 1
data: Uint8Array(32)
data8S: Int8Array(32)
data16S: Int16Array(16)
data16U: Uint16Array(16)
data32F: Float32Array(8)
data32S: Int32Array(8)
data64F: Float64Array(4)
matSize: Array(2)
rows: 4
step: Array(2)
[[Prototype]]: ClassHandle

What I'm trying to do is to send a frame (a video frame) and this perimeter_approx data to my flask server so that I can continue processing in python.

The python version of this approximation returns a numpy array with shape (4, 2) containing points (x, y) returned from the approximation. What I need are these points but I can't interpret the data stored in the Mat object. Any help would be appreciated. Thank you.

0 Answers
Related