简体   繁体   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?

I'm looking to use a pair of top-bottom pair of stereo images taken by two USB cameras connected to a Raspberry Pi 3 for use on a drone. 我希望使用由连接到Raspberry Pi 3的两个USB摄像机拍摄的一对上下一对立体声图像,以用于无人机。 How do I save the images taken simultaneously in a folder on the pi? 如何将同时拍摄的图像保存在pi上的文件夹中? Here's what I did to get both the cameras working on two separate windows: 这是使两个摄像机在两个单独的窗口上运行的工作:

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

Set of two images are saved every 7 seconds in the same directory as the .py file. 每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.

相关问题 如何修复使用USB端口连接到树莓派的热敏打印机的usb.core.USBError - How to fix the usb.core.USBError of thermal printer connected to raspberry pi using USB port 谁能解释如何使用OpenCV在Raspberry Pi上从kinect保存RGB图像? - Could anyone explain how to save RGB image from kinect on Raspberry Pi using OpenCV? Raspberry Pi 3上的OpenCV多个USB摄像头 - OpenCV multiple USB camera on Raspberry Pi 3 如何使用OpenCV捕获来自多台摄像机的实时视频? - How to use OpenCV to capture live video feed from multiple cameras? 从Raspberry Pi捕获jpeg图像并将其发送到PC套接字python? - Capture and send jpeg images from Raspberry Pi to PC socket python? 通过在OpenCV中使用python,无法在Raspberry PI上保存视频 - Can't save video on Raspberry PI by using python with OpenCV 如何在Linux中使用名为“imwrite”的python opencv函数将捕获的图像文件保存在USB中 - How to save the capture image file in USB using python opencv function named "imwrite" in Linux 如何通过 USB 电缆将消息从 Raspberry Pi 发送到 Arduino - How send messages from Raspberry Pi to Arduino via USB cable 如何使用 OPCUA 连接两个树莓派? - how to connect two raspberry pi using OPCUA? 如何使用 openCV 在两个相机之间转换坐标? - How can I transform coordinate between two cameras using openCV?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM