gpt4 book ai didi

python - 在opencv中调整图像大小

转载 作者:太空宇宙 更新时间:2023-11-03 11:26:01 26 4
gpt4 key购买 nike

我是 opencv 和图像处理的新手。我正在尝试在 pyimagesearch.com 上找到的这段代码.我将图像调整为 500 像素的高度以执行边缘检测和查找轮廓。

r = 500.0 / image.shape[1]
dim = (500,int(image.shape[0] * r))
image = cv2.resize(image,dim,interpolation = cv2.INTER_AREA)
ratio = image.shape[0] /500.0

再次,我将处理后的图像乘以比率(以便对原始图像进行更改)

warped = four_point_transform(orig,screenCnt.reshape(4,2)*ratio)
r = 500.0 / warped.shape[1]
dim = (500,int(warped.shape[0] * r))

warped = cv2.resize(warped,dim,interpolation = cv2.INTER_AREA)
cv2.imshow("Perspective Transform",warped)

在此之后,我得到的结果有点像这样 Image .只有部分图像可见,我看不到图像的其余部分。请帮我。谢谢!

最佳答案

在我看来,您正在混合宽度和高度。

对于常规图像,image.shape[] 会按顺序为您提供高度、宽度和 channel 。

所以它应该看起来像:

newHeight = 500.0
oldHeight = image.shape[0]
oldWidth = image.shape[1]
r = newHeight / oldHeight
newWidth = int(oldWidth * r)
dim = (newHeight, newWidth)
image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
aspectRatio = image.shape[1] / image.shape[0]

关于python - 在opencv中调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33646009/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com