Closed mlivai closed 1 year ago
def setupCamera():
#Sets up Camera
#Sets resolutions of camera to highest resolution
camera.resolution = (2592, 1944)
#Sets framerate to support highest resolution
camera.framerate = 15
[Reference: 2]
def takePicture():
#takes a still (image) using camera
#starts live display of cameras input
camera.start_preview()
#delay of 5 seconds
sleep(5)
#captures the still and saves it to desktop
campera.capture('/home/pi/Desktop/piimage.jpg')
#stops camera input
camera.stop_preview()
print("A picture was taken.")
[Reference: 1 & 2]
Make sure you change campera.capture('/home/pi/Desktop/piimage.jpg') when we need to take more than one photo
Functions imported into KibbleKounter.py (No library install required):
from time import sleep
from picamera import PiCamera
picamera object defined outside of functions:
camera = None
Updated function to return picamera object:
def setupCamera():
#Sets up Camera
camera = PiCamera()
#Sets resolutions of camera to highest resolution
camera.resolution = (2592, 1944)
#Sets framerate to support highest resolution
camera.framerate = 15
return camera
[Reference: 1]
Updated function to take a camera object, filename as a parameter and return the file path:
def takePicture(camera, filename):
#takes a still (image) using camera
#starts live display of cameras input
camera.start_preview()
#captures the still and saves it to desktop
camera.capture('/home/pi/Desktop/%s.jpg' % filename)
#stops camera input
camera.stop_preview()
return ('/home/pi/Desktop/%s.jpg' % filename)
[Reference: 1 & 2]
Code for demo.py:
import KibbleKounter
import time
camera = KibbleKounter.setupCamera()
fname= KibbleKounter.takePicture(camera,'picture1')
print (fname)
Instructions for running demo.py:
cd Kibble-Kounter1
nano demo.py
python3 demo.py
. The file path should be printed.
Good job!
(0.5 hr) Fill in the "dummy" functions you defined earlier with real, working code. Include instructions for testing the code by running demo.py (what should happen when you run it?)