Archive for the 'JMyron' Category

Apr 19 2009

Maestro 0.5b

I've given another last shot to the piano, it's working now. I removed proMIDI from it and implented ess r2, however, i don't have time to work on it anymore. I'm finishing the final report at the moment.

No responses yet

Apr 13 2009

Maestro Version 0.5

Published by Michael Doyle under JMyron, MIDI, Processing, proMIDI

Last ditch attempt at getting the piano version of Maestro working. Unfortunately, I haven't much time to put into it, so it's not really working. What I have got working is, once you place the green tracker over a box, a MIDI not will be played. This also works with the MIDI sequencer also. I've been trying to get the MIDI note working in order to create a grid and assign each cell a note so that a virtual piano can be made. However, there is little time left and a lot to do.

No responses yet

Apr 12 2009

Maestro Version 1.1b

I've revisted version 1.1 as the 1.2's Sine class is making it difficult to add on to at the moment. So, 1.1b is changing the pitch of a sine wave on the Y axis and changing the pitch of a triangle wave on the X axis. Here is the code:

  1. import JMyron.*;
  2. import krister.Ess.*;
  3. import controlP5.*;
  4. JMyron m; //a camera object
  5. ControlP5 controlP5;
  6. AudioChannel myChannel;
  7. AudioChannel myChannel2;
  8. SineWave myWave;
  9. TriangleWave myWave2;
  10. float volume=1;
  11. int pitch=400;
  12. int release=10000;
  13. FadeIn myFadeIn;
  14. FadeOut myFadeOut;
  15.  
  16. FadeIn myFadeIn2;
  17. FadeOut myFadeOut2;
  18.  
  19. LowPass myLowPass;
  20.  
  21. int r;
  22. int g;
  23. int b;
  24. int min_size = 50;
  25. int max_size=100;
  26. int sensitivity = 35;
  27. float objx = 160;
  28. float objy = 120;
  29. float objdestx = 160;
  30. float objdesty = 120;
  31.  
  32. void setup(){
  33. size(720,576);
  34. m = new JMyron();//make a new instance of the object
  35. m.start(width,height);//start a capture at 320x240
  36. m.findGlobs(1);//disable the intelligence to speed up frame rate
  37. controlP5 = new ControlP5(this);
  38. /*
  39.   controlP5.addSlider("sensitivity",0,255,40,10,10,10,100).setId(1);
  40.   name, low val, high val, default val, x, y, width, height,
  41.   */
  42. controlP5.addSlider("sensitivity",0,255,sensitivity,10,10,10,100).setId(1);
  43. controlP5.addSlider("min size",0,800,min_size,60,10,10,100).setId(2);
  44. //controlP5.addSlider("max size",0,400,max_size,100,10,10,100).setId(3);
  45. //println("here are the globs:" + m.globCenters());
  46. Ess.start(this);
  47. myChannel=new AudioChannel();
  48. myChannel2=new AudioChannel();
  49. myFadeIn=new FadeIn();
  50. myFadeOut=new FadeOut();
  51. myFadeIn2=new FadeIn();
  52. myFadeOut2=new FadeOut();
  53.  
  54. }
  55.  
  56. void draw(){
  57. m.update();//update the camera view
  58. m.trackColor(r,g,b,sensitivity);
  59. m.minDensity(min_size);
  60. //m.maxDensity(max_size);
  61. int[] img = m.image(); //get the normal image of the camera
  62.  
  63. loadPixels();
  64. for(int i=0;i<width*height;i++){ //loop through all the pixels
  65. pixels[i] = img[i]; //draw each pixel to the screen
  66. }
  67. updatePixels();
  68.  
  69. stroke(0,255,0);
  70. int[][][] list = m.globEdgePoints(30);//get the outlines
  71. for(int i=0;i
  72. <list.length;i++){
  73. beginShape();
  74. if(list[i]!=null){
  75. for(int ii=0;ii<list[i].length;ii++){
  76. vertex(list[i][ii][0],list[i][ii][1]);
  77. }
  78. }
  79. endShape();
  80. }
  81. int[][] centers = m.globCenters();//get the center points
  82. //draw all the dots while calculating the average.
  83. //println("Amount of globs: " + centers.length);
  84. float avX=0;
  85. float avY=0;
  86. for(int i=0;i<centers.length;i++){
  87. fill(0);
  88. rect(centers[i][0],centers[i][1],1,1);
  89. avX += centers[i][0];
  90. avY += centers[i][1];
  91. }
  92. if(centers.length-1>0){
  93. avX/=centers.length-1;
  94. avY/=centers.length-1;
  95. }
  96.  
  97. //draw the average of all the points in red.
  98. fill(255,0,0);
  99. rect(avX,avY,5,5);
  100.  
  101. //update the location of the thing on the screen.
  102. if(!(avX==0&&avY==0)&&centers.length>0){
  103. objdestx = avX;
  104. objdesty = avY;
  105. }
  106. objx += (objdestx-objx)/5.0f;
  107. objy += (objdesty-objy)/5.0f;
  108.  
  109. fill(30,100,0);
  110. ellipseMode(CENTER);
  111. ellipse(objx,objy,25,25);
  112. //println("X of Glob:" + objx + "Y of Glob:" + objy);
  113. //println("the avx variable:" + avX);
  114. myWave=new SineWave(objy,volume);
  115. myWave2=new TriangleWave(objx,1);
  116.  
  117. myChannel2.initChannel(myChannel2.frames(release));
  118. myChannel.initChannel(myChannel2.frames(release));
  119.  
  120. myWave.generate(myChannel,5,myChannel.frames(release));
  121. myWave2.generate(myChannel2,0,myChannel2.frames(release));
  122.  
  123. myFadeOut.filter(myChannel);
  124. myFadeIn.filter(myChannel);
  125.  
  126. myFadeOut2.filter(myChannel2);
  127. myFadeIn2.filter(myChannel2);
  128. }
  129.  
  130. void controlEvent(ControlEvent theEvent) {
  131. switch(theEvent.controller().id()) {
  132.  
  133. case(1):
  134. sensitivity = (int)(theEvent.controller().value());
  135. print("sensitivity changed to " + sensitivity + "\n");
  136. break;
  137.  
  138. case(2):
  139. min_size = (int)(theEvent.controller().value());
  140. break;
  141.  
  142. case(3):
  143. max_size = (int)(theEvent.controller().value());
  144. break;
  145.  
  146. }
  147.  
  148. }
  149.  
  150. void mouseClicked(MouseEvent m) {
  151. if (mouseEvent.getClickCount() == 2) {
  152. mouseX = m.getX();
  153. mouseY = m.getY();
  154. println("The co-ordinates of the mouse click are:");
  155. println("X:" + mouseX + " Y:" + mouseY);
  156. int c = get(mouseX, mouseY);
  157. r = int(red(c));
  158. g = int(green(c));
  159. b = int(blue(c));
  160. println ("R: " + r + " G: " + g + " B: " + b + " Sens: " + sensitivity);
  161.  
  162. myChannel.play();
  163. myChannel2.play();
  164. return;
  165. }
  166. }
  167.  
  168. public void stop(){
  169. Ess.stop();
  170. m.stop();//stop the object
  171. super.stop();
  172. }

