Branchez une webcam sur votre minitel !
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

video2minitelteletPerso_goodV4_3.pde 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //Video2Minitel
  2. //by Renaud, Fabrice & Phil
  3. //Inspired from Video2ledwallHarpSerial V1.0 by Fabrice Fourc
  4. // http://www.tetalab.org
  5. import processing.video.*;
  6. import processing.net.*;
  7. int plage=44;//256;
  8. int MINITEL_CHAR_WIDTH = 40;//*2;
  9. int MINITEL_CHAR_HEIGHT = 24;//*4;
  10. // en fait ce n'est pas vraiment un pixel par pixel char...
  11. int PIXEL_CHAR_WIDTH = 2;
  12. int PIXEL_CHAR_HEIGHT = 3;
  13. // Size of each cell in the grid, ratio of window size to video size
  14. int videoScale = 10;
  15. int videoScalex = 8;
  16. int videoScaley = 6;
  17. // Number of columns and rows in our system
  18. int cols, rows;
  19. // Variable to hold onto Capture object
  20. public int s = 50;
  21. import processing.serial.*;
  22. // The serial port:
  23. Serial myPort;
  24. //luminosite globale de la colone pour le son
  25. int colValue;
  26. String ledCol;
  27. String ledWallMsg;
  28. //Client myClient;
  29. Capture video;
  30. void setup()
  31. {
  32. size(MINITEL_CHAR_WIDTH*PIXEL_CHAR_WIDTH*videoScalex,MINITEL_CHAR_HEIGHT*PIXEL_CHAR_HEIGHT*videoScaley);
  33. frameRate(25);
  34. // List all the available serial ports:
  35. println(Serial.list());
  36. // I know that the first port in the serial list on my mac
  37. // is always my Keyspan adaptor, so I open Serial.list()[0].
  38. // Open whatever port is the one you're using.
  39. myPort = new Serial(this, Serial.list()[1], 1200);
  40. //myClient = new Client(this, "127.0.0.1", 5204);
  41. // Initialize columns and rows
  42. cols = width/videoScalex;
  43. rows = height/videoScaley;
  44. video = new Capture(this,cols,rows,30);
  45. }
  46. //----------------------------------------------------------
  47. void displayPixelChar2(int x, int y)
  48. {
  49. x= x *2;
  50. y = y * 3;
  51. byte carac=0; // caractère pixel
  52. carac+=(Math.pow(2,0))*getG2(x+0,y+0);
  53. carac+=(Math.pow(2,1))*getG2(x+1,y+0);
  54. carac+=(Math.pow(2,2))*getG2(x+0,y+1);
  55. carac+=(Math.pow(2,3))*getG2(x+1,y+1);
  56. carac+=(Math.pow(2,4))*getG2(x+0,y+2);
  57. carac+=(Math.pow(2,5))*1;
  58. carac+=(Math.pow(2,6))*getG2(x+1,y+2);
  59. myPort.write(carac);
  60. println("carac= "+carac);
  61. }
  62. int getG2(int x,int y)
  63. {
  64. println("x + y*video.width" + (x + y*video.width));
  65. color c = video.pixels[x + y*video.width];
  66. int value = (int)brightness(c); // get the brightness
  67. if (value<s)
  68. {
  69. return(0);
  70. }
  71. else
  72. {
  73. return(1);
  74. }
  75. }
  76. void draw() {
  77. // Read image from the camera
  78. noStroke();
  79. if (video.available())
  80. {
  81. video.read();
  82. }
  83. video.loadPixels();
  84. if(!mousePressed) //si je ne clique pas, j'affiche le preview
  85. {
  86. image(video,0,0);
  87. // Begin loop for columns
  88. for (int i = 0; i < cols; i++)
  89. {
  90. // Begin loop for rows
  91. for (int j = 0; j < rows; j++)
  92. {
  93. // Where are we, pixel-wise?
  94. int x = i*videoScalex;
  95. int y = j*videoScaley;
  96. // Looking up the appropriate color in the pixel array
  97. color c = video.pixels[i + j*video.width];
  98. int value = (int)brightness(c); // get the brightness
  99. if (value<s)
  100. {
  101. fill(0);
  102. }
  103. else
  104. {
  105. fill(255);
  106. }
  107. rect(x,y,videoScalex,videoScaley);
  108. }
  109. ledWallMsg += ledCol;
  110. }
  111. }
  112. else //si je clique sur l'image j'envoi sur le port serie
  113. {
  114. myPort.write(12);
  115. myPort.write(14);
  116. for (int y=0;y<MINITEL_CHAR_HEIGHT;y++)
  117. {
  118. for (int x=0;x<MINITEL_CHAR_WIDTH;x++)
  119. {
  120. displayPixelChar2(x,y);
  121. println("x= "+x+"y= "+y);
  122. }
  123. }
  124. }
  125. }
  126. void keyPressed() //reglage du seuil (a-, z+)
  127. {
  128. if( key == 'a')
  129. {
  130. s = s - 1;
  131. println("s " + s);
  132. }
  133. if ( key == 'z')
  134. {
  135. s = s + 1;
  136. println("s " + s);
  137. }
  138. }