利用opencv-python读取图形,并获取图像的信息
下面是代码
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)
src = cv.imread('./images/demo.png')
cv.namedWindow('input image',cv.WINDOW_AUTOSIZE)
cv.imshow('input image',src)
cv.imwrite("./spl.png",src)
get_image_info(src)
video_demo()
cv.waitKey(0)
cv.destroyAllWindows()