gpt4 book ai didi

javascript - OpenCV.js GaussianBlur 函数不起作用?

转载 作者:行者123 更新时间:2023-12-01 00:22:54 24 4
gpt4 key购买 nike

我正在尝试使用 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

我找不到问题所在。

最佳答案

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

<!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>

您的问题出在其他地方。在您的代码片段的开发人员工具中,如果我尝试获取 cv 元素,则会收到错误。您能否仔细检查您是否正在加载 opencv.js <script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>

关于javascript - OpenCV.js GaussianBlur 函数不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59271753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com