美工使用OpenCv辅助处理图片:获取图片的尺寸

cv2.imread函数的shape属性,返回的是一个Python Tuple

cv.imread.shape(h, w, 3)

w 对应 x轴,h 对应 y轴,3为通道数

x轴即:宽度,y轴即:高度

3通道图片就是R,G,B,4通道图片就是R,G,B 加上 Alpha 通道,Alpha通道就是透明度通道

其他代码懒得写,都是很基础的,自己看:

import os
import cv2


CurrentPath = os.getcwd()


def read(Path):
	for file_name in os.listdir(Path):
		img = cv2.imread(Path + "./" + file_name)
		if img is not None:
			shape = str(img.shape)
			print("file name: " + file_name + "\tfile size : " + shape)
		else:
			print('\n***** Detected other type file:', file_name)


if __name__ == '__main__':
	print("current path is ----------- " , CurrentPath)
	read(CurrentPath)

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值