【问题标题】:Interpreting results of the cv2 method: phaseCorrelate? | python opencv解释 cv2 方法的结果:phaseCorrelate? | python opencv
【发布时间】:2019-08-23 22:42:13
【问题描述】:

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

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

非常感谢任何和所有的帮助,在此先感谢您。


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)


【问题讨论】:

    标签: python opencv computer-vision


    【解决方案1】:

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

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

    【讨论】:

    • 你好,埃萨里。这是一个很好的答案,我非常感谢您的反馈。我一定会参考文档。谢谢!
    • 嗨,有时我得到的响应值大于 1,尽管在文档中说最大值是 1。当值大于 1 时,你知道如何解释它吗?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多