Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import gab.opencv.*;
  2. import processing.video.*;
  3. import java.awt.*;
  4.  
  5. Capture webcam_frame;
  6. OpenCV opencv;
  7.  
  8. // Capture resolution of webcam.
  9. int capture_x = 960;
  10. int capture_y = 720;
  11.  
  12. void setup() {
  13. // Dump list of webcams capabilities.
  14. get_webcam_capabilities();
  15.  
  16. // Make viewport size.
  17. size(capture_x * 2, capture_y);
  18.  
  19. // Resolution + fps requested from webcam.
  20. webcam_frame = new Capture(this, capture_x, capture_y, 15);
  21.  
  22. // Opencv wrapper.
  23. opencv = new OpenCV(this, capture_x, capture_y);
  24.  
  25. // Send the request for webcam to start dumping frames.
  26. webcam_frame.start();
  27.  
  28. // Disable looping in draw.
  29. noLoop();
  30. }
  31.  
  32. // Dumps the webcam frames.
  33. void draw() {
  34. // Store the current frame.
  35. opencv.loadImage(webcam_frame);
  36.  
  37. // Get the next frame.
  38. webcam_frame.read();
  39.  
  40. // Get only blue stuff;
  41. opencv.getB();
  42.  
  43. // Do a diff between the old and new image frames.
  44. // opencv.diff(webcam_frame);
  45.  
  46. // Display the video image on the processing window.
  47. set(0, 0, webcam_frame);
  48. image(opencv.getSnapshot(), capture_x, 0);
  49. }
  50.  
  51. // Unused since PImage doesn't seem to properly hold
  52. // the old camera image.
  53. PImage get_diff(PImage image_A, PImage image_B){
  54. opencv.loadImage(image_A);
  55. opencv.diff(image_B);
  56.  
  57. return opencv.getSnapshot();
  58. }
  59.  
  60. // Dump list of webcams capabilities.
  61. void get_webcam_capabilities(){
  62. // Read all camera params.
  63. String[] cameras = Capture.list();
  64.  
  65. // Dump all params to terminal.
  66. println("Available cameras:");
  67. for (int i = 0; i < cameras.length; i++)
  68. println(cameras[i]);
  69. }
  70.  
  71. // Called everytime a new camera frame is avalible.
  72. void captureEvent(Capture webcam) {
  73. println("Capture event fired");
  74.  
  75. // Redraw the GUI.
  76. redraw();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement