cvMat, cvImage and cvRect serialization
erenaud3 opened this issue · 9 comments
Hi !
Is it possible to serialize variables of type cvMat, cvImage or cvRect ?
I'm currently trying to design a system with several NodeJs programs where one master is performing facial detection while some slaves receive frames in order to perform further processing (landmarks, facial recognition,...).
Thanks for your help !
What is the application for?
I presume that you want to detect faces from stream or videos?
Yeah sorry I didn't precise it.
You're absolutely right, the goal is to detect (and later recognize) faces from a webcam stream.
For the moment, I'm using a folder when I am saving the frames I want my workers to work on. But it doesn't seem to be the best approached.
Using a folder, like by fs?
Using a folder, like by fs?
Exactly
const cv = require('opencv4nodejs')
const fr = require("face-recognition").withCv(cv)
function extractFace(htmlImageSrc) {
let result = null
const base64data = htmlImageSrc.replace('data:image/jpeg;base64', '')
.replace('data:image/png;base64', '')
const buffer = Buffer.from(base64data, 'base64')
const mat = cv.imdecode(buffer)
const cvImage = fr.CvImage(mat)
const frImage = fr.cvImageToImageRGB(cvImage)
const facesExtracted = this.detectFace(frImage)
if (facesExtracted) {
fr.saveImage(Models/image/${image.name}.png
, facesExtracted.toGray())
result = facesExtracted
}
return result
}
Not sure if this is what your looking for though.
Thank you for your help !
const base64data = image.src.replace('data:image/jpegbase64', '')
This line seems strange to me though. What is the type of "image" ? cvImage ?
It's not working for me with my image variable, which I'm getting like this :
cap = new cv.VideoCapture(videoDeviceId);
(...)
image = cap.read();
EDIT: By "not working", I mean that image.src is undefined.
@erenaud3 Oh, it was my stuff. You can just remove the ".src" part,
the only thing matters is to make variable base64data stores the base64 image data.
Not sure if this is what your looking for though.
In deed, it's a good start but the problem is I don't know how to get the base64 text from my cvImage.
Okay so there's one thing I failed to understand at first: what I'm getting with capture.read() is a cvMat and not a cvImage. Which led me to the functions i was looking for:
cv.imencode() and cv.imdecode()
But now I have a problem with those functions as well. I am opening a new issue.