【问题标题】:OpenCV.js GaussianBlur function is not working?OpenCV.js GaussianBlur 函数不起作用?
【发布时间】:2019-12-10 16:34:14
【问题描述】:

我正在尝试使用 GaussianBlur 处理图像。

但我不能让它工作。它说:

Uncaught TypeError: fields[fieldName].write is not a function
    at Object.toWireType (opencv.js:30)
    at Object.GaussianBlur (eval at new_ (opencv.js:30), <anonymous>:9:26)
    at Object.proto.<computed> [as GaussianBlur] (opencv.js:30)
    at HTMLImageElement.img.onload (pen.js:110)

这里是代码笔:https://codepen.io/sundowatch/pen/jOEqrqY?editors=1010

我找不到问题所在。

【问题讨论】:

    标签: javascript opencv gaussianblur


    【解决方案1】:

    它对我有用,这是一个工作示例:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Hello OpenCV.js</title>
    </head>
    <body>
    <h2>Hello OpenCV.js</h2>
    <p id="status">OpenCV.js is loading...</p>
    <div>
      <div class="inputoutput">
        <img id="imageSrc" alt="No Image" />
        <div class="caption">imageSrc <input type="file" id="fileInput" name="file" /></div>
      </div>
      <div class="inputoutput">
        <canvas id="canvasOutput" ></canvas>
        <div class="caption">canvasOutput</div>
      </div>
    </div>
    <script type="text/javascript">
    let imgElement = document.getElementById('imageSrc');
    let inputElement = document.getElementById('fileInput');
    inputElement.addEventListener('change', (e) => {
      imgElement.src = URL.createObjectURL(e.target.files[0]);
    }, false);
    imgElement.onload = function() {
      let src = cv.imread(imgElement);
      let dst = new cv.Mat();
      let ksize = new cv.Size(5, 5);
      cv.GaussianBlur(src, dst, ksize, 0, 0, cv.BORDER_DEFAULT);
      cv.imshow('canvasOutput', dst);
      src.delete(); dst.delete();
    };
    function onOpenCvReady() {
      document.getElementById('status').innerHTML = 'OpenCV.js is ready.';
    }
    </script>
    <script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
    </body>
    </html>
    

    您的问题在其他地方。在您的 sn-p 上的开发人员工具中,如果我尝试获取 cv 元素,则会出现错误。你能仔细检查一下你正在加载 opencv.js &lt;script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"&gt;&lt;/script&gt;

    【讨论】:

    • 它也对我有用。我找不到问题所在
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 2018-11-14
    • 2021-12-17
    相关资源
    最近更新 更多