How to merge Remap InputArray and Affine Transforms
I have input array that I use to remap my image and then perform one translation affine transform and one rotation affine transform. I believe this is computationally more intensive and can be simplified by changing the remap function's input array(s) to reflect the translation and rotation transforms. So that all can be applied to image in one go.
Need help with some code or direction to go ahead with this, as I am not sure how to get this done.
// In C++
// Remap
remap(rightCamImage, rightCamImage, camMapX, camMapY, cv::INTER_LINEAR);
// Translation (Translation needs to be done along y axis only)
Mat warp_matrix_translation = Mat::eye(2, 3, CV_64F);
warp_matrix_translation.at<double>(1, 2) = -finalDeltaY;
warpAffine(rightCamImage, rightCamImage, warp_matrix_translation, rightCamImage.size());
// Rotation
Mat warp_matrix_rotation = getRotationMatrix2D(Point(0, 0), -finalThetaRadian*180/PI, 1.0); // This function expects angle in degree
warpAffine(rightCamImage, rightCamImage, warp_matrix_rotation, rightCamImage.size());
# In Python
# Remap
undistorted_img_right = cv2.remap(imgRight, rightMapX, rightMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
# Translation
M = np.float32([[1,0,0],[0,1,-delYIntercept]])
res = cv2.warpAffine(undistorted_img_right,M,(w,h))
# Rotation
M = cv2.getRotationMatrix2D((0,0),-theta,1)
res1 = cv2.warpAffine(res,M,(w,h))
no, you don't need seperate transforms (rotation and translation can be merged into a single, homogeneous transform), but why can't you use warpAffine
show us, how you derive yout translation / rotation, then we can help better.
@berak Updated main question with code
@berak can you take a look at the code?
@berak Any suggestion ?