<jupyter_start><jupyter_text>Raspberry Pi Camera Test First we import the libraries we need and initialize a camera 'object.'<jupyter_code>import os
from picamera import PiCamera
from picamera.color import Color
from time import sleep

camera = PiCamera()
camera.start_preview()
sleep(3)
camera.stop_preview()<jupyter_output><empty_output><jupyter_text>*TADA* ... wait, nothing happened.<jupyter_code>camera.hflip = True
camera.vflip = True
camera.brightness = 50 # the default is 50, but you can set it to whatever.<jupyter_output><empty_output><jupyter_text>How about some text on the image.<jupyter_code>camera.annotate_foreground = Color(1.0,1.0,0.5)
camera.annotate_text = "STEM Camp ROCKS!"
camera.annotate_text_size = 36
camera.start_preview()
sleep(1)
camera.capture('./img/image_test.jpg')
camera.stop_preview()<jupyter_output><empty_output><jupyter_text>How about taking several shots...<jupyter_code>camera.start_preview()
for i in range(5):
    sleep(3)
    camera.capture('./img/image%s.jpg' % i)
camera.stop_preview()<jupyter_output><empty_output><jupyter_text>What about video?<jupyter_code>camera.resolution = (1280, 720)
camera.start_preview()
camera.start_recording('img/videotest.h264')
camera.wait_recording(3)
camera.stop_recording()
camera.stop_preview()<jupyter_output><empty_output><jupyter_text>This did generate a file, but the default format isn't playable through the browser, so...Note: this did require the installation of gpac with:*sudo apt-get install -y gpac*<jupyter_code># convert the video above to something playable through the browser, then delete the original unplayable version.
msg = os.system("MP4Box -fps 30 -add img/videotest.h264 img/videotest2.mp4")
os.remove("img/videotest.h264")
print msg<jupyter_output>0<jupyter_text>Now let's add a calculated annotation to the recording (a timestamp)<jupyter_code>import datetime as dt
camera.resolution = (1280, 720)
camera.framerate = 24
camera.start_preview()
camera.annotate_background = Color('black')
camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
camera.start_recording('img/timestamped2.h264')
start = dt.datetime.now()
while (dt.datetime.now() - start).seconds < 5:
    camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    camera.wait_recording(0.2)
camera.stop_recording()
# convert the video above to something playable through the browser, then delete the original unplayable version.
msg = os.system("MP4Box -fps 30 -add img/timestamped2.h264 img/timestamped2.mp4")
os.remove("img/timestamped2.h264")<jupyter_output><empty_output><jupyter_text>When we're all finished with the camera module, it's a good idea to *close* the object to prevent GPU memory leakage.<jupyter_code>camera.close()
del camera<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12027367662945625, 'fraction_numerical': 0.024486856319769535, 'mean_word_length': 6.610958904109589, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '433070', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 989, 'n_tokens_neox': 934, 'n_words': 225, 'path': '11_camera_intro.ipynb', 'repo_name': 'tvaught/compintro', 'size': '2777'}