No responses yet

Apr 12 2009

Maestro Version 1.2

Added functionality:

  • Clicking removed when changing frequencies (script from discourse)
  • Drum beat keypress added (keypress D)
  • Recording of sounds (keypress R)
  • Playback of recorded sound (keypress S)

Here's the code:

  1. import JMyron.*; //import JMyron
  2. import krister.Ess.*; //import Ess
  3. import controlP5.*; //import controlP5
  4.  
  5. JMyron m; //create camera object
  6. ControlP5 controlP5; //create controlP5 object
  7. AudioStream speaker; //Create an audiostream object
  8. Sine mSine; //create a sine object from the sine class
  9.  
  10. FadeIn myFadeIn; //create a fadein object
  11. FadeOut myFadeOut; //create a fadeout object
  12.  
  13. boolean recording=false;
  14. AudioFile myFile;
  15. int bytesWritten;
  16. AudioStream myStream;
  17. SineWave myWave;
  18.  
  19. AudioChannel myChannel;
  20. AudioChannel mySound;
  21.  
  22. int r; //intialise the red color as an int
  23. int g; //initialise the green color as an int
  24. int b; //intialise the blue color as an int
  25.  
  26. int min_size = 50;
  27. int max_size=100;
  28. int sensitivity = 50;
  29.  
  30. float objx = 160;
  31. float objy = 120;
  32. float objdestx = 160;
  33. float objdesty = 120;
  34.  
  35. float volume = 0.2;
  36.  
  37. void setup(){
  38. size(720,576);
  39. m = new JMyron();//make a new instance of the object
  40. m.start(width,height); //start a capture with the height and width
  41. m.findGlobs(1); //invoke the findGlobs method on the JMyron object
  42.  
  43. controlP5 = new ControlP5(this); //initiate a controlP5 object
  44. controlP5.addSlider("sensitivity",0,255,sensitivity,10,10,10,100).setId(1); //add a slider to the controlP5 object that will change the sensitivty of trackcolor method of JMyron
  45. controlP5.addSlider("min size",0,800,min_size,60,10,10,100).setId(2); //add a slider to the control P5 object that will change the minimum size of the detectable pixels of the minDensity of JMyron
  46. controlP5.addSlider("volume",0,3,volume,120,10,10,100).setId(3); //add a slider to the control P5 object that will change the minimum size of the detectable pixels of the minDensity of JMyron
  47.  
  48. Ess.start(this); //start the ess object
  49. speaker = new AudioStream(); //initiate a new AudioStram object
  50. mSine = new Sine(0, volume, speaker.sampleRate); //define a new since wave of set values
  51. myFile=new AudioFile();
  52. speaker.start(); //start the new audioStream Object
  53.  
  54. myChannel = new AudioChannel("drum.wav");
  55. mySound = new AudioChannel("recording.wav");
  56. }
  57.  
  58. void draw(){
  59. m.update(); //update the camera view
  60. m.trackColor(r,g,b,sensitivity); //track the rgb and sensitivity to track the rgb
  61. m.minDensity(min_size); //minimum pixels in the glob required to result in a box
  62. int[] img = m.image(); //get the normal image of the camera
  63. loadPixels(); //load the pixels
  64.  
  65. for(int i=0;i<width*height;i++){ //loop through all the pixels
  66. pixels[i] = img[i]; //put all the values in the img array into the pixel array
  67.  
  68. }
  69. updatePixels(); //update the pixels on screen
  70.  
  71. stroke(r - 25,g-25,b-25); //set the stroke to the selected color and reduce the outline
  72. int[][][] list = m.globEdgePoints(30); //create a 3 dimensional array called list and place all the points desciribing the outlines of each glob
  73.  
  74. for(int i=0;i
  75. <list.length;i++){ //loop through the list array of GlobEdgePoints
  76. beginShape(); //start recording the vertices for the shape
  77. if(list[i]!=null){ //if the list of globEdgePoints is not empty
  78. for(int ii=0;ii<list[i].length;ii++){ //create an int ii, loop through the list array of globEdgePoints
  79. vertex (list[i][ii][0],list[i][ii][1]); //draw the boxes for the globs points and connect them
  80. fill(r,g,b); //set the fill color of the glob area to the selected color
  81. }
  82. }
  83. endShape();
  84. }
  85. int[][] centers = m.globCenters(); //create an array to find the center points off all the globs
  86. //draw all the dots while calculating the average.
  87. //println("Amount of globs: " + centers.length);
  88.  
  89. float avX=0; //initialise a float integer avX
  90. float avY=0; //initialise a float integer avY
  91.  
  92. for(int i=0;i<centers.length;i++){ //a for loop that runs for the amount of center points that exist
  93. fill(0); //give them a color of black
  94. rect(centers[i][0],centers[i][1],1,1); //draw the centers at the given array values and make them 1x1 pixel in size
  95. avX += centers[i][0]; //equal to avX = avX + centers[i][0]
  96. avY += centers[i][1]; //equal to avY = avY + centers[i][1]
  97. }
  98.  
  99. if(centers.length-1>0){ //if the amount of centers -1 is greater than 0
  100. avX/=centers.length-1; //equal to avX = avX / the length of the centers array - 1
  101. avY/=centers.length-1; //equal to avY = avY / the length of the centers array - 1
  102. }
  103.  
  104. //draw the average of all the points in red.
  105. fill(255,0,0);
  106. rect(avX,avY,5,5);
  107.  
  108. //update the location of the thing on the screen.
  109. if(!(avX==0&&avY==0)&&centers.length>0){ //if the averages of the center points and are not at 0 and the centers array is greater than 0
  110. objdestx = avX; //set objestx to avX
  111. objdesty = avY; //set objesty to avY
  112. }
  113. objx += (objdestx-objx)/5.0f; //equal to objx to objx + (objdestx-objx)/2.0f, f declares it a float
  114. objy += (objdesty-objy)/5.0f; //equal to objY to objy + (objdesty-objy)/2.0f
  115.  
  116. fill(r*2,g*2,b*2); //the fill color is twice the value that was clicked on
  117. ellipseMode(CENTER); //center an elipse around that point
  118. ellipse(objx,objy,25,25); //the position of the glob is set to objx and objy, it's 5 pixels in height and width
  119.  
  120. mSine.setFreq( map(objy, 0, width, 2880, 0) ); //map the frequency of the Sine to the Y axis based between 2880 and 0 of the intial freq
  121.  
  122. //println("X of Glob:" + objx + "Y of Glob:" + objy);
  123. //println("the avx variable:" + avX);
  124.  
  125. }
  126.  
  127. void audioStreamWrite(AudioStream s)
  128. {
  129. mSine.generate(s); //generate the sine wave
  130. if (recording) {
  131. myFile.write(speaker);
  132. bytesWritten+=speaker.size*2;
  133. }
  134. }
  135.  
  136. void controlEvent(ControlEvent theEvent) { //controlP5 controller stuff
  137. switch(theEvent.controller().id()) {
  138.  
  139. case(1):
  140. sensitivity = (int)(theEvent.controller().value()); //set the sensitivity
  141. print("sensitivity changed to " + sensitivity + "\n");
  142. break;
  143.  
  144. case(2):
  145. min_size = (int)(theEvent.controller().value()); //set the minimum size of the pixels that we will track
  146. break;
  147.  
  148. case(3):
  149. volume = (float)(theEvent.controller().value()); //set the volum
  150. break;
  151.  
  152. }
  153.  
  154. }
  155.  
  156. void mouseClicked(MouseEvent m) {
  157. if (mouseEvent.getClickCount() == 2) { //if they are 2 mouse clicks
  158. mouseX = m.getX(); //get the mouse horizontal value of the JMyron object
  159. mouseY = m.getY(); //get the mouse vertical value of the JMyron object
  160. println("The co-ordinates of the mouse click are:");
  161. println("X:" + mouseX + " Y:" + mouseY);
  162. int c = get(mouseX, mouseY); //initialise c as the x and y co-ords of the mouse
  163. r = int(red(c)); //get the red int value of c
  164. g = int(green(c)); //get the green int value of c
  165. b = int(blue(c)); //get the blue int value of c
  166. println ("R: " + r + " G: " + g + " B: " + b + " Sens: " + sensitivity);
  167.  
  168. }
  169. }
  170.  
  171. void keyPressed() {
  172. if(key=='r') {
  173. if (recording) {
  174. // stop
  175. myFile.close();
  176.  
  177. println("Finished recording. "+bytesWritten+" bytes written.");
  178. } else {
  179. // start
  180. myFile.open(dataPath("recording.wav"),speaker.sampleRate,Ess.WRITE);
  181. bytesWritten=0;
  182.  
  183. println("Recording started.");
  184. }
  185.  
  186. recording=!recording;
  187. }
  188. if(key=='d') {
  189. println("drum!");
  190. myChannel.play();
  191.  
  192. }
  193. if(key=='s') {
  194. println("Play recording");
  195. mySound.play();
  196.  
  197. }
  198. }
  199.  
  200. public void stop(){
  201. m.stop(); //stop the object
  202. super.stop();
  203. }
  204.  

