예제 #1
0
 void update() {
     cam->update();
     if(cam->isFrameNew()) {
         ofPixels& pix = cam->getPixels();
         int skip = 2;
         int range = mouseX / 25;
         for(int y = 0; y < pix.getHeight(); y += skip) {
             for(int x = 0; x < pix.getWidth(); x += skip) {
                 ofColor cur = pix.getColor(x, y);
                 ofColor result(0, 0, 0, 0);
                 if(cur.r < range || cur.r > 255-range) {
                     result.r = 255;
                     result.a = 255;
                 }
                 if(cur.g < range || cur.g > 255-range) {
                     result.g = 255;
                     result.a = 255;
                 }
                 if(cur.b < range || cur.b > 255-range) {
                     result.b = 255;
                     result.a = 255;
                 }
                 clipping.setColor(x, y, result);
             }
         }
         clipping.update();
         
         if(recording) {
             string fn = "images/" + ofToString(frameCount, 6, '0') + ".jpg";
             imageSaver.saveImage(pix, fn);
             frameCount++;
         }
     }
 }
예제 #2
0
파일: App.cpp 프로젝트: nikki93/spe
void sobel(Field &field, ofImage &edges, ofPixels &pix) {
    // Sobel gradient
    #define VAL(x, y) pix.getColor(x, y).r
    float mag;
    for (int i = 1; i < 1023; ++i)
        for (int j = 1; j < 767; ++j)
        {
            ofVec2f g(0, 0);
            // left
            g.y -= 2 * VAL(i - 1, j);
            g.y -= VAL(i - 1, j - 1);
            g.y -= VAL(i - 1, j + 1);
            // right
            g.y += 2 * VAL(i + 1, j);
            g.y += VAL(i + 1, j - 1);
            g.y += VAL(i + 1, j + 1);
            // up
            g.x += 2 * VAL(i, j - 1);
            g.x += VAL(i - 1, j - 1);
            g.x += VAL(i + 1, j - 1);
            // down
            g.x -= 2 * VAL(i, j + 1);
            g.x -= VAL(i - 1, j + 1);
            g.x -= VAL(i + 1, j + 1);
            // uniform
            if (g.x < 0)
                g = -g;
            if (g.x == 0)
                g.y = fabs(g.y);
            
            field.set(i, j, 50*g.normalized());
            mag = abs(g.x) + abs(g.y);
            edges.setColor(i, j, ofColor(mag));
        }
}
예제 #3
0
void ofxBaseGui::loadStencilFromHex(ofImage& img, unsigned char* data) {
	int width = img.getWidth();
	int height = img.getHeight();
	int i = 0;
	ofColor on(255, 255);
	ofColor off(255, 0);
	for(int y = 0; y < height; y++) {
		for(int x = 0; x < width; x++) {
			int shift = i % 8;
			int offset = i / 8;
			bool cur = (data[offset] >> shift) & 1;
			img.setColor(x, y, cur ? on : off);
			i++;
		}
	}
	img.update();
}
예제 #4
0
void faceColorToTexture(ofMesh& mesh, ofImage& image)
{
	vector<ofFloatColor> &color = mesh.getColors();
	int num_face = color.size() / 3;
	
	int tex_size = ofNextPow2(ceil(sqrt(num_face)));
	
	bool arb = ofGetUsingArbTex();
	ofDisableArbTex();
	image.allocate(tex_size, tex_size, OF_IMAGE_COLOR);
	if (arb) ofEnableArbTex();
	
	mesh.clearTexCoords();
	
	image.getPixelsRef().set(0);
	
	float texel_size = (1. / image.getWidth()) * 0.5;
	
	for (int i = 0; i < num_face; i++)
	{
		int u = (i % tex_size);
		int v = (i / tex_size);
		
		ofColor c = color[i * 3];
		
		image.setColor(u, v, c);
		
		float uu = (float)u / image.getWidth() + texel_size;
		float vv = (float)v / image.getHeight() + texel_size;
		
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
	}
	
	image.update();
	mesh.clearColors();
}
예제 #5
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    //Merci Ludo pour ton aide
	
    currentFrame = vidGrabber.getPixelsRef();
    currentFrameCopy.allocate(currentFrame.getWidth(), currentFrame.getHeight(), OF_IMAGE_GRAYSCALE);


    for(int x=0 ; x < 256 ; x++) {
        histogram[x] = 0;
    }

    
    for (int i = 0; i < camWidth; i++){
        for (int j = 0; j < camHeight; j++){
            int lightness = currentFrame.getColor(i,j).getLightness();
            histogram[lightness] = histogram[lightness]+1;
            ofColor pixel;
            pixel.set(lightness, lightness, lightness);
            currentFrame.setColor(i, j, pixel);

        }
    }
    
    ofSetHexColor(0xffffff);
    currentFrame.reloadTexture();
    currentFrame.draw(0,0);
    
    ofFill();
	ofSetHexColor(0x000000);
	ofSetPolyMode(OF_POLY_WINDING_ODD);
    
    ofLine(770, 400, 770, 400-255);
    ofLine(770, 400, 770+255, 400);
    
    histogramMax = 0;
    maxIndex = 0;
    for(int x = 0 ; x < 256 ; x++) {
        if (histogram[x]>histogramMax) {
            histogramMax = histogram[x];
            maxIndex = x;
            }
        histogram[x] = histogram[x]/100;
        //cout << x << " : " << histogram[x] << "\n";
        ofLine(x+770, 400-histogram[x], x+770, 400);
    }

    ofSetColor(255,0,0);
    ofLine(maxIndex+770, 400-histogram[maxIndex], maxIndex+770, 400);
    
    ofSetColor(0);
	ofDrawBitmapString("Histogram : ", 770, 100);
	ofDrawBitmapString("0                             255 ", 770, 415);
	ofDrawBitmapString("0", 755, 400);
	ofDrawBitmapString("???", 773, 150);

    threshold = 128;
    for(int y = 0; y < camHeight; y++) {
        for(int x = 0; x < camWidth; x++) {
            ofColor cur = currentFrame.getColor(x, y);
            int lightness = cur.getLightness();
            ofColor pixel;
            if (lightness<threshold) pixel.set(0, 0, 0);
            else pixel.set(255, 255, 255);
            currentFrameCopy.setColor(x, y, pixel);
        }
    }
    
    ofSetColor(255);
    currentFrameCopy.reloadTexture();
    currentFrameCopy.draw(0, 480);


    

}