日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python opencv捕獲攝像頭并顯示內容的實現

系統 1773 0

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-----從本地攝像頭和網絡攝像頭截取圖片

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

# 獲取網絡攝像頭,格式: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)


          

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 庄浪县| 仙游县| 平遥县| 乌苏市| 从江县| 黄山市| 清丰县| 长宁县| 贡觉县| 甘孜县| 东阿县| 界首市| 皮山县| 宜城市| 三都| 舒城县| 鹿泉市| 吴川市| 泾阳县| 大洼县| 汕头市| 绥江县| 颍上县| 仁寿县| 翁牛特旗| 双流县| 延边| 黄浦区| 台中县| 晋州市| 克拉玛依市| 青浦区| 宝坻区| 灯塔市| 中西区| 布拖县| 淮安市| 大洼县| 镇巴县| 洪湖市| 蒙山县|