How to merge Remap InputArray and Affine Transforms

asked 2019-05-18 13:28:42 -0500

Kafan gravatar image

updated 2019-05-24 15:09:37 -0500

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))
edit retag flag offensive close merge delete

Comments

1

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 gravatar imageberak ( 2019-05-19 02:59:56 -0500 )edit
2

@berak Updated main question with code

Kafan gravatar imageKafan ( 2019-05-21 02:07:04 -0500 )edit

@berak can you take a look at the code?

Kafan gravatar imageKafan ( 2019-05-22 14:09:27 -0500 )edit

@berak Any suggestion ?

Kafan gravatar imageKafan ( 2019-05-23 03:24:55 -0500 )edit