2020-11-11 贾志刚学习笔记复盘---图像得加载与保存

import tensorflow as tf
import cv2 as cv
import numpy as np
"""
什么是图像?结构化存储数据信息,图像属性:通道数目、高与宽、像素数据、图像类型
加载与显示
代码层面知识点:
加载图像得模块与API
支持常见格式
"""


# 读视频
def video_demo():
    #capture = cv.VideoCapture(0)  # 0代表USB摄像头,或者文件得路径
    capture = cv.VideoCapture("C:/Users/tzt/Desktop/opencv-python/ex.mp4")
    while(True):
        ret, frame = capture.read()  # 打开相机,ret返回值,frame每一帧得值
        frame = cv.flip(frame,1)  # flip左右,1和-1上下
        cv.imshow("video", frame)
        c = cv.waitKey(50)  # 响应50ms
        if c == 27:
            break


# 读图像
def get_image_info(image):
    print(type(image))  # 类型
    print(image.shape)   # 高、宽、通道数目
    print(image.size)  # 大小
    print(image.dtype)  # 字节位数占多少
    pixel_data = np.array(image)  # 获取所有得像素数据
    print(pixel_data)


src = cv.imread("C:/Users/tzt/Desktop/opencv-python/girl.jpg")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
get_image_info(src)
# video_demo()
gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY)
cv.imwrite("C:/Users/tzt/Desktop/opencv-python/girls.jpg", gray)
cv.waitKey(0)
cv.destroyAllWindows()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容