一.计算机眼中的图像:
1.读取图像:
cv2.IMREAD_COLOR:彩色图像(三通道)
cv2.IMREAD_GRAYSCALE:灰度图(单通道)
cv2.imread:读取图像(矩阵形式,BGR格式+)
cv2.imshow(‘image’, img):显示图像
cv2.imwrite(name, img):保存图像
2.读取视频
video = cv2.VideoCapture()
open, frame = vedio.read():open为布尔型,frame为每一帧图像
import cv2
vc = cv2.VideoCapture('labvedio1.mp4')
if vc.isOpened():
open, frame = vc.read()
else:
open = False
while open:
ret, frame = vc.read()
if frame is None:
break
if ret == True:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('result', gray)
if cv2.waitKey(100) & 0xFF == 27:
break
vc.release()
cv2.destroyAllWindows()