Taking Pictures and Videos w/ your RaspPi
~~~~
~~~~
- Start up your RP and get the home screen on your monitor
* My monitor wouldn’t turn on and it was because the MicroSD card wasn’t in properly make sure to check everything thinking your RP is broken….*
- Go to the main menu and click on the first option, programming, then go down to the 7th option of Python 3 (IDLE)
- We are first going to preview the camera to check to see if it works properly before taking a picture
- Make a new file and name it ‘camera.py’
- Put into your new program
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(10)
camera.stop_preview()
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(10)
camera.stop_preview()
- Then save your program with either File, Save or pressing ctrl+shift
- Run your program with F5 or in the menu click Run then the third option of Run Module
- It doesn’t work immediately so be patient it took mine maybe 5 seconds then it the screen of my monitor showed what my camera was capturing for 10 seconds like we specified in the program
*My camera was showing me upside down so to flip it I edited my program by adding the code ‘camera.rotation = 180’ right after ‘camera = Picamera()’ and right before ‘camera.start_preview()’ this should flip your camera although you can change the 180 to any number of degrees you need to turn your camera…. If you are interested there is a way to change the transparency also by adding inside the parenthesis of the code ‘camera.start_preview()’ alpha and then a number from 0 to 255.*
- Now we will actually take a picture:
- Change your code so it looks like this:
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
**Make sure to sleep for at least 2 seconds so the camera can adjust to the surrounding lighting
- To take a second picture just add a one to the ‘image.jpg’ at the end of the camera.capture line so it looks like this:
camera.capture('/home/pi/Desktop/image1.jpg')
- So that your pictures are all saved on the desktop, remember to save them each with a different number after the image in ‘image.jpg’
Now let’s take a video:
- Change your code to look like this:
camera.start_preview()
camera.start_recording('/home/pi/video.h264')
sleep(10)
camera.stop_recording()
camera.stop_preview()
camera.start_recording('/home/pi/video.h264')
sleep(10)
camera.stop_recording()
camera.stop_preview()
- Replace the picture taking command ‘capture’ with ‘start_recording()’ and ‘stop_recording()’
- This should take a 10 second video
- Once it has finished recording open the terminal screen by clicking the terminal icon in the top the third icon away from the main menu raspberry icon
- Type in the command:
omxplayer video.h264
- And you should see your video although it may play faster than it was actually taken because of the faster frame rate
- To look at more camera adjusting options go to the website below under sources
Souces:
https://www.raspberrypi.org/learning/getting-started-with-picamera/worksheet/
Comments
Post a Comment