简体   繁体   English

如何使OpenCV(JavaScript版)在Internet Explorer 11上运行?

[英]How to get OpenCV (javascript edition) working on Internet Explorer 11?

I'm trying to get OpenCV javascript version working on IE11 for contour detection. 我正在尝试在IE11上使用OpenCV javascript版本进行轮廓检测。 My code works on every other modern browser, but I'm getting errors like: 我的代码可在所有其他现代浏览器上使用,但出现以下错误:

TypeError: Object doesn't support this action

The line of code of the OpenCV library where I'm getting this error is: 我收到此错误的OpenCV库的代码行是:

var imgData=new ImageData(new Uint8ClampedArray(img.data),img.cols,img.rows);

So it seems IE11 doesn't support that syntax. 因此,似乎IE11不支持该语法。 I've been trying to find some polyfill to make it work, but no luck for now. 我一直在尝试找到一些polyfill来使它工作,但目前还没有运气。

So anyone knows how to make this work on IE11? 因此,有人知道如何在IE11上实现这项功能吗?

Thanks. 谢谢。

IE Browser not support the ImageData() constructor , you could try to use the CanvasRenderingContext2D.createImageData() method to create the ImageData object . IE浏览器不支持ImageData()构造函数 ,您可以尝试使用CanvasRenderingContext2D.createImageData()方法创建ImageData对象。

Code like this: 像这样的代码:

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

const imageData = ctx.createImageData(100, 50);
console.log(imageData);
// ImageData { width: 100, height: 50, data: Uint8ClampedArray[20000] }

I ended up using a polyfill for this one and now it works with IE11. 我最终为此使用了一个polyfill,现在它可以与IE11一起使用。

I did some changes for my particular use case, but this gist is the following: 我针对特定的用例做了一些更改,但是要点如下:

https://gist.github.com/Convicted202/7684bc8113b3011b4a6a1b2aa9f7a36f https://gist.github.com/Convicted202/7684bc8113b3011b4a6a1b2aa9f7a36f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM