imencode in opencv.js

asked 2020-03-04 11:34:48 -0600

sine gravatar image

updated 2020-03-04 12:33:10 -0600

Hello everyone, I'm trying to extract the bounding rectangles recognised through the analysis of a VideoCapture stream, This code works great and I can draw the clip to a canvas dom object on screen:

 let rect = candidates[i]
 let rectangleFailColor = [0, 0, 255, 255]
 let rectangleOKColor = [0, 255, 0, 255]
 let point1 = new cv.Point(rect.x, rect.y);
 let point2 = new cv.Point(rect.x + rect.width, rect.y + rect.height);
 cv.rectangle(src, point1, point2,  rectangleOKColor, 2, cv.LINE_AA, 0);
 let cut_dst = src.roi(rect);
 let caca = cv.imencode('jpg',cut_dst,buff)

However, what I really want is to use the "cut_dst" clip and turn it into a base64 string. I could do it in the DOM object but as this is a video stream processing, performance is important and using a DOM object is pretty performance demanding as I extract a lot of rectangles for every frame.

Hance, I've tried imencode since it's available in js, but I'm unable to find the data type to use for my target object. Instead I get the following error: ""Cannot call imencode due to unbound types: NSt3__26vectorIhNS_9allocatorIhEEEE""

Looking into the official documentation, it seems to require a "Output buffer resized to fit the compressed image" but I have no clue as to how to instantiate such object in javascript. Hence I come to you seeking for wisdom as I've spent a good week looking for a solution and failed miserably.

Thanks a lot in advance

PS:

This is the current workaround:

let tempCanvas = document.createElement("canvas");
cv.imshow(tempCanvas,cut_dst)
let b64image = tempCanvas.toDataURL()
console.log(b64image)
edit retag flag offensive close merge delete

Comments

I've tried imencode since it's available in js,

where do you see that ?

berak gravatar imageberak ( 2020-03-06 05:57:13 -0600 )edit

I assumed it in the fact that I can call it

sine gravatar imagesine ( 2020-03-08 18:06:51 -0600 )edit