Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- //--------------------------------------------------------------
- void testApp::setup() {
- ofBackground(0, 0, 0);
- image.load("ostateczne2.png");
- fingerMovie.setPixelFormat(OF_PIXELS_RGBA);
- fingerMovie.load("film.mov");
- fingerMovie.setLoopState(OF_LOOP_NORMAL);
- fingerMovie.play();
- w = 640;
- h = 480;
- movie.initGrabber(w, h, true);
- //reserve memory for cv images
- rgb.allocate(w, h);
- hsb.allocate(w, h);
- hue.allocate(w, h);
- sat.allocate(w, h);
- bri.allocate(w, h);
- filtered.allocate(w, h);
- }
- //--------------------------------------------------------------
- void testApp::update() {
- movie.update();
- if (movie.isFrameNew()) {
- //copy webcam pixels to rgb image
- rgb.setFromPixels(movie.getPixels());
- //mirror horizontal
- rgb.mirror(false, true);
- //duplicate rgb
- hsb = rgb;
- //convert to hsb
- hsb.convertRgbToHsv();
- //store the three channels as grayscale images
- hsb.convertToGrayscalePlanarImages(hue, sat, bri);
- //filter image based on the hue value were looking for
- for (int i = 0; i < w*h; i++) {
- filtered.getPixels()[i] = ofInRange(hue.getPixels()[i], findHue - 5, findHue + 5) ? 255 : 0;
- }
- filtered.flagImageChanged();
- //run the contour finder on the filtered image to find blobs with a certain hue
- contours.findContours(filtered, 100, w*h / 2, 1, false);
- }
- }
- //--------------------------------------------------------------
- void testApp::draw() {
- //ofSetColor(255, 255, 255);
- //draw all cv images
- rgb.draw(0, 0);
- //ofSetLineWidth(2.0f); //grobosclini
- //ofSetColor(254, 254, 254); //kolor lini
- ofFill();
- //draw red circles for found blobs
- for (int i = 0; i < contours.nBlobs; i++) {
- //image.draw(contours.blobs[i].centroid.x, contours.blobs[i].centroid.y, 100, 100);
- fingerMovie.draw(contours.blobs[i].centroid.x - 30, contours.blobs[i].centroid.y - 30, 140, 180);
- }
- }
- //--------------------------------------------------------------
- void testApp::mousePressed() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement