When using cv2.remap function to remap distorted 1920 * 1080 pixels image to undistorted 2912 * 1184 pixels, I have got right results, but the color of border look strange, (there are red blue, pink…), how can I get image with black borders?
Here is my operation and code:
First calculating the undistort rectify map by camera parameters and distortion coefficients, the size of the map is (4, 1184 * 2912), where 4 is x, y of target image (dst_y, dst_x), and x, y of source image (src_y, src_x), 1184*2912 is the number of pixels in target image.
Then I reshape the value of src_y, src_x to got map_y, map_x, and using cv2.remap to undistort the image:
def cv2_remap(img_src, points_map):
map_y = points_map[2, :].reshape(1184, 2912).astype(np.float32)
map_x = points_map[3, :].reshape(1184, 2912).astype(np.float32)
img_dst = cv2.remap(img_src, map_x, map_y, interpolation=cv2.INTERSECT_NONE,
borderMode=cv2.BORDER_TRANSPARENT, borderValue=(0, 0, 0))
return img_dst