Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
LED-MATRIX/*
ledmatrix/*
*.swp
*.swo
*.pyc
**/.idea
Binary file added .webcam_pi_reciever.py.swp
Binary file not shown.
Binary file added .webcam_to_pi.py.swp
Binary file not shown.
67 changes: 67 additions & 0 deletions CV2_Movement/track_movement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from __future__ import print_function
import time
from imutils.video import WebcamVideoStream
from imutils.video import FPS
import imutils
import cv2
import websocket
import numpy as np
import pafy

w = 16 # width of pixel matrix
h = 12 # height of pixel matrix
host = "ws://192.168.254.81:5555"

def adjust_gamma(image, gamma=1.0):
# build a lookup table mapping the pixel values [0, 255] to
# their adjusted gamma values
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")

# apply gamma correction using the lookup table
return cv2.LUT(image, table)

stream = 0
vector1d = 0
new_pos = 0
max_pixels = 640*480

def threaded():
kernel = np.ones((5,5), np.uint8)
global vector1d
global new_pos
cap = WebcamVideoStream(stream).start()
fgbg = cv2.createBackgroundSubtractorMOG2()
print("Displaying image")

while True:
frame = cap.read()
fgmask = fgbg.apply(frame)
erosion = cv2.erode(fgmask, kernel, iterations = 1)
avg_white = np.argwhere(erosion == 255).tolist()
old_pos = new_pos

try:
if avg_white[0] and len(avg_white)>100:
ws = websocket.create_connection(host)
new_pos = np.mean([x[1] for x in avg_white])
vector1d = old_pos-new_pos
print(old_pos, new_pos)
send_text = "y_drift:{}".format(20*np.interp(vector1d, [-200,200], [-1,1]))
print(send_text)
ws.send(send_text)
except:
pass
#frame = adjust_gamma(frame, .2)
cv2.imshow("Frame", frame)
cv2.imshow("fg", erosion)
key = cv2.waitKey(1) & 0xff
if key == 27:
break
cv2.destroyAllWindows()
cap.stop()


if __name__ == '__main__':
threaded()
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions CV2_Movement/webstream_move_detect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from __future__ import print_function
import time
from imutils.video import WebcamVideoStream
from imutils.video import FPS
import imutils
import cv2
import websocket
import numpy as np
import pafy

w = 16 # width of pixel matrix
h = 12 # height of pixel matrix
host = "ws://192.168.254.81:5555"

def adjust_gamma(image, gamma=1.0):
# build a lookup table mapping the pixel values [0, 255] to
# their adjusted gamma values
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")

# apply gamma correction using the lookup table
return cv2.LUT(image, table)

stream = 0
vector1d = 0
new_pos = 0
max_pixels = 640*480

def threaded():
kernel = np.ones((5,5), np.uint8)
global vector1d
global new_pos
cap = WebcamVideoStream(stream).start()
fgbg = cv2.createBackgroundSubtractorMOG2()
print("Diplaying image")

while True:
frame = cap.read()
fgmask = fgbg.apply(frame)
erosion = cv2.erode(fgmask, kernel, iterations = 1)
avg_white = np.argwhere(erosion == 255).tolist()
old_pos = new_pos

try:
if avg_white[0] and len(avg_white)>100:
ws = websocket.create_connection(host)
new_pos = np.mean([x[1] for x in avg_white])
vector1d = old_pos-new_pos
print(old_pos, new_pos)
send_text = "y_drift:{}".format(20*np.interp(vector1d, [-200,200], [-1,1]))
print(send_text)
ws.send(send_text)
except:
pass
#frame = adjust_gamma(frame, .2)
cv2.imshow("Frame", frame)
cv2.imshow("fg", erosion)
key = cv2.waitKey(1) & 0xff
if key == 27:
break
cv2.destroyAllWindows()
cap.stop()


if __name__ == '__main__':
threaded()
1 change: 1 addition & 0 deletions Perlin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
25 changes: 25 additions & 0 deletions Perlin/clear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import config
import argparse
import time
from neopixel import *

def colorWipe(strip, color, wait_ms=50):
"""Wipe color across display a pixel at a time."""
for i in range(25):
strip.setPixelColor(i, color)
strip.show()
time.sleep(wait_ms/1000.0)

if __name__ == "__main__":

