【无标题】opencv读取图片和视频

import cv2
img=cv2.imread('D:/bridge.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyWindow('image')

imread():读入图片

函数参数:1.图片路径 2.读取(默认)彩色图或灰度图 1或0

imshow():展示图片

函数参数: 1.窗口名称 2.图像对象

waitKey(0):按任意键相当pass

destoryWindow():销毁窗口

函数参数 1.销毁窗口的名称

图像属性

print(img)
print(img.shape)
print(type(img))
print(img.size)

[[145 145 145 ... 117 117 117]
 [145 145 145 ... 117 117 117]
 [145 145 145 ... 116 116 116]
 ...
 [ 64  64  64 ...  48  48  48]
 [ 64  64  64 ...  48  48  48]
 [ 64  64  64 ...  48  48  48]]
(1280, 960)
<class 'numpy.ndarray'>
1228800

读取视频

import cv2
vc=cv2.VideoCapture("D:/vidio.mp4")
if vc.isOpened():#判断打开正确与否
    open,frame=vc.read()#read()读第一帧图片,返回一个布尔值和图片对象
while open:
    ret,frame=vc.read()
    if frame is None:
        break#读取到最后一帧之后跳出循环
    if ret==True:
        gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)#图像处理为灰度图
        cv2.imshow("result",gray)
        if cv2.waitKey(10)&0xFE==27:
            break
vc.release()
cv2.destroyWindow("result")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值