欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

bash + python实现自动定时摄像

程序员文章站 2022-03-08 09:12:27
...

bash脚本:

#!/bin/bash
function countdown(){
#without a specific picture's name, name it according to the time by default 
sleep 1
time=$1
echo "Be ready to capture in $time seconds."
read -p "how many pictures do you want?" number
for ((i=1;i!=number;i++)
do
echo -e "\n"
read -p "wanna to give the picture a name:     " pic
if [ -z $pic ];then
	pic=$(date %H:%M:%S)
fi
while [ $time -ge 1 ]
do
	echo $time
	time=$(($time - 1))
	sleep 1
done
echo "now capturing..."
python3 camera.py
done
}
read -p "input the time about how often you wanna to capture (h.m.s):" time_1
h_time=$(echo $time_1 | cut -d "." -f 1)
m_time=$(echo $time_1 | cut -d "." -f 2)
s_time=$(echo $time_1 | cut -d "." -f 3)
time=$(($h_time * 3600 + $m_time * 60 + $s_time))
countdown $time
video

python:

#named camera.py
import cv2
import numpy as np
import time
def Capture():
    video_capture=cv2.VideoCapture(0)
    save_path = "/home/pi/project/Captured/"

    if video_capture.isOpened():
        print("camera on...")
    while video_capture.isOpened():
        ret,frame= video_capture.read()
        frame=np.hstack((frame))
        cv2.imwrite(save_path+str(i)+".jpg", frame)
        time.sleep(3)
        print("exiting ... ")
        video_capture.release()
Capture()

相关标签: GNU/Linux