Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import gab.opencv.*;
  2. import processing.video.*;
  3. import java.awt.*;
  4.  
  5. Capture ourVideo;
  6. OpenCV opencv;
  7.  
  8. float[][] kernel = {{ -1, -1, -1},
  9. { -1, 10, -1},
  10. { -1, -1, -1}};
  11. PImage img;
  12.  
  13. void setup() {
  14. size(1280, 720);
  15. frameRate(120);
  16. ourVideo = new Capture(this, width, height);
  17. opencv = new OpenCV(this, 1280, 720);
  18. opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
  19. ourVideo.start();
  20. img = loadImage("wow.png");
  21. }
  22.  
  23. void draw() {
  24. opencv.loadImage(ourVideo);
  25. Rectangle[] faces = opencv.detect();
  26. if (ourVideo.available()) ourVideo.read();
  27. ourVideo.loadPixels();
  28. loadPixels();
  29.  
  30. for (int y = 1; y < ourVideo.height-1; y++) {
  31. for (int x = 1; x < ourVideo.width-1; x++) {
  32. float sum = 0;
  33.  
  34. for (int ky = -1; ky <= 1; ky++) {
  35. for (int kx = -1; kx <= 1; kx++) {
  36. int pos = (y + ky)*ourVideo.width + (x + kx);
  37. float val = red(ourVideo.pixels[pos]);
  38. sum += kernel[ky+1][kx+1] * val;
  39. }
  40. }
  41.  
  42. if (sum < 80) {
  43. pixels[y*ourVideo.width + x] = color(sum, sum, sum);
  44. } else {
  45. pixels[y*ourVideo.width + x] = color(255, 255, 255);
  46. }
  47.  
  48. }
  49. }
  50. updatePixels();
  51.  
  52. for(int i =0; i < faces.length; i++) {
  53. image(img, faces[i].x-200, faces[i].y-50);
  54. }
  55.  
  56. println (frameRate);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement