import cv2 as cv
import numpy as np
def get_image_info(image):
# 打印图片属性
print(type(image))
# 打印图片形状
print(image.shape)
# size = shape的三个值相乘
print(image.size)
# 打印image类型
print(image.dtype)
# 显示像素数据
pixel_data = np.array(image)
print(pixel_data)
def video_demo():
capture = cv.VideoCapture(0)
while(True):
# frame就是组成视频的一帧帧图像
ret, frame = capture.read()
# 摄像头和现实中是相反的,通过该操作将视频内容反过来
frame = cv.flip(frame, 1)
cv.imshow('video', frame)
# 在一个给定的时间内(单位ms)等待用户按键触发;如果用户没有按下 键,则接续等待(循环)
c = cv.waitKey(50)
if c == 27:
break
src = cv.imread('C:/Users/Y/Pictures/Saved Pictures/demo.png')
cv.namedWindow('input image', cv.WINDOW_AUTOSIZE)
cv.imshow('input image', src)
get_image_info(src)
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
gray = cv.imwrite('C:/Users/Y/Pictures/Saved Pictures/result.png', gray)
# video_demo()
cv.waitKey()
cv.destroyAllWindows()