[英]OpenCV.js GaussianBlur function is not working?
I'm trying to process image with GaussianBlur.我正在尝试使用 GaussianBlur 处理图像。
But I can't make it work.但我不能让它工作。 It says:它说:
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)
Here is codepen: https://codepen.io/sundowatch/pen/jOEqrqY?editors=1010这是代码笔: https ://codepen.io/sundowatch/pen/jOEqrqY ? editors = 1010
I can't find what is the problem with that.我找不到这有什么问题。
It works for me, here is a working example:它对我有用,这是一个工作示例:
<!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>
Your problem is elsewhere.你的问题在别处。 In developer tools on your snippet if I try to get the cv element I get an error.在代码片段的开发人员工具中,如果我尝试获取 cv 元素,则会出现错误。 Can you double check that you are loading opencv.js <script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
你能仔细检查一下你正在加载 opencv.js <script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
<script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.