我正在努力实现一篇研究论文中所述的内容。它描述了如何从图像中提取傅立叶特征。我试图在编码时遵循这些步骤,但是反复遇到与输入数组的数据类型和维度相关的错误。 所以我要问的是如何向函数输入复值
我遵循了研究论文中的以下指示
傅立叶描述子:傅立叶描述子提供了一种编码的方法 通过将每个像素位置(x,y)映射到 复数(x+iy)。
我的问题出现在第三步
这就是我的实现
def get_dft(image):
coordinates = cv.findNonZero(image)
# the code below removes an unnecessary dimension
coordinates = coordinates.reshape(coordinates.shape[0], 2)
y = coordinates[:, 1] * 1j # convert to complex numbers
# the code below removes an unnecessary dimension
y = y.reshape(coordinates.shape[0], 1)
x = coordinates[:, 0].reshape(coordinates.shape[0], 1)
# the statement below will convert from two separate arrays
# to a single array with each element
# of the form [a + jb]
t = x + y
# below is where the error occurs
dft = cv.dft(t, flags=cv.DFT_COMPLEX_INPUT)
这是我得到的错误
^{pr2}$当我转换为
a = numpy.ndarray(t)
我明白了
ValueError: sequence too large; cannot be greater than 32
它想说有超过32个维度。我不明白为什么会这样
当我试着
a = numpy.ndarray([t])
我知道错误了
TypeError: only integer scalar arrays can be converted to a scalar index
简而言之,我想按照文中提到的步骤,把复值向量
[[a+jb],[c+jd]...]
并传递给DFT函数。
我找到了解决问题的方法
我尝试了所有的numpy api,所有失败的原因我都不明白,但幸运的是OpenCV
^{pr2}$成功了。在
它需要多个输入数组和连接来实现多通道输出。在
我还试着在opencvapi函数中输入复数
这不是输入复数的正确方法。 OpenCV documentation explains complex input here
上面写着国旗,cv.DFT_复数输入在
注意,我还面临转换为双通道的问题,这是由于我没有正确理解作为函数输入所需的结构cv::UMat()。在
总结是,
如果要在OpenCV API函数中输入复数
您的输入必须由2个通道组成,要完成双通道阵列,OpenCV函数
^{pr2}$link to its documentation,当您尝试组合多个单独的频道时,似乎可以正确地完成任务。在
相关问题 更多 >
编程相关推荐