收藏
回答

小程序编译后的opencv.js和opencv_js.wasm.br需要改什么才能用?

我把WebAssembly改成了WXWebAssembly,onRuntimeInitialized没有被触发。

const cv = require('../../opencv/opencv.js');

onLoad: async function (options) {

    var _that = this

    console.log(1);

    cv['onRuntimeInitialized'= () => {

      console.log(3);

      _that.imread(_that.data.src).then(res => {

        _that.imshow("src", res)

      })

      _that.removeBg()

    };

    console.log(2);

  },



function instantiateArrayBuffer(receiver) {

                    return getBinaryPromise()

                        .then(function (binary) {

                            //return WXWebAssembly.instantiate(binary, info);

                            return WXWebAssembly.instantiate(

                                "/opencv/opencv_js.wasm.br",

                                info

                              );

                        })

                        .then(receiver, function (reason) {

                            err(

                                "failed to asynchronously prepare wasm: " +

                                    reason

                            );

                            abort(reason);

                        });

                }




instantiateAsync方法:

var result = WXWebAssembly.instantiate(

                            "/opencv/opencv_js.wasm.br",

                            info

                        );

                        return result.then(

                            receiveInstantiatedSource,

                            function (reason) {

                                err("wasm streaming compile failed: " + reason);

                                err(

                                    "falling back to ArrayBuffer instantiation"

                                );

                                return instantiateArrayBuffer(

                                    receiveInstantiatedSource

                                );

                            }

                        );


回答关注问题邀请回答
收藏
登录 后发表内容