Example #1
0
def recordingvideo():
    date_recording = '/home/pi/Videos/video_date' + time.strftime(
        "%c") + '.h264'
    camera = picamera.Picamera()
    camera.resolution(640, 480)
    camera.start_recording(date_recording)
    camera.wait_recording(60)
    camera.stop_recording()
Example #2
0
    def snap(self):
        """
        Snap an image and saves it to /static/images/image-**timestamp**.jpg
        """
        filename = generate_filename("jpg")
        with picamera.Picamera() as camera:
            camera.start_preview()
            time.sleep(2)
            camera.capture(filename)
            camera.stop_preview()

        return filename
Example #3
0
    def shoot(self):
        """
        Shoots a video and saves it to /static/videos/video-**timestamp**.h264
        """
        filename = generate_filename('h264', 'videos')
        with picamera.Picamera() as camera:
            camera.resolution = (640, 480)
            camera.start_preview()
            camera.start_recording(filename)
            camera.wait_recording(10)
            camera.stop_recording()
            camera.stop_preview()

        return filename
Example #4
0
def takePic():
    try:
        db = sqlite3.connect('/home/pi/WebBoomEL/pics.db')
        cursor = db.cursor()
        currentTime = time.srtftime('%x %X %Z')
        camera = picamera.Picamera()
        timeTaken = time.strftime("%Y%m%d-%H%M%S")
        pic = camera.capture('static/' + timeTaken + '.jpg')
        camera.close()
        picPath = timeTaken + ".jpg"
        cursor.execute(
            '''INSERT INTO pics(picPath, datetime)
                            VALUES(?,?)''', (picPath, currentTime))
        db.commit()
    except Exception as e:
        db.rollback()
        raise e
    finally:
        db.close()
    return render_template('main.html')
Example #5
0
import SimpleCV
import picamera
cam=picamera.Picamera()
cam.capture('snap1.png')
from SimpleCV import Image
img=Image('snap1.png')
def position():
	crop1=img.crop(60,140,40,200)
	crop2=img.crop(140,140,40,200)
	crop3=img.crop(220,140,40,200)
	crop4=img.crop(300,140,40,200)
	crop5=img.crop(380,140,40,200)
	crop6=img.crop(460,140,40,200)
	crop7=img.crop(540,140,40,200)
	col1=crop1.meanColor()
	col2=crop2.meanColor()
	col3=crop3.meanColor()
	col4=crop4.meanColor()
	col5=crop5.meanColor()
	col6=crop6.meanColor()
	col7=crop7.meanColor()
	m1=-1
	m2=-1
	m3=-1
 	m4=-1
	m5=-1
	m6=-1
	m7=-1
	print col1
	print col2
	print col3
                        pool.append(self)


def streams():
    while not done:
        with lock:
            if pool:
                processor = pool.pop()
            else:
                processor = None
        if processor:
            yield processor.stream
            processor.event.set()
        else:
            time.sleep(0.1)


with picamera.Picamera() as camera:
    pool = [imageProcessor() for i in range(4)]
    camera.resolution = (640, 480)
    camera.framerate = 30
    camera.start_preview()
    time.sleep(2)
    camera.capture_sequence(streams(), use_video_port=True)

with pool:
    with lock:
        processor = pool.pop()
    processor.terminated = True
    processor.join()
Example #7
0
import picamera
import time
import uuid

camera = picamera.Picamera()

camera.resolution = (1920, 1080)
camera.framerate = 60
uuid_str = uuid.uuid4().hex

camera.start_preview()
camera.capture('tem_file%s.jpg' % uuid_str)
camera.stop_preview()
import LCD_Display  # Printing to LCD
import Matrix_Keypad  # Handing the keypad IO
import DHT11  # Temperature and humidity sensor
import PIR  # Pyroelectric Infrared Motion Detector
import LEDs  # LEDs for status and alert
import CO_Sensor  # Carbon Monoxide sensor
import alarm  # Alarm buzzer

#####################################################################

#  Class Instantiations  #
lcd = LCD_Display.AdafruitCharLCD()  # LCD
kp = Matrix_Keypad.Keypad()  # Keypad
pir = PIR.PIR()  # Motion Detector
led = LEDs.LED()  # Status/Alert LEDs
cam = picamera.Picamera()  # Video Camera
co = CO_Sensor.COSensor()  # Carbon Monoxide Sensor
alm = alarm.Alarm()  # Alarm buzzer

# Constants #
NULL_PIN = [0, 0, 0, 0]
DIGITS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
DISABLED = "DISABLED"
ENABLED = "ENABLED"
FAHRENHEIT = "FAHRENHEIT"
CELSIUS = "CELSIUS"


def __main__():

    # Setup LEDs [turns on power LED too] #
#Import necessary modules for Pi Camera module
import picamera
import time

camera = picamera.Picamera() #Define the camera object as camera
camera.capture('example.jpg') #.capture() snaps a quick photo

camera.vflip = True #Flips the camera vertifcally
#.hlip flips the camera horizontally

camera.capture('example 2.jpg')

