方式1:通过CV2库直接查看图像信息
源码如下
import cv2
file_path = 'W:\PY\WDPY\piccc\dfgdd.jpg'
# file_path = 'C:/Users/admin/Pictures/scence/1.jpg'
img = cv2.imread( file_path ) # 读取图片信息
# sp = img.shape[0:2] #截取长宽
sp = img.shape # [高|宽|像素值由三种原色构成]
print( sp )
输出结果:
(1080, 1920, 3)
Process finished with exit code 0
方式2:通过PIL库的image包处理
结果输出:
(1920, 1080)
1920 1080 JPEG
Process finished with exit code 0
源码如下:
from PIL import Image
file_path = 'W:\PY\WDPY\piccc\dfgdd.jpg'
sp = img.shape # [高|宽|像素值由三种原色构成]
img = Image.open( file_path )
imgSize = img.size # 大小/尺寸
w = img.width # 图片的宽
h = img.height # 图片的高
f = img.format # 图像格式
print( imgSize )
print( w, h, f )
另外:最终版,展示全部的高度和长度以及通道。RGB3真彩,详细信息显示如下。
(1080, 1920, 3)
height is: 1080
(1080, 1920, 3)
width is: 1920
(1080, 1920, 3)
channel is: 3
源码附上:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author's_name_is_NIKOLA_SS
from PIL import Image
import cv2 as cv
import numpy as np
file_path = 'W:\PY\WDPY\piccc\dfgdd.jpg'
im=cv.imread(file_path)
height=im.shape[0]
cv.imshow('origin image',im)
print(im.shape)
print('height is:',height)
width=im.shape[1]
print(im.shape)
print('width is:',width)
channel=im.shape[2]
print(im.shape)
print('channel is:',channel)
cv.waitKey()