利用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()