【问题标题】:How to get image width and height in OpenCV? [duplicate]如何在 OpenCV 中获取图像的宽度和高度? [复制]
【发布时间】:2016-01-03 10:42:17
【问题描述】:

我想获得图像的宽度和高度,我该如何在 OpenCV 中做到这一点?

例如:

Mat src = imread("path_to_image");
cout << src.width;

对吗?

【问题讨论】:

    标签: python c++ opencv


    【解决方案1】:

    您可以使用rowscols

    cout << "Width : " << src.cols << endl;
    cout << "Height: " << src.rows << endl;
    

    size():

    cout << "Width : " << src.size().width << endl;
    cout << "Height: " << src.size().height << endl;
    

    size

    cout << "Width : " << src.size[1] << endl;
    cout << "Height: " << src.size[0] << endl;
    

    【讨论】:

      【解决方案2】:

      对于python中的openCV,你也可以这样做:

      img = cv2.imread('myImage.jpg')
      height, width, channels = img.shape 
      

      【讨论】:

      • 很好,但是 OP 要求使用 C++
      • 是的,这是真的,但是谷歌搜索 python 的结果会带你到这里。
      • AttributeError: 'NoneType' 对象没有属性 'shape'
      猜你喜欢
      • 2013-09-24
      • 2011-11-26
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多