我是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[]
将按此顺序提供高度,宽度和通道。
所以它应该看起来像:
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]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句