本文介绍了OpenCV warpAffine和逆warpAffine不一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenCV warpAffine函数进行一些图像处理.奇怪的是,我在应用了warpAffine然后是反向warpAffine之后发现了这一点.处理后的图像与原始图像不一致,在原始图像的底部有一个像素的边框填充.

I'm using the OpenCV warpAffine function to do some image processing. The weird thing is that I found after applying a warpAffine and then an inverse warpAffine. The processed image is inconsistent with the original image, where there is one-pixel border padding at the bottom.

img_path = '140028_199844.jpg'
img = cv2.imread(img_path,cv2.IMREAD_COLOR)
plt.imshow(img[:,:,::-1])
h,w,_=img.shape # h=220 w=173
src = np.array([[ 86., 109.5], [ 86. , 0. ], [-23.5, 0. ]])
dst = np.array([[192., 192.], [192. , 0.], [  0. , 0.]])
trans = cv2.getAffineTransform(np.float32(src), np.float32(dst))
inv_trans = cv2.getAffineTransform(np.float32(dst), np.float32(src))
input = cv2.warpAffine(
    img,
    trans,
    (384, 384),
    flags=cv2.INTER_LINEAR,
    borderMode=cv2.BORDER_CONSTANT,
    borderValue=(0, 0, 0))
plt.imshow(input[:,:,::-1])
output = cv2.warpAffine(
        input,
        inv_trans,
        (w, h),
        flags=cv2.INTER_LINEAR,
        borderMode=cv2.BORDER_CONSTANT,
        borderValue=(0,0,0))
plt.imshow(output[:,:,::-1])

那么这个问题可能导致什么?

So what is the possible reseason for such problem?

推荐答案

将图像旋转180度时,Scipy ndimage.rotate(img,angle)帮助了我.似乎速度较慢,但​​对于一些图像来说,时间并不多.

The Scipy ndimage.rotate(img, angle) helped me when rotating images 180 degrees. It seems slower but for a few images it is not much time.

这篇关于OpenCV warpAffine和逆warpAffine不一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:59