diff --git a/README.md b/README.md index 7d2afd1..5703414 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ Touchless 3D Tracking =================== ----- This is based on an original project by [Kyle Mc Donald](https://github.com/kylemcdonald) : http://www.instructables.com/id/DIY-3D-Controller/. -Our slightly adapted setup is documented on my hacklab website [hackens.org](http://hackens.org/). All the documentation can be found here : **(documentation to be written)**. +Our slightly adapted setup is documented on my hacklab website [hackens.org)](http://hackens.org/) (in french, I may write english doc if some people are interested in that). All the documentation can be found here : http://hackens.org/Projets/TouchlessTracking **(in french, documentation will be written soon, after some extra tests)**. In this repository, you'll find : @@ -30,21 +29,40 @@ You'll also find some basic Python scripts as examples on possible use of the se This script represents the position of your hand in the RGB space. You can then pick a color by placing your hand at a specific point in the box of the electrodes. +### Chorizo.py + +__(working on)__ + +A script to play music using chorizo pads as a musical keyboard. See [our website](http://hackens.org/Projets/TouchlessTracking) (french, but vids are available, more coming soon) for infos and demos. + +### 3d_view.py + +__(working on)__ + +Same as _colors.py_ but represents the position in real space (cube view) rather than in RGB space. + ### Some ideas (TODO List) -* Same as colors.py but representing it with a 3D view. * Then, use the previous code as a control interface for your computer, just like Minority Report :) * Other ideas ? It's up to you :) ## Note about the license -# ============================================================================ -# All the scripts in this repository are released under a very permissive -# license. To make a long story short : do whatever you want with these -# scripts (but try to have fun :), I don't mind. It would be cool to quote -# the origin of the script if you reuse it, but you don't have to. I'd like to -# be noticed of what you did cool with it (if you think it's worth). :) -# Ah, I almost forgot : If by chance we ever meet and you think this script is -# worth, you can buy me a soda :) -# -# Phyks -# ============================================================================= + +TLDR; I don't give a damn to anything you can do using this code. It would just +be nice to quote where the original code comes from. + +* ----------------------------------------------------------------------------- +* "THE NO-ALCOHOL BEER-WARE LICENSE" (Revision 42): +* Phyks (webmaster@phyks.me) wrote this file. As long as you retain this notice +* you can do whatever you want with this stuff (and you can also do whatever +* you want with this stuff without retaining it, but that's not cool...). If we +* meet some day, and you think this stuff is worth it, you can buy me a +* beer soda in return. +* Phyks +* ------------------------------------------------------------------------------ + +## Thanks + +* `Baltazar` from hackEns for his help to set it up and for the original idea. +* [Kyle Mc Donald](https://github.com/kylemcdonald) for his documentation on his setup +* [PRKTRNIC](http://vimeo.com/68763028) (video in french) for the idea about playing music with chorizo and sausages ! diff --git a/chorizo.py b/chorizo.py new file mode 100755 index 0000000..61a13d3 --- /dev/null +++ b/chorizo.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import wave +import math +import pyaudio + +NomFichier = "temp" +Monson = wave.open(NomFichier, 'w') + +channels = 1 # Mono +sample_size = 1 # Size of a sample -> 8 bits +sampling_freq = 44100 # Sampling frequency + +freq = 440 # Note frequency +length = 5 # Length of the note in seconds +level = 150 # Between 0 (max < 0) and 255 (max > 0), 0 is 127 + +sample_number = int(length*sampling_freq) + +parameters = (channels, sample_size, sampling_freq, sample_number, 'NONE', + 'not compressed') + +Monson.setparams(parameters) # File header + +for i in range(0, sample_number): + value = int(128.0+level*math.sin(2.0*math.pi*freq*i/sampling_freq)) + wave.struct.pack('h', value) + + Monson.close() + +wf = open(NomFichier, 'rb') + +p = pyaudio.PyAudio() + +stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), + channels=wf.getnchannels(), + rate=wf.getframerate(), + output=True) + +data = wf.readframes(CHUNK) + +while data != '': + stream.write(data) + data = wf.readframes(CHUNK) + +stream.stop_stream() +stream.close() + +p.terminate() diff --git a/music.py b/music.py deleted file mode 100755 index 99951c9..0000000 --- a/music.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/env python - -# NOTE : This script is *not* working yet... - -# ============================================================================ -# I had to play "Petit papa Noël" in an original way for some events. So, why -# not using these cool electrodes to handle it ? Left hand would control the -# volume and right hand, the note which is played. -# -# Disclaimer : Even with a lot of practice, I'm not sure you will be able to -# play a nice with this script :) -# -# As all the other scripts in this repository, I release it under a very -# permissive license. To make a long story short : do whatever you want with -# this script (but try to have fun :), I don't mind. It would be cool to quote -# the origin of the script if you reuse it, but you don't have to. I'd like to -# be noticed of what you did cool with it (if you think it's worth). :) -# Ah, I almost forgot : If by chance we ever meet and you think this script is -# worth, you can buy me a soda :) -# -# Phyks -# ============================================================================= - -import serial -import pygame -import sys -import getopt - - -serial_port = "/dev/ttyACM0" - -try: - opts, args = getopt.getopt(sys.argv[1:], "hs:", ["help", "serial="]) - - for opt, arg in opts: - if opt == "-h" or opt == "-help": - print("Touchless 3D tracking with color mapping") - print("\nUsage : "+sys.argv[0]+" [OPTIONS]") - print("\nTrack the position of your hand in 3D and map it " + - "in RGB space") - print("\nOptions :") - print("\t-h (--help) \t display this help message") - print("\t-s (--serial) \t change serial port (default is " + - "/dev/tty/ACM0") - sys.exit(0) - elif opt in ("-s", "--serial"): - serial_port = arg -except getopt.GetoptError: - pass - -ser = serial.Serial(serial_port, 115200) - -try: - ser.open() -except Exception as e: - print("Error while opening serial port : "+str(e)) - -if ser.isOpen(): - try: - ser.flushInput() - ser.flushOutput() - - print("Calibration :") - print("Press any key to launch the program when calibration is " + - "finished.") - running = True - while running: - for event in pygame.event.get(): - if event.type == pygame.KEYDOWN: - running = False - continue - - line = ser.readline() - line = line.decode().strip("\r\n") - line = line.split(" ") - line = [int(j or 0) for j in line] - - for i in range(3): - if line[i] < minimum[i] or minimum[i] < 0: - minimum[i] = line[i] - if line[i] > maximum[i]: - maximum[i] = line[i] - - print(line) - - print("Running...") - running = True - while running: - # Read line from serial - line = ser.readline() - line = line.decode().strip("\r\n") - line = line.split(" ") - line = [int(j or 0) for j in line] - - # Compute the value for red - value[1] = value[0] - value[0] = compute_value(line, minimum, maximum) - value_bg = [(value[0][i] + value[1][i])/2 for i in range(3)] - value_text = [255 - i for i in compute_value(line, minimum, - maximum)] - - ser.close() - except Exception as e: - print("Error while fetching data from serial : "+str(e))