[英]Is there an alternative to cv2.resize() in OpenCV for downscaling images?
[英]Python/OpenCV: Using cv2.resize() I get an error
我正在使用 python 2.7 和 opencv。
我正在嘗試使用:
cv2.resize(src, dst, Size(), 0.5, 0.5, interpolation=cv2.INTER_LINEAR);
取自這里。 但是當我運行這段代碼時,我得到NameError: global name 'Size' is not defined.
你能幫我嗎?
您可能正在查看resize
方法的 C++ api。
python API 看起來像這樣:
dst = cv2.resize(src, dsize)
在哪里
src - Original image
dsize - a tuple defining the final size of the image.
如果你想傳遞額外的參數,那么你可以使用 API 的命名參數:
dst = cv2.resize(src, dsize, fx = 0.5, fy=0.5, interpolation = cv2.INTER_LINEAR)
由於 dsize 是必需的參數,但如果您仍然希望resize
方法為您計算dsize
,那么您可以將參數作為None
傳遞。
dst = cv2.resize(src, None, fx = 0.5, fy=0.5)
以前的答案是好的,但我想重用存儲 - 調整image
大小以適應resized
現有存儲(都是 3 維uint8
numpy 數組),我需要使用
ret = cv2.resize(image, dsize=resized.shape[:2][::-1], dst=resized)
請注意, dsize 參數是向后的——它不是 (rows, columns),而是 (width, height),因此是[::-1]
。
我返回ret
只是為了確認確實(ret == resized).all()
。
# lets doubled the size of our image/ increasing the size...
img_double_scaled = cv2.resize(img, None, fx = 1.5, fy = 1.5, interpolation = cv2.INTER_CUBIC)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.