bool ChainCode::GetFirstChnPix(ofVec2f* curPixel, ofImage EG_map)
{
	int w = ofGetWidth();
	int h = ofGetHeight();
	ofColor black;
	black.set(0,0,0);
	int x = curPixel->x;
	int y = curPixel->y;
	ofVec2f orgPixel;
	orgPixel.set(*curPixel);
	// Find the first edge pixel
	while(y<h && *curPixel == orgPixel)
	{
		y++;
		x = 0;
		while(x<w && *curPixel == orgPixel)
		{
			if(EG_map.getColor(x,y)==black)
				curPixel->set(x,y);
			x++;
		}
	}
	if(EG_map.getColor(curPixel->x,curPixel->y)==black)
	{
		//cout<<"Found the first edge pixel: "<<curPixel->x<<", "<<curPixel->y<<endl;
		return true;
	}
	else
		return false;
}
Example #2
0
void Particle::update( const ofImage &img, ofVec2f mousePos ) {

    vel += acc;

    float maxVel = 2.0;
    if( vel.lengthSquared() > maxVel*maxVel ) {
        vel.normalize();
        vel *= maxVel;
    }

    pos += vel;
    vel *= decay;
    acc.set(0,0);

    // we don't care about age any more
//    age++;
//    if( age > lifespan ){
//        bIsDead = true;
//    }

//    float agePct = 1.0 - ((float)age / (float)lifespan);
//    radius = agePct * 3.0;

    radius = img.getColor(pos.x, pos.y).r / 255.0 * 3.0;

    mass = radius * radius * 0.0001f + 0.01f;
}
Example #3
0
void Particle::update( const ofImage &img ){
    
    grayValue = img.getColor( pos.x, pos.y ).g;
    radius = ((float)grayValue / 255.0) * 7.0;
    
    radius = 4;
}
ofVec3f getVertexFromImg(ofImage& img, int x, int y) {
	ofColor color = img.getColor(x, y);
	if(color.a > 0) {
		float z = ofMap(color.a, 0, 255, -480, 480);
		return ofVec3f(x - img.getWidth() / 2, y - img.getHeight() / 2, z);
	} else {
		return ofVec3f(0, 0, 0);
	}
}
ofVec3f getVertexFromImg(ofImage& img, int x, int y) {
	ofColor color = img.getColor(x, y);
	if(color.a > 200) {  //adjust to get a good image
		float z = ofMap(color.a, 200, 255, -480, 480); //mapping alpha to a good range
		return ofVec3f(x - img.getWidth() /2, y - img.getHeight() / 2, z);
	} else {
		return ofVec3f(0, 0, 0);
	}
}
Example #6
0
ofVec3f getVertexFromImg(ofImage& pastImg, int x, int y) {   
	ofColor color = pastImg.getColor(x, y);
	if(color.a > 0) {
		float z = ofMap(color.a, 0, 255, -480, 480);
        // this maps this to -480, 480
		return ofVec3f(x - pastImg.getWidth() / 2, y - pastImg.getHeight() / 2, z);
	} else {
		return ofVec3f(0, 0, 0);
	}
}
Example #7
0
//--------------------------------------------------------------
ofMesh testApp::pixelManipulate(ofImage imageA, ofMesh meshA, float intensityThreshold, float sketchDepth){
    
    
    imageA.resize(200, 200);
    
    //create mesh with points as the primitive
    //meshA.setMode(OF_PRIMITIVE_POINTS);
    
    //create a mesh with lines
      meshA.setMode(OF_PRIMITIVE_LINE_LOOP);
    
    //meshA.setMode(OF_PRIMITIVE_LINE_STRIP);
    
    
    int w = imageA.getWidth();
    
    int h = imageA.getHeight();
    
    //loop through each pixel in the image using image width & height
    for (int x=0; x<w; x++){
        for(int y=0; y<h; y++){
            
            //create the color object at that pixel
            //ofColor c = imageA.getColor(x, y);
            
            ofColor c = imageA.getColor(x, y);

            
            //check the intensity of the pixel's color
            float intensity = c.getLightness();
            
            //if the intensity exceeds the threshold, create a vertex at the location of the pixel
            //& color it with the pixel's color
            if (intensity >= intensityThreshold){
                
                //pushes brighter colors in the positive z direction
                //pushes whiter colors in the negative z direction
                float saturation = c.getSaturation();
                float z = ofMap(saturation, 0, 255, -sketchDepth, sketchDepth);
                
                //the image is now 1/4 the size of the OF window, so multiply
                //the pixel location by 4 so that the mesh covers the OF window
                ofVec3f pos(5*x, 4*y, z);
                meshA.addVertex(pos);
                meshA.addColor(c);
            }
        }
    }
    
    return meshA;
}
Example #8
0
ofColor RGB2rgb(pos i, ofImage inROI){
	//Get RBG of pixel position i
	ofColor temp = inROI.getColor(i.getX(),i.getY());
	//convert to rg -> r = \frac{R}{R+G+B}  g = \frac{G}{R+G+B}  b = \frac{B}{R+G+B}
	//we only need the r and g values since r+g+b=1 so we can calculate b value when needed
	ofColor outCol = temp;

	if(temp.r != 0)outCol.r = (unsigned char)(((float)temp.r/((float)temp.r + (float)temp.g + (float)temp.b))*255.0f);
	if(temp.g != 0)outCol.g = (unsigned char)(((float)temp.g/((float)temp.r + (float)temp.g + (float)temp.b))*255.0f);
	outCol.b = (unsigned char)abs(((int)outCol.r + (int)outCol.g) - 255);

	//cout << "red: " << (int)outCol.r << " green: " << (int)outCol.g << " blue: " << (int)outCol.g << endl;

	//return the new rg color
	return outCol;
}
Example #9
0
void Particles::update(ofImage img){
    
    
    //Uncomment if you want to have some particles dancing. It might get super slow though.
    //    pos.x = ofRandom(0, ofGetWindowWidth());
    //    pos.y = ofRandom(0, ofGetWindowHeight());
    
    diagonal = ofDist( 0, 0 , ofGetWindowWidth(), ofGetWindowHeight());
    
    tempSize = ofDist(ofGetMouseX(), ofGetMouseY(), pos.x, pos.y);
    
    
    rectSize = ofMap( tempSize, 0, diagonal, 0, rectSizeMax);
    
    pixelColor = img.getColor(pos.x,pos.y);
    
    
    
}
Example #10
0
void Particle::update( const ofImage &img, ofVec2f mousePos ) {

    // this gives us a vector of the direction from the mouse, to our particle
    dirToCursor = mousePos - pos;
    dirToCursor.normalize();
    newLoc = pos + dirToCursor * 50.0;


//    float timeOffset = ofGetElapsedTimef() * 4.0;
//    dirToCursor = mousePos - pos;
//    float dist = dirToCursor.length() * 0.05;
//    float sinOffset = sin( dist - timeOffset ) * 100.0;
//    dirToCursor.normalize();
//
//    newLoc = pos + dirToCursor * sinOffset;

    newLoc.x = ofClamp( newLoc.x, 0.0, img.width );
    newLoc.y = ofClamp( newLoc.y, 0.0, img.height );

    grayValue = img.getColor( newLoc.x, newLoc.y ).r;
}
Example #11
0
//get the average color for a poly within a region
//for some definition of average ...
ofColor
getAverageColor(ofImage i, ofRectangle bounds, int nverts, float *vertx, float * verty)
{
    float r, g, b;
    r = g = b = 0;
    float ncols = 0;
    
    for (int x = bounds.x; x <= bounds.width; x++) {
        for (int y = bounds.y; y <= bounds.height; y++) {
            if (pnpoly(nverts, vertx, verty, x, y)) {
                ofColor c = i.getColor(x, y);
                r += c.r;
                g += c.g;
                b += c.b;
                ncols += 1.0;
            }
        }
    }
    
    return(ofColor(r/ncols, g/ncols, b/ncols));
}
Example #12
0
void img2integralImg(ofImage imgIn, colorImg2integral sIn,vector<vector<int>>& outVec){
	
	int height = imgIn.getHeight();
	int width = imgIn.getWidth();
	
	for(int i = 0 ; i < width ; i++){
		for(int j = 0 ; j < height ; j++){
			
			int currentVal;

			//Choose what color to make it from
			switch (sIn){
			case RED :
				currentVal = imgIn.getColor(i,j).r;
				break;
			case GREEN :
				currentVal = imgIn.getColor(i,j).g;
				break;
			case BLUE :
				currentVal = imgIn.getColor(i,j).b;
				break;
			case MEAN : 
				currentVal = (imgIn.getColor(i,j).r + imgIn.getColor(i,j).g + imgIn.getColor(i,j).b) / 3;
				break;
			//Error massage for when colorImg2integral sIn is out of range
			default : 
				cout << "invalid input for img2integralImg" << endl;
			}

			//Updating the integral image with the value for the given pixel
			currentVal;
			if(j == 0 && i == 0){
				outVec.push_back(vector<int>());
				outVec[i].push_back(currentVal);
			}else if(j == 0){
				outVec.push_back(vector<int>());
				outVec[i].push_back(outVec[i-1][j] + currentVal);
			}else if(i == 0){
				outVec[i].push_back(outVec[i][j-1] + currentVal);
			}else{
				outVec[i].push_back(outVec[i-1][j] + outVec[i][j-1] + currentVal - outVec[i-1][j-1]);
			}
		}
	}
};
void MeterGridPoint::update(const ofImage &image) {
    mReading = image.getColor(mX, mY).getBrightness();
}
//--------------------------------------------------------------
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);


    

}
Example #15
0
void fmVertController::draw(ofImage img) {
    for(fmVert v: verts)
        v.draw(img.getColor(v.loc.x, v.loc.y));

}
Example #16
0
void ckvdSingleColorGrabber::setColorFromFrame(ofImage& frame)
{
    _color = frame.getColor(x, y);
    _fixture.set_rgb(_color.r, _color.g, _color.b);
}
//-----------------------------------------------------------------------------------
//
// Search in the next direction, if found one, update the curPixel and return
//
//-----------------------------------------------------------------------------------
bool ChainCode::SearchThisDir(ofVec2f* curPixel, int dir, ofImage EG_map)
{
	// Search the 3*3 neighborhood of curPixel
	switch(dir)
	{
	case 0:	// East
		if(EG_map.getColor(curPixel->x+1,curPixel->y) == 0)
		{
			curPixel->x++;
			return true;
		}
		else
			return false;
	case 1:	// Northeast
		if(EG_map.getColor(curPixel->x+1,curPixel->y-1) == 0)
		{
			curPixel->x++;
			curPixel->y--;
			return true;
		}
		else
			return false;
	case 2:	// North
		if(EG_map.getColor(curPixel->x,curPixel->y-1) == 0)
		{
			curPixel->y--;
			return true;
		}
		else
			return false;
	case 3: // Northwest
		if(EG_map.getColor(curPixel->x-1,curPixel->y-1) == 0)
		{
			curPixel->x--;
			curPixel->y--;
			return true;
		}
		else
			return false;
	case 4:	// West
		if(EG_map.getColor(curPixel->x-1,curPixel->y) == 0)
		{
			curPixel->x--;
			return true;
		}
		else
			return false;
	case 5:	// Southwest
		if(EG_map.getColor(curPixel->x-1,curPixel->y+1) == 0)
		{
			curPixel->x--;
			curPixel->y++;
			return true;
		}
		else
			return false;
	case 6:	// South
		if(EG_map.getColor(curPixel->x,curPixel->y+1) == 0)
		{
			curPixel->y++;
			return true;
		}
		else
			return false;
	case 7:	// Southeast
		if(EG_map.getColor(curPixel->x+1,curPixel->y+1) == 0)
		{
			curPixel->x++;
			curPixel->y++;
			return true;
		}
		else
			return false;
	default:
		return false;

	}
}