Python-OpenCV 图像处理(一):图片和视频读、写、显示等操作

import cv2
import numpy as np

__author__ = "zxsuperstar"
__email__ = "[email protected]"


def video_demo():
    # VideoCapture()中参数是0,表示打开笔记本的内置摄像头,参数是视频文件路径则打开视频
    capture = cv2.VideoCapture(0)
    while(True):
        ret, frame = capture.read()
        frame = cv2.flip(frame,1)
        cv2.imshow("video", frame)
        c = cv2.waitKey(50)
        if c == 27:
            break


def get_image_info(image):
    print(type(image))
    print(image.shape)
    print(image.size)
    print(image.dtype)
    print(np.array(image))


if __name__ == "__main__":
    src = cv2.imread("1.jpg")
    cv2.namedWindow("input image", cv2.WINDOW_AUTOSIZE)
    cv2.imshow("input image",src)
    get_image_info(src)
    gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
    cv2.imshow("gray",gray)
    cv2.imwrite("./res.jpg", gray)
    # video_demo()
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    print("hi")

Python-OpenCV 图像处理(一):图片和视频读、写、显示等操作_第1张图片

你可能感兴趣的:(图像处理)