图片视频读取保存

import cv2 as cv
import numpy as np


def video_demo():
    capture = cv.VideoCapture(0)  #读取第几个摄像头
    while True:
        ret, frame = capture.read()
        frame = cv.flip(frame, 1)  #左右翻转
        cv.imshow('videv', frame)
        c = cv.waitKey(50)
        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('./0.png')
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('./result.png', gray)
cv.waitKey(0)
cv.destroyAllWindows()

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 2621041184@qq.com