无法将C ++代码(具有OpenCV用法)编译为wasm [英] Unable to compile C++ code (having OpenCV usage) to wasm

查看:400
本文介绍了无法将C ++代码(具有OpenCV用法)编译为wasm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下C ++代码.这里是一些图像处理相关操作的OpenCV库.

I have the following C++ code. Here I am OpenCV library for some image processing-related operations.

#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <opencv/cv.hpp>

using namespace cv;
using namespace std;


int main()
{
    try
    {
        Mat frame, g_frame, r_frame; //, reduced_frame;
        int REDUCTION = 3;
        //--- INITIALIZE VIDEO_CAPTURE
        VideoCapture cap;

        // open selected camera using selected API
        cap.open(cv::CAP_DSHOW);
        // check if we succeeded
        if (!cap.isOpened()) {
            cerr << "ERROR! Unable to open camera\n";
            return -1;
        }

        //--- GRAB AND WRITE LOOP
        cout << "Start grabbing" << endl
             << "Press any key to terminate" << endl;

        // image_window win;
        while(true)
        {
            // wait for a new frame from camera and store it into 'frame'
            cap.read(frame);
            // check if we succeeded
            if (frame.empty()) {
                cerr << "ERROR! blank frame grabbed\n";
                break;
            }

            // flipping the image
            cv::flip(frame, frame, 1);
            cv::resize(frame, frame, cv::Size(), 2.0f, 2.0f, cv::INTER_CUBIC);

            // converting image to grey scale image
            cv::cvtColor(frame, g_frame, CV_BGR2GRAY);

            // reducing size of image
            cv::resize(g_frame, r_frame, cv::Size(), 1.0/REDUCTION, 1.0/REDUCTION, cv::INTER_CUBIC);

            cv::imshow("Live", frame);
            if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC
        }

    }
    catch (exception& e)
    {
        cout << "\nexception thrown!" << endl;
        cout << e.what() << endl;
    }
    return 0;
}

当我尝试使用以下命令将此代码编译为wasm时:

when I am trying to compile this code to wasm using the following command:

emcc -msse3 -msimd128 -std=c++11 -O3 -I ../opencv/build/include main.cpp -lpthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s TOTAL_MEMORY=1024MB -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s WASM=1 -o main.js

然后我遇到以下错误:

error: undefined symbol: _ZN2cv12VideoCapture4openEi (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN2cv12VideoCapture4openEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCapture4readERKNS_12_OutputArrayE (referenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCapture4readERKNS_12_OutputArrayE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCaptureC1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCaptureC1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv12VideoCaptureD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN2cv12VideoCaptureD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv3Mat10deallocateEv (referenced by top-level compiled C/C++ code)
warning: __ZN2cv3Mat10deallocateEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv4flipERKNS_11_InputArrayERKNS_12_OutputArrayEi (referenced by top-level compiled C/C++ code)
warning: __ZN2cv4flipERKNS_11_InputArrayERKNS_12_OutputArrayEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6String10deallocateEv (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6String10deallocateEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6String8allocateEm (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6String8allocateEm may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6imshowERKNS_6StringERKNS_11_InputArrayE (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6imshowERKNS_6StringERKNS_11_InputArrayE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi (referenced by top-level compiled C/C++ code)
warning: __ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv7waitKeyEi (referenced by top-level compiled C/C++ code)
warning: __ZN2cv7waitKeyEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii (referenced by top-level compiled C/C++ code)
warning: __ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN2cv8fastFreeEPv (referenced by top-level compiled C/C++ code)
warning: __ZN2cv8fastFreeEPv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZNK2cv12VideoCapture8isOpenedEv (referenced by top-level compiled C/C++ code)
warning: __ZNK2cv12VideoCapture8isOpenedEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: 'C:/emsdk/node/12.18.1_64bit/bin/node.exe C:\emsdk\upstream\emscripten\src\compiler.js C:\Users\Nitin\AppData\Local\Temp\tmppq_ad1ya.txt' failed (1)

请帮助我.

上述问题是通过使用错误本身提供的建议来解决的.

The above problem is solved by using the suggestions provided in the error itself.

emcc -msse3 -msimd128 -std=c++11 -O3 -I ../opencv/build/include main.cpp -lpthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s TOTAL_MEMORY=1024MB -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s WASM=1 -s LLD_REPORT_UNDEFINED -s ERROR_ON_UNDEFINED_SYMBOLS=0 -o main.html

但是,在浏览器中打开main.html文件时.我现在收到以下错误.

However, while opening the main.html file in the browser. I am now getting the following error.

CompileError: WebAssembly.instantiate(): Compiling function #607 failed: invalid value type 'Simd128', enable with --experimental-wasm-simd @+105826

请帮助我解决这个问题.

Please help me in solving this.

推荐答案

您必须使用-experimental-wasm-simd 选项运行浏览器,因为SIMD不属于Webassembly规范(尚未).

You have to run your browser with the option --experimental-wasm-simd, as SIMD isn't a part of the webassembly spec (yet).

这篇关于无法将C ++代码(具有OpenCV用法)编译为wasm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