python 'Assertion Error (depth == CV_32F || depth == CV_64F)'

标签 python opencv assertion phase

cv2.phase() 函数有问题。我编写了以下代码:

img = cv2.imread("1.jpg", 0)
cv2.imshow("image", img)

img_dx = cv2.Sobel(img, cv2.CV_8U, 1, 0)
img_dy = cv2.Sobel(img, cv2.CV_8U, 0, 1)
angles = cv2.phase(img_dy, img_dx)

并且在调用 cv2.phase() 时返回断言错误。相位函数的两个输入图像都是通过使用相同的输入图像调用 cv2.sobel() 函数生成的。所以两个输入图像的 dtype 都是 uint8 并且它们具有相同的大小。所以我不明白为什么我会收到断言错误。

我得到的完整错误信息是:

OpenCV Error: Assertion failed (src1.size() == src2.size() && type == src2.type() && (depth == CV_32F || depth == CV_64F)) in cv::phase, file ..\..\..\modules\core\src\mathfuncs.cpp, line 209

最佳答案

您必须将图像作为 float 变量传递以查找 Sobel 边缘。因此,将您的代码更改为以下内容:

img_dx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
img_dy = cv2.Sobel(img, cv2.CV_32F, 0, 1)

现在你应该能够找到相位...

弧度为单位的相位:

OpenCV 默认以弧度为单位查找相位:

phase = cv2.phase(sobelx, sobely)

度数阶段:

要指定您想要以度为单位的相位,您必须设置标志 angleInDegrees = True,如下所示:

phase = cv2.phase(sobelx, sobely, angleInDegrees = True)

关于 python 'Assertion Error (depth == CV_32F || depth == CV_64F)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43665106/

相关文章:

python - 同时使用多个双绞线套接字服务器

python - 如何删除类似的 alembic 版本?

Android OpenCV 2.4.9 静态初始化不像示例 APK 那样工作

web-services - 如何在 JMeter bean shell 断言中打印变量的值

python - 如何从 Pandas 数据框中获取 key

python - 使用 Qt 样式表更改状态更改时的图标

python - OpenCV 不会画圆 - Python

c++ - OpenCV2.4 从视频中捕获帧可能存在的错误

c++ - 如何在 constexpr 函数中执行运行时断言?

c++ - 在 C++ 中使用 sprintf 调试断言失败