如何在OpenCV中获取图像宽度和高度?

时间:2015-10-06 13:27:25

标签: c++ opencv

我想获得图像宽度和高度,我该如何在OpenCV中实现?

例如:

(function () {
// Append the safeHTML polyfill
var scriptElem = document.createElement('script');
scriptElem.setAttribute('src', 'scripts/winstore-jscompat.js');
var scriptElem2 = document.createElement('script');
scriptElem.setAttribute('src', 'scripts/system-polyfills.js');
if (document.body) {
    document.body.appendChild(scriptElem);
    document.body.appendChild(scriptElem2);
} else {
    document.head.appendChild(scriptElem);
    document.head.appendChild(scriptElem2);
}
}());

是吗?

2 个答案:

答案 0 :(得分:67)

您可以使用rowscols

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

size()

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

答案 1 :(得分:36)

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

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