我有一个关于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()函数来生成的。因此,两个输入图像的数据类型都是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发布于 2017-04-28 02:40:23
您必须将图像作为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)发布于 2017-04-28 03:09:14
来自文档:http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#phase
相位计算二维矢量的旋转角度。
C++:空相( InputArray x,InputArray y,OutputArray angle,bool angleInDegrees=false)
Python: cv2.phase(x,y[,→,angleInDegrees])角度
参数:
二维矢量x坐标的x输入**floating-point array**。
二维向量的y坐标的y输入数组;它必须与x具有相同的大小和类型。
angle输出向量角度的数组;它与x具有相同的大小和**same type**。
angleInDegrees -如果为true,则函数以度为单位计算角度;否则,以弧度为单位测量角度。
https://stackoverflow.com/questions/43665106
复制相似问题