试图将相机中的照片保存到文件中

Trying to save photos from camera into file

正在尝试使用 raspberry pi 3b plus 相机拍照。我们正在向 space 附近发送气象气球,需要每 3 分钟拍照一次并保存所有照片。我不知道我们是否应该将其保存到文件或其他来源。此外,我们每 3 分钟需要一张照片。请帮忙!!

这应该可以,我没有 raspberry pi 摄像头来测试它。该程序使用 opencv 捕获相机,然后每 3 分钟永远捕获照片。使用 ctrl + c 退出。

import time
import cv2
import os

# creates an image folder
if (not os.path.exists(os.getcwd() + "/images")):
    os.mkdir(os.getcwd() + "/images")
counter = 0 # counter so each image name is different
cap = cv2.VideoCapture(0) # gets the camera

while True:
    # Capture frame
    ret, frame = cap.read()
    if ret:
        cv2.imwrite(os.getcwd() + "/images/" +
                    "image{}.jpg".format(counter), frame)
        counter += 1
    time.sleep(180)  # wait 3min

您可以像这样尝试拍摄带有日期和时间标记的测试图像:

raspistill -dt -o /home/pi/image-%d.jpg

这应该会在 /home/pi 中产生这样的图像:

-rw-r--r--   1 pi pi    4397351 Nov 12 08:28 image-1112082809.jpg

对它的质量和尺寸感到满意。然后你可以通过在你的 crontab 中添加一个条目来每 3 分钟拍摄一张图像:

*/3 * * * * raspistill -dt -o /home/pi/image-%d.jpg

如果您不熟悉 cron,您可以使用命令 crontab -e 并选择最简单的编辑器 nano 来编辑 crontab。如果您想列出并检查 cron 条目而不编辑它们,请使用 crontab -l

如果您不熟悉 raspistill,您可以通过 raspistill --help.

获得有关其语法和选项的帮助

仅供参考,在 Dave Akerman 的页面 here.

上有一个名副其实的宝库 material 关于 Raspberry Pis 的高空热气球飞行