Sine Class

  1. class Sine
  2. {
  3. private float freq, newFreq;
  4. private float amp;
  5. private float stepSize;
  6. private float step;
  7.  
  8. Sine(float f, float a, float s)
  9. {
  10. freq = f;
  11. newFreq = freq;
  12. amp = a;
  13. stepSize = 1/s;
  14. step = 0;
  15. }
  16.  
  17. void setFreq(float f)
  18. {
  19. newFreq = f;
  20. }
  21.  
  22. boolean generate(AudioOutput ao)
  23. {
  24. float[] buff = new float[ao.buffer.length];
  25. boolean alert = generate(buff);
  26. arraycopy(buff, 0, ao.buffer2, ao.buffer.length, buff.length);
  27. arraycopy(buff, 0, ao.buffer, 0, buff.length);
  28. return alert;
  29. }
  30.  
  31. boolean generate(float[] buff)
  32. {
  33. boolean alert = freq != newFreq;
  34. for ( int i = 0; i < buff.length; i++ )
  35. {
  36. buff[i] = amp*sin(freq*TWO_PI*step);
  37. if ( abs(freq-newFreq) < 0.1f ) freq = newFreq;
  38. else if ( freq < newFreq ) freq += 0.1f;
  39. else if ( freq > newFreq ) freq -= 0.1f;
  40. step += stepSize;
  41. if ( step > 1/freq ) step %= 1/freq;
  42. }
  43. return alert;
  44. }
  45.  
  46. }

