Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import processing.video.*;
  2.  
  3. Capture video;
  4.  
  5. PGraphics pg;
  6.  
  7. PImage backgroundImage;
  8. float threshold = 30;
  9.  
  10. void setup() {
  11. size(320, 240);
  12. video = new Capture(this, width, height);
  13. video.start();
  14.  
  15. backgroundImage = createImage(video.width, video.height, RGB);
  16. pg = createGraphics(320, 240);
  17. }
  18.  
  19. void captureEvent(Capture video) {
  20. video.read();
  21. }
  22.  
  23. void draw() {
  24. pg.beginDraw();
  25.  
  26. loadPixels();
  27. video.loadPixels();
  28. backgroundImage.loadPixels();
  29.  
  30. image(video, 0, 0);
  31. for (int x = 0; x < video.width; x++) {
  32. for (int y = 0; y < video.height; y++) {
  33. int loc = x + y * video.width;
  34.  
  35.  
  36.  
  37. color fgColor = video.pixels[loc];
  38. color bgColor = backgroundImage.pixels[loc];
  39.  
  40. float r1 = red(fgColor); float g1 = green(fgColor); float b1 = blue(fgColor);
  41. float r2 = red(bgColor); float g2 = green(bgColor); float b2 = blue(bgColor);
  42. float diff = dist(r1, g1, b1, r2, g2, b2);
  43.  
  44.  
  45. if (diff > threshold) {
  46. pixels[loc] = fgColor;
  47. } else {
  48. pixels[loc] = color(0, 0);
  49. }
  50. }}
  51. pg.updatePixels();
  52. pg.endDraw();
  53.  
  54.  
  55. saveFrame("line-######.png");
  56. }
  57.  
  58.  
  59. void mousePressed() {
  60. backgroundImage.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
  61. backgroundImage.updatePixels();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement