打印圖像相關屬性¶
概要¶
opencv圖像的數據結構是numpy, 本節主要講解了numpy的一些基礎屬性
keywords numpy 圖像寬度 size 圖像高度
打印圖像屬性¶
Image的屬性,其實就是numpy的ndarray數據格式的屬性.
我們可以直接獲取img對象的諸多屬性, 在這里我們將其打印出來.
# -*- coding: utf-8 -*- import numpy as np import cv2 # 導入一張圖像 模式為彩色圖片 img = cv2.imread('cat.jpg', cv2.IMREAD_COLOR) print("================打印一下圖像的屬性================") print("圖像對象的類型 {}".format(type(img))) print(img.shape) print("圖像寬度: {} pixels".format(img.shape[1])) print("圖像高度: {} pixels".format(img.shape[0])) print("通道: {}".format(img.shape[2])) print("圖像分辨率: {}".format(img.size)) print("數據類型: {}".format(img.dtype))
結果輸出
================打印一下圖像的屬性================ 圖像對象的類型 <class 'numpy.ndarray'> (182, 277, 3) 圖像寬度: 277 pixels 圖像高度: 182 pixels 通道: 3 圖像分辨率: 151242 數據類型: uint8
如果想熟練的使用python-opencv的話,必須對numpy的ndarray非常的熟悉。所以還得仔細讀一下, 阿凱寫的numpy教程. 吼吼.