0

このスクリプトは、ラズベリーパイの crontab から午前 3 時にトリガーされます。アイデアは、1 日のうちにタイムラプス ビデオを撮影することですが、日の出から日没までの間のみです。コードがトリガーされると、日没時刻と日の出時刻が計算され、日の出を待ちます。その後、写真の撮影を開始する必要がありますが、何らかの理由で日の出時にトリガーされていないようです. これはおそらく「if home.date ==Sunrise:」が正確すぎるためだと思いますか? 1秒未満、または数秒を完全に無視するにはどうすればよいですか?

これは完全なコードです-

import os
import time
import ephem

# find time of sun rise and sunset
sun = ephem.Sun()
home = ephem.Observer()
home.lat, home.lon = '52.8709', '-1.797' #your lat long
sun.compute(home)
sunrise, sunset = home.next_rising(sun)),
                   home.next_setting(sun))
daylightminutes = (sunset - sunrise) * 1440 # find howmany minutes of daylight there are
daylightminutes = (round(daylightminutes))
def dostuff() :
        if home.date == sunrise:
                import datetime
                import sys
                FRAMES = 60#daylightminutes -600 # number of images you want in timelapse video
                FPS_IN = 4 # number of images per second you want in video
                FPS_OUT = 4 # number of fps in finished video 24 is a good value
                TIMEBETWEEN = 6 # number of seconds between pictures, 60 = 1 minute
                #take the pictures needed for the time lapse video
                frameCount = 0
                while frameCount < FRAMES:
                    imageNumber = str(frameCount).zfill(7)
                    os.system("raspistill -rot 270 -o /home/pi/image%s.jpg"%(imageNumber))
                    frameCount += 1
                    time.sleep(TIMEBETWEEN - 6) #Takes roughly 6 seconds to take a picture
                #record current time and date in variable datetime
                datetime = time.strftime("%Y%m%d-%H%M")
                # make the timelapse video out of the images taken
                os.system("avconv -r %s -i /home/pi/image%s.jpg -r %s -vcodec libx264 -crf 20 -g 15 -vf crop=2592:1458,scale=1280:720 /home/pi/timelapse%s.mp4" %(FPS_IN,'%7d',FPS_OUT,datet$
                #send the timelapse video to dropbox
                from subprocess import call
                photofile = "/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload /home/pi/timelapse%s.mp4 /home/pi/timelapse%s.mp4" %(datetime,datetime)
                call ([photofile], shell=True)
                #remove the timelapse video copy and all images it is made up of that are held localy on the Rpi
                os.system("rm /home/pi/timelapse%s.mp4"%(datetime))
                os.system("rm /home/pi/image*")
                sys.exit()
while home.date <= sunrise:
        dostuff()

問題の原因である可能性のある他の問題を見つけた場合は、お知らせください。

乾杯

スティーブ

4

1 に答える 1

0

(a) を作成するObserverと、date手動で変更するまで固定されたままになります。したがって、home.dateチェックし続けることsunriseは決して変わらないため、実際に日の出に達することはありません. 代わりにPyEphemnow()ルーチンを呼び出して、現在の時間のアイデアを進めることができます。

(b) 正確に日の出のミリ秒で比較を行う可能性は非常に低い==ため、代わりに不等式を使用して比較することをお勧めします。

(c) 日の出が到着するまで、ループは CPU を 100% 駆動して、日の出がまだ到着しているかどうかを 1 秒間に何千回もチェックしているように見えます。time.sleep(1)Raspberry Pi をより涼しく保つために待っている間に、そうしたいかもしれません。

于 2014-03-09T16:39:24.887 に答える