import cv2 as cv
import numpy as np
#图像资料获取
def get_image_info(image):
print(type(image))#image type <class 'numpy.ndarray'>
print(image.shape)#长宽,通道数
print(image.size)
print(image.dtype)
pixel_data=np.array(image)#得到像素矩阵
print(pixel_data)
#获取视频数据,调用电脑摄像头
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:#退出键ascall
break
print("hello---------------opencv")
src=cv.imread("D:/cvdata/demo.jpg")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
get_image_info(src)
gray=cv.cvtColor(src,cv.COLOR_BGR2GRAY)#得到灰色图形
cv.imwrite("D:/result1.jpg",gray)
#video_demo()
cv.waitKey(0)#延迟
cv.destoryAllWindows()
图像以及视频的获取
最新推荐文章于 2022-03-13 00:00:00 发布