This question already has an answer here:
这个问题在这里已有答案:
- Size of Matrix OpenCV 5 answers
Matrix OpenCV 5的大小答案
I want to get image width and height, how can I do that in OpenCV?
我想得到图像的宽度和高度,我怎么能在OpenCV中做到这一点?
For example:
Mat src = imread("path_to_image");
cout << src.width;
Is that right?
是对的吗?
2 个解决方案
#1
47
You can use rows
and cols
:
您可以使用行和列:
cout << "Width : " << src.cols << endl;
cout << "Height: " << src.rows << endl;
or size()
:
cout << "Width : " << src.size().width << endl;
cout << "Height: " << src.size().height << endl;
#2
21
Also for openCV in python you can do:
对于python中的openCV,你可以这样做:
img = cv2.imread('myImage.jpg')
height, width, channels = img.shape
#1
47
You can use rows
and cols
:
您可以使用行和列:
cout << "Width : " << src.cols << endl;
cout << "Height: " << src.rows << endl;
or size()
:
cout << "Width : " << src.size().width << endl;
cout << "Height: " << src.size().height << endl;
#2
21
Also for openCV in python you can do:
对于python中的openCV,你可以这样做:
img = cv2.imread('myImage.jpg')
height, width, channels = img.shape