No responses yet

Apr 10 2009

Interaction Update

After playing around with the last interaction example, a sound is generated if my hand goes over a button. I'm going to try and develop this with MIDI to create a virtual piano. Should be fun....

No responses yet

Apr 10 2009

Interaction

Published by Michael Doyle under JMyron, Processing

I updated iteration #6 to enable interaction. I got this script from the learning section of processing.org.
The script gives examples of mouse overs, so the adaptation of this isn't working as good as I want. There is no mouse over function, just a calculation of the position of the x+y co-ordinates of the mouse and if it's the same are as a rectangle.
here's the code:

  1. import JMyron.*;
  2. import krister.Ess.*;
  3. import controlP5.*;
  4. JMyron m;//a camera object
  5. ControlP5 controlP5;
  6.  
  7. float bx;
  8. float by;
  9. int bs = 20;
  10. boolean bover = false;
  11. boolean locked = false;
  12. float bdifx = 0.0;
  13. float bdify = 0.0;
  14.  
  15. int r;
  16. int g;
  17. int b;
  18. int min_size = 50;
  19. int max_size=100;
  20. int sensitivity = 35;
  21. float objx = 160;
  22. float objy = 120;
  23. float objdestx = 160;
  24. float objdesty = 120;
  25.  
  26. void setup(){
  27. size(720,576);
  28. m = new JMyron();//make a new instance of the object
  29. m.start(width,height);//start a capture at 320x240
  30. m.findGlobs(1);//disable the intelligence to speed up frame rate
  31. controlP5 = new ControlP5(this);
  32. controlP5.addSlider("sensitivity",0,255,sensitivity,10,10,10,100).setId(1);
  33. controlP5.addSlider("min size",0,800,min_size,60,10,10,100).setId(2);
  34.  
  35. bx = width/2.0;
  36. by = height/2.0;
  37. rectMode(RADIUS);
  38.  
  39. }
  40.  
  41. void draw(){
  42. m.update();//update the camera view
  43. m.trackColor(r,g,b,sensitivity);
  44. m.minDensity(min_size);
  45. //m.maxDensity(max_size);
  46. int[] img = m.image(); //get the normal image of the camera
  47.  
  48. loadPixels();
  49. for(int i=0;i<width*height;i++){ //loop through all the pixels
  50. pixels[i] = img[i]; //draw each pixel to the screen
  51. }
  52. updatePixels();
  53.  
  54. stroke(0,255,0);
  55. int[][][] list = m.globEdgePoints(30);//get the outlines
  56. for(int i=0;i
  57. <list.length;i++){
  58. beginShape();
  59. if(list[i]!=null){
  60. for(int ii=0;ii<list[i].length;ii++){
  61. vertex(list[i][ii][0],list[i][ii][1]);
  62. }
  63. }
  64. endShape();
  65. }
  66. int[][] centers = m.globCenters();//get the center points
  67. //draw all the dots while calculating the average.
  68. //println("Amount of globs: " + centers.length);
  69. float avX=0;
  70. float avY=0;
  71. for(int i=0;i<centers.length;i++){
  72. fill(0);
  73. rect(centers[i][0],centers[i][1],1,1);
  74. avX += centers[i][0];
  75. avY += centers[i][1];
  76. }
  77. if(centers.length-1>0){
  78. avX/=centers.length-1;
  79. avY/=centers.length-1;
  80. }
  81.  
  82. //draw the average of all the points in red.
  83. fill(255,0,0);
  84. rect(avX,avY,5,5);
  85.  
  86. //update the location of the thing on the screen.
  87. if(!(avX==0&&avY==0)&&centers.length>0){
  88. objdestx = avX;
  89. objdesty = avY;
  90. }
  91. objx += (objdestx-objx)/10.0f;
  92. objy += (objdesty-objy)/10.0f;
  93. fill(30,100,0);
  94. ellipseMode(CENTER);
  95. ellipse(objx,objy,25,25);
  96. println("X of Glob:" + objx + "Y of Glob:" + objy);
  97. println("the avx variable:" + avX);
  98.  
  99. if (objx > bx-bs && objx < bx+bs &&
  100. objy > by-bs && objy < by+bs) {
  101. bover = true;
  102. if(!locked) {
  103. stroke(255);
  104. fill(153);
  105. }
  106. } else {
  107. stroke(153);
  108. fill(153);
  109. bover = false;
  110. }
  111.  
  112. // Draw the box
  113. rect(bx, by, bs, bs);
  114. }
  115.  
  116. void mousePressed() {
  117. if(bover) {
  118. locked = true;
  119. fill(255, 255, 255);
  120. } else {
  121. locked = false;
  122. }
  123. bdifx = mouseX-bx;
  124. bdify = mouseY-by;
  125.  
  126. }
  127.  
  128. void controlEvent(ControlEvent theEvent) {
  129. switch(theEvent.controller().id()) {
  130.  
  131. case(1):
  132. sensitivity = (int)(theEvent.controller().value());
  133. print("sensitivity changed to " + sensitivity + "\n");
  134. break;
  135.  
  136. case(2):
  137. min_size = (int)(theEvent.controller().value());
  138. break;
  139.  
  140. case(3):
  141. max_size = (int)(theEvent.controller().value());
  142. break;
  143.  
  144. }
  145.  
  146. }
  147.  
  148. void mouseClicked(MouseEvent m) {
  149. if (mouseEvent.getClickCount() == 2) {
  150. mouseX = m.getX();
  151. mouseY = m.getY();
  152. println("The co-ordinates of the mouse click are:");
  153. println("X:" + mouseX + " Y:" + mouseY);
  154. int c = get(mouseX, mouseY);
  155. r = int(red(c));
  156. g = int(green(c));
  157. b = int(blue(c));
  158. println ("R: " + r + " G: " + g + " B: " + b + " Sens: " + sensitivity);
  159. return;
  160. }
  161. }
  162.  
  163. public void stop(){
  164. m.stop();//stop the object
  165. super.stop();
  166. }
  167.  

