opencv - 如何使用 opencv.js 中的 cv.goodFeaturesToTrack?

标签 opencv

我正在尝试的代码:

let src = cv.imread('inputImage');  // read from <img id="inputImage" />
let temp = new cv.Mat();
src.convertTo(temp, cv.CV_32FC1);  // cv.CV_32FC1 === 5

let features = new cv.Mat();
cv.goodFeaturesToTrack(temp, features, 500, 0.01, 10); // These numbers are arbitrary.
我在浏览器控制台上:
OpenCV Error: Assertion failed (src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) || src.type() == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3))) in cornerEigenValsVecs, file /build/master-contrib_docs-lin64/opencv/modules/imgproc/src/corner.cpp, line 269 opencv.js:21:3644

Uncaught 6384400 - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch. opencv.js:21:1597503
(((0) & ((1 << 3) - 1)) + (((1)-1) << 3))
-> 0
cv.CV_8U
-> 0
(((5) & ((1 << 3) - 1)) + (((1)-1) << 3))
-> 5
cv.CV_32F
-> 5
cv.CV_32FC1
-> 5
cv.CV_8UC1
-> 0
使用 convertTo() 或使用 cv.cvtColor() 时是否转换到另一个 channel ?

最佳答案

输入 goodFeaturesToTrack should be an 8-bit or 32-bit single channel image .看来您实际上是在传递 3 channel 图像;问题是 convertTo可用于更改位深度,但不能更改 channel 数 -- see documentation here .
我建议这样做:

cv.cvtColor(src, src, cv.COLOR_BGR2GRAY); // convert to 1-channel
let features = new cv.Mat();
cv.goodFeaturesToTrack(src, features, 500, 0.01, 10);
换句话说,convertTo call 可以完全省略。

关于opencv - 如何使用 opencv.js 中的 cv.goodFeaturesToTrack?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62726710/

相关文章:

c++ - 在opencv c++函数中查找凸缺陷点

c++ - 城市环境特征检测的最佳算法——OpenCV

通过未知类型的 Mat 进行 OpenCV 索引

opencv - 如何将 'extended' 选项用于 Surf 算法

c++ - OpenCV——如何优化颜色跟踪程序?

opencv - OpenCV C++ 中跟踪对象的背景减法和光流

python - 如何播放wav文件,并使您的代码继续在python中运行?

opencv - 架构 arm64 的 undefined symbol :cv::StereoMatcher::compute

python - 在 Ubuntu 15.04 中使用 Python3 安装 opencv-python

python - 如何从opencv中的图像中删除多余的空格?