Open CV系列学习笔记(一)图像的加载与保存 2021-01-19

Open CV系列学习笔记(一)图像的加载与保存

一、视频读取

调用电脑摄像头

import cv2 as cv


def video_demo():  # 视屏读取
    capture = cv.VideoCapture(0)
    while (True):
        ret, frame = capture.read()
        frame = cv.flip(frame, 1)
        cv.imshow("video", frame)
        c = cv.waitKey(20)
        if c == 27:
            break

video_demo()
cv.waitKey(0)     

二、图片读取

读取图片,输出图片的大小等信息:

import cv2 as cv
import numpy as np

def get_image_info(image):#图片读取
    print(type(image))#数据类型
    print(image.shape)#像素大小和通道
    print(image.size)#总大小
    print(image.dtype)
    pixel_date = np.array(image)
    print(pixel_date)

print("--------HEllow Python-------")
src = cv.imread("E:/picture/10.bmp")
cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)
cv.imshow("input image",src)
cv.waitKey(0)

以此为例:在这里插入图片描述

输出结果:
--------HEllow Python-------
<class ‘numpy.ndarray’>
(659, 615, 3)
1215855
uint8
[[[235 185 132]
[235 185 132]
[235 185 132]

[231 177 116]
[231 177 116]
[231 177 116]]

[[234 184 131]
[234 184 131]
[234 184 131]

[232 178 117]
[232 178 117]
[232 178 117]]

[[234 184 131]
[234 184 131]
[234 184 131]

[232 178 117]
[232 178 117]
[232 178 117]]

[[193 224 239]
[194 225 240]
[196 225 239]

[230 217 139]
[223 210 132]
[220 207 129]]

[[193 223 240]
[192 225 241]
[196 225 240]

[229 216 138]
[223 210 132]
[219 206 128]]

[[193 223 240]
[192 225 241]
[196 225 240]

[229 216 138]
[223 210 132]
[219 206 128]]]

三、图片的保存

import cv2 as cv
import numpy as np

def get_image_info(image):#图片读取
    print(type(image))#数据类型
    print(image.shape)#像素大小和通道
    print(image.size)#总大小
    print(image.dtype)#
    pixel_date = np.array(image)
    print(pixel_date)

print("--------HEllow Python-------")
src = cv.imread("E:/picture/10.bmp")
cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)
cv.imshow("input image",src)
get_image_info(src)
v.imwrite("./result.png",src)#保存图片
cv.waitKey(0)

将读取的图片,保存 或者将电脑摄像头读取的到视频截图。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值