B站python+opencv3.3视频教学笔记 02图像加载与保存

代码如下

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("video", 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)


print("--------- Hello Python ---------")
src = cv.imread("E:/Users/tu.png")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
get_image_info(src)
gray = cv.cvtColor(src, cv.COLOR_RGB2GRAY)
cv.imwrite("D:/result.jpg", gray)
video_demo()
cv.waitKey(0)
cv.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/weixin_42138331/article/details/89512288