emscripten-opencv icon indicating copy to clipboard operation
emscripten-opencv copied to clipboard

How to use imencode and return image as string?

Open mostafafarzaneh opened this issue 3 years ago • 0 comments

Hey @Jonathan, This repo is exactly what I need. Without it, It would be really hard to do my project.

I get the image from JS and do some processing on it and return it to JS as you did in the project. Everything works fine.

But since the JS side does not need to show the image and wants to just send it, I thought that it would be more efficient if I can encode the image and return the image to JS as a string so JS won't need to do so. I tried to encode Mat using imencode In my C++ code, which received the following error:

error: undefined symbol: _ZN2cv8imencodeERKNSt3__212basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS_11_InputArrayERNS0_6vectorIhNS4_IhEEEERKNSC_IiNS4_IiEEEE (referenced by top-level compiled C/C++ code)

I know that it is because the project is not linked with imgcodec. So I edit the opencv/platforms/js/build_js.py file and add -DBUILD_opencv_imgcodecs=ON to it and recompile OpenCV. But still, It does not build imgcodec library.

Do you have any idea how I can build OpenCV with imgcodec?

mostafafarzaneh avatar Dec 24 '21 07:12 mostafafarzaneh