camera.start_recording('examplevid.h264') #.start_recording records the video
time.sleep(5) #time.sleep() determines the recording duration
camera.stop_recording() #.stop_recording() stops recording the video
Example #10
0
    def __init__(self, motor_limitation=0.6):
        """Init environment

        TODO:
            Add IMU for detecting shock (or crash).

        Notes:
            Hardware:
                RC ECS: Takes 2 PWM signals as inputs to control motor and steering servo.

            Adjust parameters to fit your own car.

        Args:
            motor_limitation (float): A number less than 1. Limiting the motor signal (for safety reason).

        Raises:
            AssertionError: If motor_limitation is greater than 1.
        """
        assert motor_limitation <= 1, '"motor_limitation" should not be greater than 1.'

        # Pin configuration.
        self._STEERING_SERVO_PIN = 4
        self._MOTOR_PIN = 17
        self._LEFT_LINE_SENSOR_PIN = 1
        self._RIGHT_LINE_SENSOR_PIN = 2
        self._ENCODER_DIR_PIN = 12
        self._ENCODER_PUL_PIN = 12
        self._ENCODER_ZERO_PIN = 13
        self._FORWARD_PIN_LEVEL = 1

        # Hardware configuration. TODO: Servo range.
        self._TIRE_DIAMETER = 0.05
        self._GEAR_RATIO = 145. / 35.
        self._ENCODER_LINE = 512
        self._SERVO_RANGE = 200
        self._MOTOR_RANGE = 500

        # Parameters.
        self._SPEED_UPDATE_INTERVAL = 500
        self._REWARD_UPDATE_INTERVAL = 500

        # Set up hardware controlling. TODO: RISING_EDGE or FALLING_EDGE
        os.system('sudo pigpiod')
        time.sleep(1)

        self._pi = pigpio.pi()
        self._pi.set_watchdog(self._ENCODER_PUL_PIN,
                              self._SPEED_UPDATE_INTERVAL)
        self._pi.set_watchdog(self._ENCODER_ZERO_PIN,
                              self._REWARD_UPDATE_INTERVAL)
        self._pi.callback(self._ENCODER_PUL_PIN, pigpio.RISING_EDGE,
                          self._interrupt_handle)
        self._pi.callback(self._ENCODER_ZERO_PIN, pigpio.RISING_EDGE,
                          self._interrupt_handle)
        self._pi.callback(self._LEFT_LINE_SENSOR_PIN, pigpio.RISING_EDGE,
                          self._interrupt_handle)
        self._pi.callback(self._RIGHT_LINE_SENSOR_PIN, pigpio.RISING_EDGE,
                          self._interrupt_handle)

        # TODO: Set up IMU.

        self._update_pwm(0, 0)

        # Set up camera.
        self._image_width, self._image_height = (320, 240)
        self._image = np.empty((self._image_height, self._image_width, 3),
                               dtype=np.float32)

        self._cam = picamera.Picamera()
        self._cam.resolution = 1640, 1232
        self._cam.framerate = 30
        self._cam.exposure_mode = 'sport'
        self._cam.image_effect = 'denoise'
        self._cam.meter_mode = 'backlit'

        self._car_info = {
            'Steering signal': np.array([0], np.float32),
            'Motor signal': np.array([0], np.float32),
            'Reward': np.array([0], np.float32),
            'Car speed': np.array([0], np.float32),
            'Done': False
        }

        self._motor_limitation = motor_limitation

        self._encoder_pulse_count = 0

        # For init agent.
        self.sample_state = np.random.rand(self._image_height,
                                           self._image_width,
                                           3).astype(np.float32)
        self.sample_action = (np.random.rand(2) * 2 - 1).astype(np.float32)
Example #11
0
 def captureContact(self):
     #picamera capture & make file
     with picamera.Picamera() as camera:
         camera.resolution = (1024, 768)
         camera.start_preview()
         camera.capture('1.jpg')
Example #12
0
# Hello dear user :) I recently been challenged to make a security solution without a router
# Making home security a thing without IP camera is a thing apparently but I somehow managed to do something interesting
# Note that this is my very first Python script and I will explain below how it work
#
# Hardware Raspi 3B and IR Camera (ext HDD also couldn't afford the pricey micro SD cards :p)
#
# The script : It make several one hour length video and store it to an external or directly on a raspberry pi
#
# If you want the script to run in a loop I'm using a workaround as I haven't find a way to replace the first file in Range
# Workaround : I've made a simple reboot.sh script and use crontable to make them both run :
#
# sudo crontable -e | @reboot sleep 20 /home/pi/Desktop/myscript.py
#                     @daily /home/pi/Desktop/reboot.sh
# That the thoughts, that way every day when it reboot it simply relaunch the python script with no end
# If anyone have a cleaner solution to replace file without the reboot thingy reach me out.
# I'll try to keep my script updated as I work on them

import picamera
import time
from datetime import datetime

date = datetime.now().strftime("%d-%m-%Y_%I-%M-%S_%p")
path = "Your path"

while True:
    Camera = picamera.Picamera(resolution=(680, 480))
    for filename in camera.record_sequence(
        (path) + (date) + "%d.h264" % i for i in range(1, 49)):
        camera.wait_recording(3600)