[Swlug] Python camera
Rhys Sage
rhys_sage at yahoo.com
Thu Mar 17 22:50:28 UTC 2022
I came across an odd situation where the recommended solution on the Pi website does not work.
I'm using a Pi 3B+ with Raspbian Buster.
pi at raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster
The sample code I'm using is this:
import camera
import os
import subprocess
rpistr = "ls /media/pi"
proc = subprocess.Popen(rpistr, shell=True, preexec_fn=os.setsid,stdout=subprocess.PIPE)
line = proc.stdout.readline()
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
The camera is Infrared 1080p. Not sure of the model. It's 5 megapixels so probably an older model.
The result I get is...
Python 3.7.3 (/usr/bin/python3)
>>> %Run camera.py
Traceback (most recent call last):
File "/home/pi/Desktop/camera.py", line 1, in <module>
import camera
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 305, in _custom_import
module = self._original_import(*args, **kw)
File "/home/pi/Desktop/camera.py", line 7, in <module>
camera.start_preview()
AttributeError: module 'camera' has no attribute 'start_preview'
At some point I must have had this working because i see some image files. The actual working code seems to have vanished. Unless, of course I produced the images using commandline - which is always possible.
Has anybody any suggestions?
Rhys Sage
More information about the Swlug
mailing list