OpenCV Image Resize翻转尺寸?

时间:2014-01-21 02:53:33

标签: python opencv

我正在尝试使用Python OpenCV绑定(CV2,新绑定)缩小图像:

ret, frame = cap.read()
print frame.shape
# prints (720, 1280, 3)
smallsize = (146,260)

smallframe = cv2.resize(frame, smallsize)
print smallframe.shape
# prints (260, 146, 3)

正如您所看到的,尺寸最终会在缩小的图像上翻转。我没有返回维度(WxH) 146x260 的图片,而是 260x146

是什么给出了?

2 个答案:

答案 0 :(得分:15)

很久以前就回答了这个问题,但从未接受过。让我为那些对此感到困惑的其他人解释一下。问题是在python中,OpenCV使用numpy。 Numpy数组形状,函数等假设(高度,宽度),而OpenCV函数,方法等使用(宽度,高度)。你只需要注意。

要点:

  • cv2.anything() - >使用 (width, height)
  • image.anything() - >使用 (height, width)
  • numpy.anything() - >使用 (height, width)

答案 1 :(得分:1)

因为大小首先采用列,而矩阵的第一维是行。看看the documentation here