码迷,mamicode.com
首页 > 编程语言 > 详细

python opencv捕获摄像头并显示内容

时间:2017-08-20 00:43:19      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:des   实时   show   numpy   dex   video   operation   port   frame   

1、捕获摄像头和实时显示

import cv2
import numpy as np
import pickle
import matplotlib.pyplot as plt

cap = cv2.VideoCapture(0)

while True:
    ret,frame = cap.read()
    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # Display the resulting frame
    cv2.imshow(‘frame‘,gray)
    if cv2.waitKey(1) & 0xFF == ord(‘q‘):
        break
 
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

 

2、从摄像头内抓拍图片

 

import cv2
import numpy as np
import pickle
import matplotlib.pyplot as plt

cap = cv2.VideoCapture(0)
index = 0
while True:
    ret,frame = cap.read()
    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # Display the resulting frame
    cv2.imshow(‘frame‘,gray)
    if cv2.waitKey(1) & 0xFF == ord(‘p‘):
        cv2.imwrite("kk.jpg",frame)
        index = index + 1
    if cv2.waitKey(1) & 0xFF == ord(‘q‘):
        break
 
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

  

 

python opencv捕获摄像头并显示内容

标签:des   实时   show   numpy   dex   video   operation   port   frame   

原文地址:http://www.cnblogs.com/TransTown/p/7398254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!