No responses yet

Apr 09 2009

Maestro Version 1.1

Published by Michael Doyle under JMyron, Processing, ess r2

Major breakthrough. I've got a digital thermin created, although it isn't very polished, it's working!  The play method is placed in the mouose event method, and updates each time the average point is updated. The click is still occuring, however, I will try and change the priginal prototype to AudioStreams rather than channels to see if it'll sort that out.

Here's the code:

import JMyron.*;
import krister.Ess.*;
import controlP5.*;
JMyron m;//a camera object
ControlP5 controlP5;
AudioChannel myChannel;
SineWave myWave;
float volume=1;
int pitch=400;
int release=10000;
FadeIn myFadeIn;
FadeOut myFadeOut;
 
int r;
int g;
int b;
int min_size = 50;
int max_size=100;
int sensitivity = 35;
float objx = 160;
float objy = 120;
float objdestx = 160;
float objdesty = 120;
 
void setup(){
  size(720,576);
  m = new JMyron();//make a new instance of the object
  m.start(width,height);//start a capture at 320x240
  m.findGlobs(1);//disable the intelligence to speed up frame rate
  controlP5 = new ControlP5(this);
  /*
  controlP5.addSlider("sensitivity",0,255,40,10,10,10,100).setId(1);
   name, low val, high val, default val, x, y, width, height,
   */
  controlP5.addSlider("sensitivity",0,255,sensitivity,10,10,10,100).setId(1);
  controlP5.addSlider("min size",0,800,min_size,60,10,10,100).setId(2);
  //controlP5.addSlider("max size",0,400,max_size,100,10,10,100).setId(3);
  //println("here are the globs:"  + m.globCenters());
   Ess.start(this);
   myChannel=new AudioChannel();
   myFadeIn=new FadeIn();
   myFadeOut=new FadeOut();
 
}
 
