opencv warpAffine忽略标志=cv2.INTER\u区域

2024-05-19 12:35:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我对cv2.warpAffine有问题。我想使用cv2.INTER_AREA插值。但当我将图像从3kx3k调整到100x100时,它的工作原理与cv2.INTER_LINEAR相同。 在docs中有一个类似于interpolation type的标志,但它不起作用=(

https://docs.opencv.org/3.1.0/da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983

# create random image
image = np.random.randint(0, 255, (3000, 3500, 3)).astype(np.uint8)
pts1 = np.float32([[0,0],[3000, 3500],[0,3500]])
t_size = 100
pts2 = np.float32([[5,12],[t_size + 20,t_size + 10],[0,t_size-50]])
# calculate transformation matrix
M = cv2.getAffineTransform(pts1,pts2)
# warp with different flags
image_linear = cv2.warpAffine(image, M, (t_size, t_size), flags = cv2.INTER_LINEAR)
image_area = cv2.warpAffine(image, M, (t_size, t_size), flags = cv2.INTER_AREA)
assert((image_linear == image_area).all())

而且图像是相等的,断言中没有任何异常。你知道吗


Tags: 图像imagedocssizenparearandomcv2
1条回答
网友
1楼 · 发布于 2024-05-19 12:35:22
我在OpenCV C++代码中找到答案。你知道吗

https://github.com/opencv/opencv/blob/174b4ce29d8e1ddbd899095c4b9fb4443444af45/modules/imgproc/src/imgwarp.cpp#L2600

仿射函数中有下一行代码

if( interpolation == INTER_AREA )
         interpolation = INTER_LINEAR;

至于我,我分裂仿射变换旋转,移动和调整大小。并使用旋转和移动与线性插值。并使用interpolation= cv2.INTER_AREA插值调整大小。你知道吗

相关问题 更多 >