web-dev-qa-db-ja.com

OpenCVで画像の幅と高さを取得する方法は?

画像の幅と高さを取得したいのですが、OpenCVでどのようにできますか?

例えば:

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

そうですか?

36
sarmad m

rowsおよびcolsを使用できます。

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

またはsize()

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

pythonのopenCVについても、次のことができます。

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