forked from XPUB/si_7-IRIS
add the files. Up and running
parent
04490a36c7
commit
b99136a813
@ -0,0 +1,9 @@
|
|||||||
|
announcements_position.txt
|
||||||
|
Audio_recordings/**
|
||||||
|
**.jpg
|
||||||
|
**.pyc
|
||||||
|
LED-strips/**
|
||||||
|
__pycache__/**
|
||||||
|
trash/**
|
||||||
|
|
||||||
|
|
@ -0,0 +1,131 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import Adafruit_WS2801
|
||||||
|
import Adafruit_GPIO.SPI as SPI
|
||||||
|
import time
|
||||||
|
|
||||||
|
# count of pixels:
|
||||||
|
PIXEL_COUNT = 19
|
||||||
|
|
||||||
|
# specify a hardware SPI connection on /dev/spidev0.0:
|
||||||
|
SPI_PORT = 0
|
||||||
|
SPI_DEVICE = 0
|
||||||
|
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
|
||||||
|
|
||||||
|
|
||||||
|
# colors of each character
|
||||||
|
color_guru = [146, 200, 0] # purple
|
||||||
|
color_pirate = [255, 0, 200] # yellow
|
||||||
|
color_announcer= [0, 100, 200] # aqua blue
|
||||||
|
|
||||||
|
def leds_color_intensity(color, intensity):
|
||||||
|
# color: a list of 3 rgb components 0 to 255
|
||||||
|
# intensity: between 0 and 1
|
||||||
|
# pixN: number of pixels
|
||||||
|
r = color[0]
|
||||||
|
g = color[1]
|
||||||
|
b = color[2]
|
||||||
|
for i in range(PIXEL_COUNT):
|
||||||
|
pixels.set_pixel_rgb(i,
|
||||||
|
int(r*intensity),
|
||||||
|
int(g*intensity),
|
||||||
|
int(b*intensity) ) # Set the RGB color (0-255) of pixel i
|
||||||
|
pixels.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# LEDs grow and shrink
|
||||||
|
def leds_color_length(color, intensity):
|
||||||
|
# color: a list of 3 rgb components 0 to 255
|
||||||
|
# intensity: between 0 and 1
|
||||||
|
# pixN: number of pixels
|
||||||
|
r = color[0]
|
||||||
|
g = color[1]
|
||||||
|
b = color[2]
|
||||||
|
led_length = int(PIXEL_COUNT * intensity)
|
||||||
|
for i in range(led_length):
|
||||||
|
pixels.set_pixel_rgb(i,
|
||||||
|
int(r),
|
||||||
|
int(g),
|
||||||
|
int(b) ) # Set the RGB color (0-255) of pixel i
|
||||||
|
time.sleep(0.01)
|
||||||
|
pixels.show()
|
||||||
|
pixels.clear()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# LEDS for pirate
|
||||||
|
def leds_pirate_blink(color):
|
||||||
|
# color: a list of 3 rgb components 0 to 255
|
||||||
|
# pixN: number of pixels
|
||||||
|
r = color[0]
|
||||||
|
g = color[1]
|
||||||
|
b = color[2]
|
||||||
|
while True:
|
||||||
|
|
||||||
|
pixels.clear()
|
||||||
|
pixels.show()
|
||||||
|
|
||||||
|
time.sleep(0.02)
|
||||||
|
for i in range(PIXEL_COUNT):
|
||||||
|
pixels.set_pixel_rgb(i,
|
||||||
|
int(r),
|
||||||
|
int(g),
|
||||||
|
int(b) ) # Set the RGB color (0-255) of pixel i
|
||||||
|
|
||||||
|
pixels.show()
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
|
def leds_pirate_circle(color):
|
||||||
|
# color: a list of 3 rgb components 0 to 255
|
||||||
|
# pixN: number of pixels
|
||||||
|
r = color[0]
|
||||||
|
g = color[1]
|
||||||
|
b = color[2]
|
||||||
|
while True:
|
||||||
|
|
||||||
|
for i in range(PIXEL_COUNT):
|
||||||
|
pixels.set_pixel_rgb(i,
|
||||||
|
int(r),
|
||||||
|
int(g),
|
||||||
|
int(b) ) # Set the RGB color (0-255) of pixel i
|
||||||
|
pixels.show()
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
pixels.clear()
|
||||||
|
pixels.show()
|
||||||
|
time.sleep(0.3)
|
||||||
|
|
||||||
|
|
||||||
|
def leds_pirate_bounce(color):
|
||||||
|
# color: a list of 3 rgb components 0 to 255
|
||||||
|
# pixN: number of pixels
|
||||||
|
r = color[0]
|
||||||
|
g = color[1]
|
||||||
|
b = color[2]
|
||||||
|
leds = list(range(PIXEL_COUNT))+ (list(range(PIXEL_COUNT))[::-1])
|
||||||
|
n = 0
|
||||||
|
while True:
|
||||||
|
n = n + 1
|
||||||
|
for i in leds:
|
||||||
|
pixels.set_pixel_rgb(i,
|
||||||
|
int(r),
|
||||||
|
int(g),
|
||||||
|
int(b) ) # Set the RGB color (0-255) of pixel i
|
||||||
|
pixels.show()
|
||||||
|
time.sleep(0.01)
|
||||||
|
pixels.clear()
|
||||||
|
pixels.show()
|
||||||
|
time.sleep(0.3)
|
||||||
|
|
||||||
|
if n > 3:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
pixels.clear() # Clear all the pixels to turn them off.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
## IRIS
|
||||||
|
|
||||||
|
* scripts locations /var/www/html/lifeHackAgent
|
||||||
|
* audio recording script /var/www/html/lifeHackAgent/Audio_recordings
|
||||||
|
|
||||||
|
## test system:
|
||||||
|
* `./motion.sh`
|
||||||
|
|
||||||
|
## cronjob:
|
||||||
|
runs announcements.py
|
||||||
|
|
||||||
|
|
||||||
|
# systemd service file
|
||||||
|
* run on boot
|
||||||
|
* location: /lib/systemd/system/lifehack.service
|
||||||
|
* status: sudo systemctl ststatus lifehack.service
|
||||||
|
* start: sudo systemctl start lifehack.service
|
||||||
|
* stop: sudo systemctl stop lifehack.service
|
@ -0,0 +1,87 @@
|
|||||||
|
# import the necessary packages
|
||||||
|
import imutils
|
||||||
|
from imutils.video import VideoStream
|
||||||
|
import argparse
|
||||||
|
import datetime
|
||||||
|
import time, sys
|
||||||
|
from time import sleep
|
||||||
|
import cv2
|
||||||
|
|
||||||
|
# construct the argument parser and parse the arguments
|
||||||
|
ap = argparse.ArgumentParser()
|
||||||
|
ap.add_argument("-a", "--min-area", type=int, default=5000, help="minimum area size")
|
||||||
|
args = vars(ap.parse_args())
|
||||||
|
|
||||||
|
# using picamera as default
|
||||||
|
vs = VideoStream(usePiCamera=True).start()
|
||||||
|
sleep(2.0)
|
||||||
|
|
||||||
|
# initialize the first frame in the video stream
|
||||||
|
firstFrame = None
|
||||||
|
occupied = False
|
||||||
|
# loop over the frames of the video
|
||||||
|
while True:
|
||||||
|
# grab the current frame and initialize the occupied/unoccupied
|
||||||
|
# text
|
||||||
|
frame = vs.read()
|
||||||
|
frame = frame if args.get("video", None) is None else frame[1]
|
||||||
|
text = "Unoccupied"
|
||||||
|
# if the frame could not be grabbed, then we have reached the end
|
||||||
|
# of the video
|
||||||
|
if frame is None:
|
||||||
|
break
|
||||||
|
|
||||||
|
# resize the frame, convert it to grayscale, and blur it
|
||||||
|
frame = imutils.resize(frame, width=500)
|
||||||
|
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||||
|
gray = cv2.GaussianBlur(gray, (210, 210), 0)
|
||||||
|
|
||||||
|
# if the first frame is None, initialize it
|
||||||
|
if firstFrame is None:
|
||||||
|
firstFrame = gray
|
||||||
|
continue
|
||||||
|
|
||||||
|
# compute the absolute difference between the current frame and
|
||||||
|
# first frame
|
||||||
|
frameDelta = cv2.absdiff(firstFrame, gray)
|
||||||
|
thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
|
||||||
|
|
||||||
|
# dilate the thresholded image to fill in holes, then find contours
|
||||||
|
# on thresholded image
|
||||||
|
thresh = cv2.dilate(thresh, None, iterations=2)
|
||||||
|
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
|
||||||
|
cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
|
||||||
|
|
||||||
|
# loop over the contours
|
||||||
|
for c in cnts:
|
||||||
|
# if the contour is too small, ignore it
|
||||||
|
if cv2.contourArea(c) < args["min_area"]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# compute the bounding box for the contour, draw it on the frame,
|
||||||
|
# and update the text
|
||||||
|
(x, y, w, h) = cv2.boundingRect(c)
|
||||||
|
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
||||||
|
text = "Occupied"
|
||||||
|
if not occupied:
|
||||||
|
occupied = True
|
||||||
|
print ('occupied')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if occupied and text == "Unoccupied":
|
||||||
|
occupied = False
|
||||||
|
print ("Unoccupied")
|
||||||
|
|
||||||
|
# show the frame and record if the user presses a key
|
||||||
|
# cv2.imshow("Security Feed", frame)
|
||||||
|
cv2.imwrite('normal.jpg', frame)
|
||||||
|
#cv2.imshow("Thresh", thresh)
|
||||||
|
cv2.imwrite('thereshold.jpg', thresh)
|
||||||
|
#cv2.imshow("Frame Delta", frameDelta)
|
||||||
|
cv2.imwrite('Gaussianblur.jpg', frameDelta)
|
||||||
|
#key = cv2.waitKey(1) & 0xFF
|
||||||
|
|
||||||
|
# cleanup the camera and close any open windows
|
||||||
|
vs.stop() if args.get("video", None) is None else vs.release()
|
||||||
|
#cv2.destroyAllWindows()
|
@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Life hack motion activation on reboot
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/bin/sh /var/www/html/lifeHackAgent/motion.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
DIR=/var/www/html/lifeHackAgent/
|
||||||
|
while [ 1 ]
|
||||||
|
do
|
||||||
|
python "$DIR"motion_detector_2.py -a 10
|
||||||
|
python "$DIR"guru-pirate.py
|
||||||
|
sleep 10
|
||||||
|
done
|
@ -0,0 +1,97 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# coding=utf-8
|
||||||
|
# USAGE
|
||||||
|
# python motion_detector.py
|
||||||
|
# python motion_detector.py --video videos/example_01.mp4
|
||||||
|
|
||||||
|
# import the necessary packages
|
||||||
|
import imutils
|
||||||
|
from imutils.video import VideoStream
|
||||||
|
import argparse
|
||||||
|
import datetime
|
||||||
|
import time, sys
|
||||||
|
from time import sleep
|
||||||
|
import cv2
|
||||||
|
|
||||||
|
# construct the argument parser and parse the arguments
|
||||||
|
ap = argparse.ArgumentParser()
|
||||||
|
ap.add_argument("-a", "--min-area", type=int, default=6000, help="minimum area size")
|
||||||
|
args = vars(ap.parse_args())
|
||||||
|
|
||||||
|
# if the video argument is None, then we are reading from webcam
|
||||||
|
vs = VideoStream(usePiCamera=True).start()
|
||||||
|
sleep(2.0)
|
||||||
|
|
||||||
|
# initialize the first frame in the video stream
|
||||||
|
firstFrame = None
|
||||||
|
occupied = False
|
||||||
|
# loop over the frames of the video
|
||||||
|
while True:
|
||||||
|
# grab the current frame and initialize the occupied/unoccupied
|
||||||
|
# text
|
||||||
|
frame = vs.read()
|
||||||
|
frame = frame if args.get("video", None) is None else frame[1]
|
||||||
|
text = "Unoccupied"
|
||||||
|
# if the frame could not be grabbed, then we have reached the end
|
||||||
|
# of the video
|
||||||
|
if frame is None:
|
||||||
|
break
|
||||||
|
|
||||||
|
# resize the frame, convert it to grayscale, and blur it
|
||||||
|
frame = imutils.resize(frame, width=500)
|
||||||
|
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||||
|
gray = cv2.GaussianBlur(gray, (21, 21), 0)
|
||||||
|
|
||||||
|
# if the first frame is None, initialize it
|
||||||
|
if firstFrame is None:
|
||||||
|
firstFrame = gray
|
||||||
|
continue
|
||||||
|
|
||||||
|
# compute the absolute difference between the current frame and
|
||||||
|
# first frame
|
||||||
|
frameDelta = cv2.absdiff(firstFrame, gray)
|
||||||
|
thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
|
||||||
|
|
||||||
|
# dilate the thresholded image to fill in holes, then find contours
|
||||||
|
# on thresholded image
|
||||||
|
thresh = cv2.dilate(thresh, None, iterations=2)
|
||||||
|
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
|
||||||
|
cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
|
||||||
|
|
||||||
|
# loop over the contours
|
||||||
|
for c in cnts:
|
||||||
|
# if the contour is too small, ignore it
|
||||||
|
if cv2.contourArea(c) < args["min_area"]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# compute the bounding box for the contour, draw it on the frame,
|
||||||
|
# and update the text
|
||||||
|
(x, y, w, h) = cv2.boundingRect(c)
|
||||||
|
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
||||||
|
text = "Occupied"
|
||||||
|
if not occupied:
|
||||||
|
occupied = True
|
||||||
|
print ('occupied')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if occupied and text == "Unoccupied":
|
||||||
|
occupied = False
|
||||||
|
print ("Unoccupied")
|
||||||
|
|
||||||
|
# # show the frame and record if the user presses a key
|
||||||
|
# # cv2.imshow("Security Feed", frame)
|
||||||
|
# cv2.imwrite('security.jpg', frame)
|
||||||
|
# #cv2.imshow("Thresh", thresh)
|
||||||
|
# cv2.imwrite('threshold.jpg', thresh)
|
||||||
|
# #cv2.imshow("Frame Delta", frameDelta)
|
||||||
|
# cv2.imwrite('blured.jpg', frameDelta)
|
||||||
|
# #key = cv2.waitKey(1) & 0xFF
|
||||||
|
#
|
||||||
|
# # if the `q` key is pressed, break from the lop
|
||||||
|
# #if key == ord("q"):
|
||||||
|
# # break
|
||||||
|
|
||||||
|
# cleanup the camera and close any open windows
|
||||||
|
vs.stop() if args.get("video", None) is None else vs.release()
|
||||||
|
#cv2.destroyAllWindows()
|
Loading…
Reference in New Issue