Opencv-Python调整大小图像 [英] Opencv-Python-Resizing image

查看:209
本文介绍了Opencv-Python调整大小图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试调整图像大小,但出现错误提示.

Tryin'to resize the image but got an error saying.

TypeError :resize()缺少1个必需的位置参数:"image".

TypeError: resize() missing 1 required positional argument: 'image'.

line 11, in <module> img = resize(img, width = 1280)


import cv2
import numpy as np
from matplotlib import pyplot as plt

def resize(self,image,window_height = 500):
aspect_ratio = float(image.shape[1])/float(image.shape[0])
window_width = window_height/aspect_ratio
image = cv2.resize(image, (int(window_height),int(window_width)))
return image

img = cv2.imread('hr.jpg')
img_resized = resize(img,window_height = 800)
cv2.imshow("Resized",img_resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

推荐答案

您也需要说出高度和宽度. :)

You need to say the height and the width too. :)

resized_image = cv2.resize(image, (800, 250)) # for example

第一个是宽度(800),第二个是高度(250)

First is width (800) and the second is height (250)

编辑 也许您的代码可以工作(我不知道),但是您在调整大小之前忘记了cv2.,但是我建议您编写宽度和高度.

EDIT Maybe your code can work (I don't know) but you have forgotten cv2. before resize but I recomend you write width and height.

这篇关于Opencv-Python调整大小图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