void draw(){
  m.update();//update the camera view
  m.trackColor(r,g,b,sensitivity);
  m.minDensity(min_size);
  //m.maxDensity(max_size);
  int[] img = m.image(); //get the normal image of the camera
 
  loadPixels();
  for(int i=0;i<width*height;i++){ //loop through all the pixels
    pixels[i] = img[i]; //draw each pixel to the screen
  }
  updatePixels();
 
  stroke(0,255,0);
  int[][][] list = m.globEdgePoints(30);//get the outlines
  for(int i=0;i
<list.length;i++){
    beginShape();
    if(list[i]!=null){
      for(int ii=0;ii<list[i].length;ii++){
        vertex(list[i][ii][0],list[i][ii][1]);
      }
    }
    endShape();
  }
  int[][] centers = m.globCenters();//get the center points
  //draw all the dots while calculating the average.
  //println("Amount of globs: " + centers.length);
  float avX=0;
  float avY=0;
  for(int i=0;i<centers.length;i++){
    fill(0);
    rect(centers[i][0],centers[i][1],1,1);
    avX += centers[i][0];
    avY += centers[i][1];
  }
  if(centers.length-1>0){
    avX/=centers.length-1;
    avY/=centers.length-1;
  }
 
  //draw the average of all the points in red.
  fill(255,0,0);
  rect(avX,avY,5,5);
 
  //update the location of the thing on the screen.
  if(!(avX==0&&avY==0)&&centers.length>0){
    objdestx = avX;
    objdesty = avY;
  }
  objx += (objdestx-objx)/10.0f;
  objy += (objdesty-objy)/10.0f;
  fill(30,100,0);
  ellipseMode(CENTER);
  ellipse(objx,objy,25,25);
  println("X of Glob:" + objx + "Y of Glob:" + objy);
  println("the avx variable:" + avX);
 
                myWave=new SineWave(objx,volume);
    myChannel.initChannel(myChannel.frames(release));
    myWave.generate(myChannel,5,myChannel.frames(release));
    myFadeOut.filter(myChannel);
    myFadeIn.filter(myChannel);
}
 
void controlEvent(ControlEvent theEvent) {
  switch(theEvent.controller().id()) {
 
    case(1):
    sensitivity = (int)(theEvent.controller().value());
    print("sensitivity changed to " + sensitivity + "\n");
    break;  
 
    case(2):
    min_size = (int)(theEvent.controller().value());
    break;
 
    case(3):
    max_size = (int)(theEvent.controller().value());
    break;
 
  }
 
}
 
