簡體   English   中英

如何使用OpenCV從同時連接到Raspberry Pi 3的兩個USB攝像機捕獲和保存圖像?

[英]How to capture and save images from two USB cameras connected to a Raspberry Pi 3 simultaneously using OpenCV?

我希望使用由連接到Raspberry Pi 3的兩個USB攝像機拍攝的一對上下一對立體聲圖像,以用於無人機。 如何將同時拍攝的圖像保存在pi上的文件夾中? 這是使兩個攝像機在兩個單獨的窗口上運行的工作:

import cv2

frame0 = cv2.VideoCapture(1)
frame1 = cv2.VideoCapture(3)
while 1:

   ret0, img0 = frame0.read()
   ret1, img00 = frame1.read()
   img1 = cv2.resize(img0,(1280,720))                          #360,240
   img2 = cv2.resize(img00,(1280,720))
   if (frame0):
       cv2.imshow('img1',img1)
   if (frame1):
       cv2.imshow('img2',img2)

   k = cv2.waitKey(30) & 0xff
   if k == 27:
      break

frame0.release()
frame1.release()
cv2.destroyAllWindows()

每7秒將兩個圖像集與.py文件保存在同一目錄中。

import cv2
import time

frames = 100
interval = 7

frame0 = cv2.VideoCapture(1)
frame0.release()
frame0 = cv2.VideoCapture(1)
frame1 = cv2.VideoCapture(3)
frame1.release()
frame1 = cv2.VideoCapture(3)
for i in range(frames):

   ret0, img0 = frame0.read()
   ret1, img00 = frame1.read()
   img1 = cv2.resize(img0,(1280,720))                          #360,240
   img2 = cv2.resize(img00,(1280,720))
   if (frame0):
       cv2.imwrite('./img_'+str(i).zfill(4)+'.jpg',img1)
   if (frame1):
       cv2.imwrite('./img2_'+str(i).zfill(4)+'.jpg',img2)

   time.sleep(interval)
   #k = cv2.waitKey(30) & 0xff
   #if k == 27:
    #  break

frame0.release()
frame1.release()
cv2.destroyAllWindows()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM