An overhead inspection camera checks whether a fixture has moved. A registration function reports a horizontal shift of seven pixels. Applying that shift to the latest frame can move its marks farther from the reference if the code uses the measurement as a correction. A known translation makes it possible to verify argument order, coordinate order, and correction direction separately.
OpenCV's phase correlation estimates translation between two grayscale floating-point arrays. The return value contains an X displacement and a Y displacement. NumPy array axes are ordered by row, then column. In a conventional image array, increasing row index moves down the image. Keep that convention visible when passing the result to an array operation.
Test with a known translation
This example creates three dissimilar marks on a dark frame. It moves their image seven columns to the right and four rows up, estimates the displacement in both directions, and checks that the inverse integer shift restores the original pixels.
import cv2 as cv
import numpy as np
reference = np.zeros((64, 80), dtype=np.float32)
reference[14:19, 20:28] = 1.0
reference[30:36, 44:47] = 0.6
reference[39, 29] = 0.8
observed = np.roll(reference, shift=(-4, 7), axis=(0, 1))
forward, response = cv.phaseCorrelate(reference, observed)
backward, _ = cv.phaseCorrelate(observed, reference)
assert np.allclose(forward, (7, -4), atol=0.01)
assert np.allclose(backward, (-7, 4), atol=0.01)
dx, dy = (int(round(v)) for v in forward)
aligned = np.roll(observed, shift=(-dy, -dx), axis=(0, 1))
assert np.array_equal(aligned, reference)
The tested result in OpenCV 5.0.0 was approximately (7, -4) with the reference first and the observed frame second. Swapping the frames returned approximately (-7, 4). The image correction in this example shifts the observed image four rows down and seven columns left. Because the test uses integer motion and a circular roll in both directions, the last check can demand exact pixel equality.
Decide what the production check should measure
A camera shift can reveal pixels along an edge. NumPy's roll wraps those pixels around, so it is only a convenient tool for this synthetic test. For a live comparison, choose a border rule and measure alignment error where the two frames have valid overlapping data. Avoid rounding a fractional displacement unless the downstream application deliberately works at whole-pixel resolution.
Record the reference image, camera crop, returned shift, and the remaining alignment error. OpenCV's response summarizes the correlation peak, and its API does not define it as a probability that the alignment meets an inspection tolerance. Test the direction against an asymmetric target you can move by a known amount. A translation in the image is measured in pixels. Converting it to a distance on a fixture needs a separate calibration that accounts for the imaging geometry.
Sources
OpenCV motion analysis reference for phaseCorrelate and its response
https://docs.opencv.org/4.13.0/d7/df3/group__imgproc__motion.html
NumPy roll documentation for axis order and wraparound
https://numpy.org/doc/stable/reference/generated/numpy.roll.html