void mouseClicked(MouseEvent m) {
  if (mouseEvent.getClickCount() == 2) {
    mouseX = m.getX();
    mouseY = m.getY();
    println("The co-ordinates of the mouse click are:");
    println("X:" + mouseX + " Y:" + mouseY);
    int c = get(mouseX, mouseY);
    r = int(red(c));
    g = int(green(c));
    b = int(blue(c));
    println ("R: " + r + " G: " + g + " B: " + b + " Sens: " + sensitivity);
 
    myChannel.play();
    return;
  }
}
 
public void stop(){
  m.stop();//stop the object
  super.stop();
}

No responses yet

Apr 09 2009

Tracking pixels

For testing purposes, I have added the tracking of the pixels of a certain value and the average point of these. This allows me to grab the x and y co-ordinates of the average point an, hopefully, work the ess prototype around it.

    No responses yet

    Apr 08 2009

    JMyron + controlP5 iteration #6

    Published by Michael Doyle under JMyron, Processing, controlP5

    Updated this to now include:

    • Finds the average point of all blobs and places a marker where it is
    • Outputs the amount of Globs detected for the clicked color value

    So after playing around with it,  I have to say it's working quite well. It's come on a long way from what I started with. I now have to concentrate on the ellipse and look at how I can track that to manipulate the pitch of sine waves and start hit tests with buttons.

    Here is the code:

    1. import JMyron.*;
    2. import controlP5.*;
    3. JMyron m;//a camera object
    4. ControlP5 controlP5;
    5. int r;
    6. int g;
    7. int b;
    8. int min_size = 50;
    9. int max_size=100;
    10. int sensitivity = 35;
    11. float objx = 160;
    12. float objy = 120;
    13. float objdestx = 160;
    14. float objdesty = 120;
    15.  
    16. void setup(){
    17. size(720,576);
    18. m = new JMyron();//make a new instance of the object
    19. m.start(width,height);//start a capture at 320x240
    20. m.findGlobs(1);//disable the intelligence to speed up frame rate
    21. controlP5 = new ControlP5(this);
    22. /*
    23.   controlP5.addSlider("sensitivity",0,255,40,10,10,10,100).setId(1);
    24.   name, low val, high val, default val, x, y, width, height,
    25.   */
    26. controlP5.addSlider("sensitivity",0,255,sensitivity,10,10,10,100).setId(1);
    27. controlP5.addSlider("min size",0,800,min_size,60,10,10,100).setId(2);
    28. //controlP5.addSlider("max size",0,400,max_size,100,10,10,100).setId(3);
    29. //println("here are the globs:" + m.globCenters());
    30. }
    31.  
    32. void draw(){
    33. m.update();//update the camera view
    34. m.trackColor(r,g,b,sensitivity);
    35. m.minDensity(min_size);
    36. //m.maxDensity(max_size);
    37. int[] img = m.image(); //get the normal image of the camera
    38.  
    39. loadPixels();
    40. for(int i=0;i<width*height;i++){ //loop through all the pixels
    41. pixels[i] = img[i]; //draw each pixel to the screen
    42. }
    43. updatePixels();
    44.  
    45. stroke(0,255,0);
    46. int[][][] list = m.globEdgePoints(30);//get the outlines
    47. for(int i=0;i
    48. <list.length;i++){
    49. beginShape();
    50. if(list[i]!=null){
    51. for(int ii=0;ii<list[i].length;ii++){
    52. vertex(list[i][ii][0],list[i][ii][1]);
    53. }
    54. }
    55. endShape();
    56. }
    57. int[][] centers = m.globCenters();//get the center points
    58. //draw all the dots while calculating the average.
    59. println("Amount of globs: " + centers.length);
    60. float avX=0;
    61. float avY=0;
    62. for(int i=0;i<centers.length;i++){
    63. fill(0);
    64. rect(centers[i][0],centers[i][1],1,1);
    65. avX += centers[i][0];
    66. avY += centers[i][1];
    67. }
    68. if(centers.length-1>0){
    69. avX/=centers.length-1;
    70. avY/=centers.length-1;
    71. }
    72.  
    73. //draw the average of all the points in red.
    74. fill(255,0,0);
    75. rect(avX,avY,5,5);
    76.  
    77. //update the location of the thing on the screen.
    78. if(!(avX==0&&avY==0)&&centers.length>0){
    79. objdestx = avX;
    80. objdesty = avY;
    81. }
    82. objx += (objdestx-objx)/10.0f;
    83. objy += (objdesty-objy)/10.0f;
    84. fill(30,100,0);
    85. ellipseMode(CENTER);
    86. ellipse(objx,objy,25,25);
    87. }
    88.  
    89. void controlEvent(ControlEvent theEvent) {
    90. switch(theEvent.controller().id()) {
    91.  
    92. case(1):
    93. sensitivity = (int)(theEvent.controller().value());
    94. print("sensitivity changed to " + sensitivity + "\n");
    95. break;
    96.  
    97. case(2):
    98. min_size = (int)(theEvent.controller().value());
    99. break;
    100.  
    101. case(3):
    102. max_size = (int)(theEvent.controller().value());
    103. break;
    104.  
    105. }
    106.  
    107. }
    108.  
    109. void mouseClicked(MouseEvent m) {
    110. if (mouseEvent.getClickCount() == 2) {
    111. mouseX = m.getX();
    112. mouseY = m.getY();
    113. println("The co-ordinates of the mouse click are:");
    114. println("X:" + mouseX + " Y:" + mouseY);
    115. int c = get(mouseX, mouseY);
    116. r = int(red(c));
    117. g = int(green(c));
    118. b = int(blue(c));
    119. println ("R: " + r + " G: " + g + " B: " + b + " Sens: " + sensitivity);
    120. return;
    121. }
    122. }
    123.  
    124. public void stop(){
    125. m.stop();//stop the object
    126. super.stop();
    127. }

    No responses yet

    Apr 06 2009

    JMyron + controlP5 iteration #5

    Published by Michael Doyle under JMyron, Processing, controlP5

    Got everything working great. I did a step around the mouse click problem. To select a color, a double click is needed.Since only one click is needed to drag the sliders in controlP5, it won't invoke the mouse event method.

    So, at the moment, this iteration allows a user to:

    • Double click the video feed to track a color
    • See the RGB value of their chosen color
    • See the x,y co-ordinates of their mouse click
    • Set the sensitivity of the color tracking
    • Set the max/min amount of pixels to detect

    Here is the code:

    1. import JMyron.*;
    2. import controlP5.*;
    3.  
    4. JMyron m;
    5. ControlP5 controlP5;
    6.  
    7. int r;
    8. int g;
    9. int b;
    10. int sensitivity = 50;
    11. int min_size = 50;
    12. int max_size=200;
    13. int mouseX;
    14. int mouseY;
    15.  
    16. void setup(){
    17. int width = 720;
    18. int height = 576;
    19. size(width,height);
    20. m = new JMyron();
    21. m.start(width,height);
    22. frameRate(25);
    23. //println("Myron " + m.version());
    24. noFill();
    25. controlP5 = new ControlP5(this);
    26. controlP5.addSlider("sensitivity",0,255,40,10,140,10,50).setId(1);
    27. controlP5.addSlider("min size",0,400,10,60,140,10,50).setId(2);
    28. controlP5.addSlider("max size",0,400,10,100,140,10,50).setId(3);
    29. }
    30.  
    31. void draw(){
    32.  
    33. m.trackColor(r,g,b,sensitivity);
    34. //m.minDensity(min_size);
    35. //m.maxDensity(max_size);
    36. float ir,ig,ib;
    37. m.update();//update the camera view
    38. int[] img = m.image(); //get the normal image of the camera
    39.  
    40. //draw what the camera sees
    41. loadPixels();
    42. for(int i=0;i<width*height;i++){ //loop through all the pixels
    43. pixels[i] = img[i]; //draw each pixel to the screen
    44. }
    45. updatePixels();
    46.  
    47. stroke(0,255,0);
    48. int[][][] list = m.globEdgePoints(30);//get the outlines
    49. for(int i=0;i
    50. <list.length;i++){
    51. beginShape();
    52. if(list[i]!=null){
    53. for(int ii=0;ii<list[i].length;ii++){
    54. vertex(list[i][ii][0],list[i][ii][1]);
    55. }
    56. }
    57. endShape();
    58. }
    59.  
    60. }
    61. void controlEvent(ControlEvent theEvent) {
    62. switch(theEvent.controller().id()) {
    63.  
    64. case(1):
    65. sensitivity = (int)(theEvent.controller().value());
    66. print("sensitivity changed to " + sensitivity + "\n");
    67. break;
    68.  
    69. case(2):
    70. min_size = (int)(theEvent.controller().value());
    71. break;
    72.  
    73. case(3):
    74. max_size = (int)(theEvent.controller().value());
    75. break;
    76.  
    77. }
    78.  
    79. }
    80.  
    81. void mouseClicked(MouseEvent m) {
    82. if (mouseEvent.getClickCount() == 2) {
    83. mouseX = m.getX();
    84. mouseY = m.getY();
    85. println("The co-ordinates of the mouse click are:");
    86. println("X:" + mouseX + " Y:" + mouseY);
    87. int c = get(mouseX, mouseY);
    88. r = int(red(c));
    89. g = int(green(c));
    90. b = int(blue(c));
    91. println (r + " " + g + " " + b);
    92.  
    93. return;
    94. }
    95. }
    96.  
    97. void stop(){
    98. m.stop();//stop the object
    99. super.stop();
    100. }

    No responses yet

    Next »