在open cv

时间:2015-11-11 07:32:55

标签: python opencv image-processing

我对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。只有部分图像可见,我无法看到图像的其余部分。请帮我。谢谢!

2 个答案:

答案 0 :(得分:2)

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

对于常规图像,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]

答案 1 :(得分:0)

如果您想要一种非常简单的方法来升级或缩小图像,请使用pyrUp和pyrDown。

http://docs.opencv.org/2.4/doc/tutorials/imgproc/pyramids/pyramids.html

imageSmall = cv2.pyrDown(image) # make image smaller
imageLarger = cv2.pyrUp(image) # make image larger