# def opt_parse():
parser = argparse.ArgumentParser()
parser.add_argument('-c', action='store_true', help='clear the display on exit')
parser.add_argument('profile', type=str, help='profile name from config.json')
args = parser.parse_args()
if not args.profile:
print("no profile")
fixture = config.load(args.profile)
strip = Adafruit_NeoPixel(fixture["LED_COUNT"], fixture["LED_PIN"], fixture["LED_FREQ_HZ"], fixture["LED_DMA"], fixture["LED_INVERT"], fixture["LED_BRIGHTNESS"], fixture["LED_CHANNEL"], ws.WS2811_STRIP_RGB)
strip.begin()
colorWipe(strip, Color(0,0,0), 10)
10 changes: 10 additions & 0 deletions Perlin/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"5x5":{
"xsize": 5,
"ysize": 5
},
"16x14":{
"xsize": 16,
"ysize": 14
}
}
File renamed without changes.
16 changes: 8 additions & 8 deletions perlin_2d.py → Perlin/perlin_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def opt_parse():
signal.signal(signal.SIGINT, signal_handler)

# LED strip configuration:
LED_COUNT = 144 # Number of LED pixels.
LED_COUNT = 25 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
#LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
Expand All @@ -35,19 +35,19 @@ def opt_parse():
# h = int(LED_COUNT/w) # height of pixel matrix
#
# def interp(val, smin=0.0, smax=100.0, tmin=0.0, tmax=1.0):
w = 12 # width of pixel matrix
h = 16 # height of pixel matrix
mag = 10 # magnification/scale of perlin field
w = 5 # width of pixel matrix
h = 5 # height of pixel matrix
mag = 3 # magnification/scale of perlin field
octaves = 2
timing = 0.001
timing = 0.0001
min_bright = 0
max_bright = 255
max_bright = 200
x_drift = 0
y_drift = 1000
x_stretch = 1
y_stretch = 1
red_offset = 1000
green_offset = 100
green_offset = 500

def interp(val, smin=0.0, smax=100.0, tmin=0.0, tmax=1.0, power=1):
return((((abs(val)-smin)*(tmax-tmin))/(smax-smin))+tmin)
Expand Down Expand Up @@ -102,4 +102,4 @@ def display_img(count, strip):
while True:
display_img(count, strip)
count += timing
#print(array(img))
# print(array(count))
61 changes: 40 additions & 21 deletions perlin_asyncio_2d.py → Perlin/perlin_asyncio_2d.bak.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,51 @@
import time
import threading
import websockets
import socket
import asyncio
import json

from neopixel import *

import argparse
import signal
import sys

args = {}

def get_ip():
""" go through hostnames, kick out '127.0.0.1', return IP address"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0]
except:
IP = '127.0.0.1'
finally:
s.close()
return IP


with open('/home/pi/ledmatrix/Perlin/config.json') as json_data_file:
data = json.load(json_data_file)
print(data)

def signal_handler(signal, frame):
colorWipe(strip, Color(0,0,0))
sys.exit(0)

def opt_parse():
parser = argparse.ArgumentParser()
parser.add_argument('-c', action='store_true', help='clear the display on exit')
args = parser.parse_args()
if args.c:
signal.signal(signal.SIGINT, signal_handler)

def get_ip():
ts = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ts.connect(("8.8.8.8", 80))
ip_ = ts.getsockname()[0]
ts.close()
return(ip_)

# def opt_parse():
parser = argparse.ArgumentParser()
parser.add_argument('-c', action='store_true', help='clear the display on exit')
parser.add_argument('profile', type=str, help='profile name from config.json')
args = parser.parse_args()
if not args.profile:
print("no profile")
if args.c:
signal.signal(signal.SIGINT, signal_handler)

# LED strip configuration:
LED_COUNT = 12*16 # Number of LED pixels.
LED_COUNT = data[args.profile]['xsize']*data[args.profile]['ysize'] # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
#LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
Expand All @@ -42,11 +59,12 @@ def get_ip():
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
LED_STRIP = ws.WS2811_STRIP_RGB # Strip type and colour ordering

h = 12 # height of pixel matrix
w = int(LED_COUNT/h) # width of pixel matrix
h = 5 # height of pixel matrix
w = int(LED_COUNT/h) # width of pixel matrix
host = get_ip()
print(host)
led_vars = {
"mag":8,
"mag":1,
"octaves": 2,
"timing":0.002,
"min_bright": 0,
Expand Down Expand Up @@ -110,23 +128,24 @@ def interp(val, smin=0.0, smax=100.0, tmin=0.0, tmax=1.0):

strip.setPixelColor(led_index,
Color(redColor, greenColor, blueColor ))
strip.show()

async def display_img(strip):
count = 0
while 1:
await build_matrix(count, **led_vars)
count += led_vars['timing']
strip.show()

# Main program logic follows:
if __name__ == '__main__':
# Process arguments
opt_parse()
# args = opt_parse()
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP)
# Intialize the library (must be called once before other functions).
strip.begin()


print(args.profile)
start_server = websockets.serve(listen, host, 5555)
loop = asyncio.get_event_loop()
# loop.run_until_complete(asyncio.gather(start_server, display_img(strip)))
Expand Down
Loading