学习的视频是python+opencv3.3
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(“E:/image/lena.jpg”) cv.namedWindow(“input_image”, cv.WINDOW_AUTOSIZE) cv.imshow(“input_image”, src) #显示图片,命名为input_image get_image_info(src) cv.imwrite(“E:/image/lena1.jpg”, src) #将图片保存到指定的文档 src_gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY) #将彩色图像转换成灰色图像 cv.imshow(“gray_lena”, src_gray) cv.waitKey(0)
cv.destroyAllWindows()