python - cv2 方法的解释结果 : phaseCorrelate? | python

标签 python opencv computer-vision

我写了一个简单的脚本,它返回两个图像之间的相位相关性。为此,我调用了 cv2 方法:cv2.phaseCorrelate

我知道它返回两个图像之间的亚像素相移,但是,我不清楚返回对象的每个组件的具体细节(方法返回一个包含元组和 float 的列表)。

非常感谢任何帮助,提前致谢。


import cv2
import math
import time
import numpy as np

class CorrelationCalculator(object):
    'TODO: class description'

    version = '0.1'

    def __init__(self, initial_frame, detection_threshold=4):
        self.initial_frame = np.float32(cv2.cvtColor(initial_frame, cv2.COLOR_BGR2GRAY))
        self.detection_threshold = detection_threshold

    def detect_phase_shift(self, current_frame):    
        'returns detected sub-pixel phase shift between two arrays'
        self.current_frame = np.float32(cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY))
        shift = cv2.phaseCorrelate(self.initial_frame, self.current_frame)
        return shift

# implementation

import cv2

img = cv2.imread('img1.jpg')
img2 = cv2.imread('img2.jpg')

obj = CorrelationCalculator(img)
shift = obj.detect_phase_shift(img2)

print(str(shift)

输出:

((4.3597901057868285, -2.8767423065464186), 0.4815432178477446)


最佳答案

返回的第一个元组告诉您 imgimg2 在 x 和 y 坐标中的偏移量。例如,请考虑下面的两张图片。

Source Image Target Image

这个方法应该找到矩形的像素值偏移。其他值显示我们从相位相关过程中获得的响应值。您可能认为它是计算确定性的衡量标准。您可以在 OpenCv documentation 上找到详细信息在 phaseCorrelate 标题下。

关于python - cv2 方法的解释结果 : phaseCorrelate? | python ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57626656/

相关文章:

python - numpy 数组中的二维矩阵如何定义轴?

python - 将时间戳转换为 Pandas 中的自定义周期之一

python - Mypy 提示 __setitem__ 签名

linux - arm-linux 下缺少 libopencv_ts 缺失

python - 从OpenCV中的图像定位和提取(未知)书籍

python - Tkinter 文本不显示

java - 如何从 mat 对象获取整数数组,反之亦然

python - 如何找到颜色 "Upper"和 "Lower"范围内的颜色?

OpenCV : FREAK Descriptor arguments

machine-learning - 二进制数而不是一个热向量