Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void testApp::setup() {
  5. ofBackground(0, 0, 0);
  6.  
  7. image.load("ostateczne2.png");
  8.  
  9. fingerMovie.setPixelFormat(OF_PIXELS_RGBA);
  10. fingerMovie.load("film.mov");
  11. fingerMovie.setLoopState(OF_LOOP_NORMAL);
  12. fingerMovie.play();
  13.  
  14. w = 640;
  15. h = 480;
  16.  
  17. movie.initGrabber(w, h, true);
  18.  
  19. //reserve memory for cv images
  20. rgb.allocate(w, h);
  21. hsb.allocate(w, h);
  22. hue.allocate(w, h);
  23. sat.allocate(w, h);
  24. bri.allocate(w, h);
  25. filtered.allocate(w, h);
  26. }
  27.  
  28. //--------------------------------------------------------------
  29. void testApp::update() {
  30.  
  31. movie.update();
  32.  
  33. if (movie.isFrameNew()) {
  34.  
  35. //copy webcam pixels to rgb image
  36. rgb.setFromPixels(movie.getPixels());
  37.  
  38. //mirror horizontal
  39. rgb.mirror(false, true);
  40.  
  41. //duplicate rgb
  42. hsb = rgb;
  43.  
  44. //convert to hsb
  45. hsb.convertRgbToHsv();
  46.  
  47. //store the three channels as grayscale images
  48. hsb.convertToGrayscalePlanarImages(hue, sat, bri);
  49.  
  50. //filter image based on the hue value were looking for
  51. for (int i = 0; i < w*h; i++) {
  52. filtered.getPixels()[i] = ofInRange(hue.getPixels()[i], findHue - 5, findHue + 5) ? 255 : 0;
  53. }
  54. filtered.flagImageChanged();
  55.  
  56. //run the contour finder on the filtered image to find blobs with a certain hue
  57. contours.findContours(filtered, 100, w*h / 2, 1, false);
  58. }
  59. }
  60.  
  61. //--------------------------------------------------------------
  62. void testApp::draw() {
  63. //ofSetColor(255, 255, 255);
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. //draw all cv images
  71. rgb.draw(0, 0);
  72.  
  73.  
  74. //ofSetLineWidth(2.0f); //grobosclini
  75. //ofSetColor(254, 254, 254); //kolor lini
  76. ofFill();
  77.  
  78. //draw red circles for found blobs
  79. for (int i = 0; i < contours.nBlobs; i++) {
  80. //image.draw(contours.blobs[i].centroid.x, contours.blobs[i].centroid.y, 100, 100);
  81. fingerMovie.draw(contours.blobs[i].centroid.x - 30, contours.blobs[i].centroid.y - 30, 140, 180);
  82. }
  83. }
  84.  
  85. //--------------------------------------------------------------
  86. void testApp::mousePressed() {
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement