1
我一直想我的樹莓派成立了自動拍照,每5秒,該文件保存爲圖像1,圖像2等,這是Python代碼,我一直在努力:樹莓派相機自動捕捉python腳本
import time
import picamera
counter = 0
with picamera.PiCamera() as camera:
for each in range(5):
counter = counter + 1
camera.start_preview()
time.sleep(5)
camera.capture("/home/pi/python/Pictures/image",counter,".jpg")
camera.stop_preview()
但每次我跑這個時候,我得到這個錯誤:
Traceback (most recent call last):
File "/home/pi/python/camera_repeated.py", line 9, in <module>
camera.capture("/home/pi/python/Pictures/image",counter,".jpg")
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1303, in capture
format = self._get_image_format(output, format)
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 684, in _get_image_format
format[6:] if format.startswith('image/') else
AttributeError: 'int' object has no attribute 'startswith'
這看起來像應該工作,我已經測試了它,但它現在說:TypeError:不能將'int'對象隱式轉換爲str – 2014-08-31 13:27:22
我假設當我修復它應該正常工作? – 2014-08-31 13:30:30
哎呀,錯過了從int到字符串的轉換。您需要使用'str(counter)'將int轉換爲字符串才能進行字符串連接。更新了我的答案,所以現在應該真的有效。 – ConcurrentHashMap 2014-08-31 13:30:38