代码之家  ›  专栏  ›  技术社区  ›  fightstarr20

opencv img.shape返回错误的尺寸

  •  0
  • fightstarr20  · 技术社区  · 5 年前

    我正在用python opencv加载一个图像并获取尺寸,如下所示…

    img = cv2.imread(filepath)
    
    height, width = srcImg.shape
    
    print("width %s" % width)
    print("height %s" % height)
    

    我正在加载的图像是800x600,但是shape报告为64x480

    有人知道为什么吗?

    0 回复  |  直到 5 年前
        1
  •  1
  •   sashaboulouds    5 年前

    我想你得到的图像尺寸不对,这里 srcImg 而不是 img .

    试试这个:

    img = cv2.imread(filepath)
    
    height, width = img.shape[:2]
    
    print("width %s" % width)
    print("height %s" % height)
    
        2
  •  1
  •   Taha    5 年前

    试试这个,这对普通的图像格式有效

    img = cv2.imread(filepath)
    height,width=img.shape[0],img.shape[1]
    print(height,width)
    

    希望这对你有帮助