最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python opencv捕獲攝像頭并顯示內(nèi)容的實現(xiàn)

 更新時間:2019年07月11日 10:29:42   作者:小呆丶  
這篇文章主要介紹了python opencv捕獲攝像頭并顯示內(nèi)容的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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、從攝像頭內(nèi)抓拍圖片

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() 

補(bǔ)充:python-----從本地攝像頭和網(wǎng)絡(luò)攝像頭截取圖片

import cv2

# 獲取本地攝像頭
# folder_path 截取圖片的存儲目錄
def get_img_from_camera_local(folder_path):
  cap = cv2.VideoCapture(0)
  i = 1
  while True:
    ret, frame = cap.read()
    cv2.imshow("capture", frame)
    print str(i)
    cv2.imwrite(folder_path + str(i) + '.jpg', frame) # 存儲為圖像
    if cv2.waitKey(1) & 0xFF == ord('q'):
      break
    i += 1
  cap.release()
  cv2.destroyAllWindows()

# 獲取網(wǎng)絡(luò)攝像頭,格式:rtsp://username:pwd@ip/
# folder_path 截取圖片的存儲目錄
def get_img_from_camera_net(folder_path):
  cap = cv2.VideoCapture('rtsp://username:pwd@ip/')
  i = 1
  while True:
    ret, frame = cap.read()
    cv2.imshow("capture", frame)
    print str(i)
    cv2.imwrite(folder_path + str(i) + '.jpg', frame) # 存儲為圖像
    if cv2.waitKey(1) & 0xFF == ord('q'):
      break
    i += 1
  cap.release()
  cv2.destroyAllWindows()

# 測試
if __name__ == '__main__':
  folder_path = 'D:\\img_from_camera\\'
  get_img_from_camera_local(folder_path)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

合川市| 论坛| 永和县| 保亭| 淅川县| 綦江县| 曲靖市| 张家口市| 拜泉县| 思南县| 河源市| 商丘市| 明水县| 岳西县| 上饶县| 徐闻县| 平定县| 晋城| 香格里拉县| 七台河市| 台南县| 清镇市| 五常市| 灵山县| 读书| 子洲县| 宜都市| 巴林左旗| 同心县| 登封市| 南木林县| 隆子县| 全州县| 长武县| 沛县| 汤阴县| 钦州市| 大渡口区| 中宁县| 云林县| 彩票|