如何使用 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 上的文件夹中?这是我让两个摄像头在两个单独的 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()
每 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()
我想使用连接到 Raspberry Pi 3 的两个 USB 摄像头拍摄的一对上下立体图像,用于无人机。如何将同时拍摄的图像保存在 pi 上的文件夹中?这是我让两个摄像头在两个单独的 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()
每 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()