use warpAffine()
for that, with appropriate interpolation flag.
the appropriate matrix is easily constructed. start with a 3x3 identity matrix, then change the third column to effect translation. or construct a 2x3 matrix directly.
filter2D anchor should usually be inside the kernel’s domain. I don’t know if filter2D tolerates anchors going outside of that.
you can always take the “outside” part of it out of the call, and afterwards pad/move the resulting data with some other operation (copymakeborder or whatever).
I wouldn’t bother with any of this filter2D business if your kernel represents interpolation that is already implemented in warpAffine.