cv2.imread(const String & filename, int flags)
filename 图片名,字符串
flags 三种类型imread_color/grayscale/unchanged
如果图片不可以读入,则返回一个空矩阵。
cv2.imshow(const String & winname, InputArray mat)
winname 窗口名称
mat 要展示的图片的矩阵
Show with the function cv::Window_autosize
Always followed by the function cv::WaitKey
cv2.imwrite(const String & filename,InputArray img)
将要展示的图片输出到文件名为filename的文件
key = cv2.waitKey(int delayTime) & 0xFF
用于在键盘上读取输入
delayTime是反应时间
将返回值转换成AssCi码需要使用 & 0xFF
cv2.destoryAllWindows()
cv2.destoryWindow()
cv2.namedWindow(const String & winname, int flags=WINDOW_AUTOSIZE)
create a window with Window_autosize
cv2.VideoCapture()
import cv2 as cv
cap = cv.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame',gray)
if cv.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
从摄像头获取视频信息
#用输出文件流对录制的文件信息进行保存
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc,20.0,(640,480))
import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
# Define the codec and create VideoWriter object
fourcc = cv.VideoWriter_fourcc(*'XVID')
out = cv.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
#frame = cv.flip(frame,0)
# write the flipped frame
out.write(frame)
cv.imshow('frame',frame)
if cv.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv.destroyAllWindows()
原文:https://www.cnblogs.com/Xiaojianxiang/p/11232123.html