The context is that I have an html/js/canvas webpage reading a jpg file furnished by the user and sending the file to a c++/wasm function. (everything in the browser)
On the c++ part I have a function like this one:
void readBlob(std::string textBlog)
{
std::cout << textBlob << std::endl;
}
That one works well : I see in the browser console the content of the jpg
file.
My question are :
- how to "read" this
std::string
to create an opencv image ? - Is there any hope to succeed without recompiling the jpg support for OpenCV and then a load of third parties ?
I've tried that one :
writeInFile(textBlob, "image.jpg");
cv::Mat image = cv::imread("image.jpg")
where writeInFile
is a function which writes on the disk (wasm has its own virtual filesystem).
The problem with that approach is that cv::imread
causes "undefined symbol" when linking (I think that I compiled opencv to wasm without codecs or something).
I'm not really good at understanding the differences between char*, buffers and all that. So I'm not sure how to use cv::imdecode
from a std::string
.
EDIT : here is how I encode the image into std::string
.
In the javascript part, I draw the image in a canvas and do:
canvas.toBlob(manageBlob, 'image/jpeg', 1)
where manageBlob
is the following:
function manageBlob(blob)
{
const blobText = await new Response(blob).text();
Module["readBlob"](blobText);
}
Here Module["readBlob"]
is the wasm "magics" to send the js string blobText
to the c++ function whose signature is std::string
.