openCV与python联合获取图像信息图像处理初步-源码实战

方式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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海宝7号

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值