OpenCV常用基本处理函数(1)读写

图像的基本操作

cv.imread()      读取图片

cv.imshow()     显示图片

cv2.imwrite()    保存图像

使用摄像头捕获实时图像

OpenCV 为这中应用提供了一个非常简单的接口

 1 import numpy as np
 2 import cv2
 3 
 4 cap = cv2.VideoCapture(0)
 5 
 6 while(True):
 7     # Capture frame-by-frame
 8     ret, frame = cap.read()
 9 
10     # Our operations on the frame come here
11     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
12 
13     # Display the resulting frame
14     cv2.imshow('frame',gray)
15     if cv2.waitKey(1) & 0xFF == ord('q'):
16         break
17 
18 # When everything done, release the capture
19 cap.release()
20 cv2.destroyAllWindows()

从文件中播放视频

只需要改变ViddeoCapture的参数为文件名字即可

cap = cv2.VideoCapture('vtest.avi')



系列文章均参考自opencv-python中文文档,以及翻译者的博客
https://www.cnblogs.com/Undo-self-blog/p/8423851.html
原文地址:https://www.cnblogs.com/ywheunji/p/10986973.html