cv2.imread读取图片的shape
时间: 2023-11-24 19:52:38 浏览: 157
OpenCV 使用imread()函数读取图片的六种正确姿势
cv2.imread读取图片的shape属性可以通过以下两种方式获取:
1. 直接读取图片shape属性,以元组形式返回:
```python
import cv2
import numpy as np
Img = cv2.imread('1.jpg',cv2.IMREAD_UNCHANGED)
print ('The shape of this image :',Img.shape)
```
2. 注意:Img.shape返回的是一个tuple,tuple=(rows,cols,channels):
```python
import cv2
import numpy as np
Img = cv2.imread('1.jpg',cv2.IMREAD_GRAYSCALE)
print ('该图片的行数为:',Img.shape[0])
print ('该图片的列数为:',Img.shape[1])
print ('该图片的通道数为:',Img.shape[2])
```
阅读全文