ajb974 / Kibble-Kounter1

Apache License 2.0
1 stars 0 forks source link

Camera - Fill in Dummy Functions #11

Closed mlivai closed 1 year ago

mlivai commented 1 year ago

(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?)

mlivai commented 1 year ago

References:

  1. https://projects.raspberrypi.org/en/projects/getting-started-with-picamera/7

  2. https://picamera.readthedocs.io/en/release-1.13/recipes1.html#capturing-to-a-file

mlivai commented 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]

mlivai commented 1 year ago
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]

ajb974 commented 1 year ago

Make sure you change campera.capture('/home/pi/Desktop/piimage.jpg') when we need to take more than one photo

mlivai commented 1 year ago

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

mlivai commented 1 year ago

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]

mlivai commented 1 year ago

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]

mlivai commented 1 year ago

Code for demo.py:

import KibbleKounter
import time

camera = KibbleKounter.setupCamera()
fname= KibbleKounter.takePicture(camera,'picture1')
print (fname) 

Instructions for running demo.py:

  1. Run: cd Kibble-Kounter1
  2. Run: nano demo.py
  3. Define the filename. In this code the file name is 'picture1'.
  4. Run: python3 demo.py. The file path should be printed. Screenshot (640)
  5. The picture should be at the location it states in the file path. In this code it would be '/home/pi/Desktop/picture1.jpg'.
ajb974 commented 1 year ago

Good job!