pixelFetcher

A simple app that captures video and displays the colour of the pixel under the mouse. Exciting!

pixelFetcher

Download pixelFetcher.

openFrameworks code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef _TEST_APP
#define _TEST_APP
 
#include "ofMain.h"
#include "ofAddons.h"
 
#define WIDTH  640
#define HEIGHT 480
#define SQUARE 30
 
class testApp : public ofSimpleApp {
    public:
        void setup();
        void update();
        void draw();
 
        ofVideoGrabber 	capture;
        unsigned char*  videoPixels;
        int             pixelColour;
};
 
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "testApp.h"
 
//--------------------------------------------------------------
void testApp::setup(){
    capture.setVerbose(true);
    capture.initGrabber(WIDTH, HEIGHT);
 
    videoPixels = new unsigned char[WIDTH*HEIGHT * 3];
}
 
//--------------------------------------------------------------
void testApp::update() {
    capture.grabFrame();
 
    if (capture.isFrameNew()) {
        videoPixels = capture.getPixels();
    }
 
    // get the pixel color under the mouse
    int index = ((MAX(0, mouseY) * WIDTH) + MAX(0, mouseX)) * 3;
    pixelColour = videoPixels[index] << 16 |
                  videoPixels[index+1] << 8 |
                  videoPixels[index+2];
}
 
//--------------------------------------------------------------
void testApp::draw() {
    // draw the capture image
    ofSetColor(0xffffff);
    capture.draw(0, 0);
 
    // draw the pixel colour
    ofSetColor(pixelColour);
    ofFill();
    ofRect(mouseX - SQUARE, mouseY - SQUARE, SQUARE*2, SQUARE*2);
 
    // draw the pixel frame
    ofSetColor(0xffffff - pixelColour);
    ofNoFill();
    ofRect(mouseX - SQUARE, mouseY - SQUARE, SQUARE*2, SQUARE*2);
 
    // draw the pixel colour value
    char* rgbValue = new  char[13];
    sprintf(rgbValue, "#%06x", pixelColour);
    ofDrawBitmapString(rgbValue, mouseX - SQUARE + 1, mouseY - 5);
}

0 Responses to “pixelFetcher”


  • No Comments

Leave a Reply