I have written a simple script which returns the phase correlation between two images. To achieve this I call the cv2 method: cv2.phaseCorrelate
I understand that it returns the sub-pixel phase shift between two images, however, I am unclear with the specific details of each component of the return object (method returns a list containing a tuple, and a floating points number).
Any and all help is greatly appreciated, thank you in advance.
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)
Output:
((4.3597901057868285, -2.8767423065464186), 0.4815432178477446)

