void draw(){ wc.begin(); if(!switchVideo){ wc.setUniformTexture("colorMap", img.getTexture(), 1); wc.setUniformTexture("heightMap",gray.getTexture(), 2); } else{ wc.setUniformTexture("colorMap", player.getTexture(), 1); fboDepth.begin(); player.draw(0,0); fboDepth.end(); wc.setUniformTexture("heightMap",fboDepth.getDepthTexture(),2); } wc.setUniform1f("time", ofGetElapsedTimef()*time); wc.setUniform1f("gradientStep", stepGradient); wc.setUniform1f("advectStep", advectStep); wc.setUniform1f("flipHeightMap",flipHeightMap); wc.setUniform4f("advectMatrix",advectMatrix->w,advectMatrix->x,advectMatrix->y,advectMatrix->z); fbo.draw(0,0); wc.end(); img.draw(0,0,img.getWidth()/4,img.getHeight()/4); player.draw(img.getWidth()/4,0,img.getWidth()/4,img.getHeight()/4); gui.draw(); }
genImg::genImg(ofImage &src, int scale, int nColors) { dna = DNA(src.getWidth()*scale * src.getHeight()*scale, nColors); img.allocate(src.getWidth()*scale, src.getHeight()*scale, OF_IMAGE_COLOR); heatmap.allocate(src.getWidth()*scale, src.getHeight()*scale, OF_IMAGE_COLOR); fitness = 1; }
void setup(float x, float y, string path, string videoPath){ img.loadImage(path); r.set(x,y,img.getWidth(),img.getHeight()); video = videoPath; thumbPath = path; loadPos(); }
//------------------------------------------------------------------------- void ofxRfeUIImageButton::setup(ofImage _button_image, float _x, float _y){ x = _x; y = _y; w = _button_image.getWidth(); h = _button_image.getHeight(); buttonImage = _button_image; buttonImageHighlight = _button_image; ofPixels pixels = buttonImageHighlight.getPixelsRef(); for (int x = 0; x < buttonImageHighlight.getWidth(); x++) { for (int y = 0; y < buttonImageHighlight.getHeight(); y++) { ofColor cur = pixels.getColor(x, y); cur.r = 255 - cur.r; cur.g = 255 - cur.g; cur.b = 255 - cur.b; pixels.setColor(x, y, cur); } } buttonImageHighlight.setFromPixels(pixels); }
string ofxBaseGui::saveStencilToHex(ofImage& img) { stringstream strm; int width = img.getWidth(); int height = img.getHeight(); int n = width * height; unsigned char cur = 0; int shift = 0; strm << "{"; for(int i = 0; i < n;) { if(img.getPixels()[i * 4 + 3] > 0) { cur |= 1 << shift; } i++; if(i % 8 == 0) { strm << "0x" << hex << (unsigned int) cur; cur = 0; shift = 0; if(i < n) { strm << ","; } } else { shift++; } } strm << "}"; return strm.str(); }
// image2data converts an image to OctoWS2811's raw data format. // The number of vertical pixels in the image must be a multiple // of 8. The data array must be the proper size for the image. //-------------------------------------------------------------- void ofxTeensyOcto::image2data(ofImage image, unsigned char* data, bool layout) { int offset = 3; int x, y, xbegin, xend, xinc, mask; int linesPerPin = image.getHeight() / 8; int* pixel = new int[8]; // get the copied image pixels pixels2 = image.getPixels(); // 2d array of our pixel colors for (int x = 0; x < ledWidth; x++) { for (int y = 0; y < (ledHeight * stripsPerPort * numPortsMain); y++) { int loc = x + y * ledWidth; colors[loc] = pixels2.getColor(x, y); } } for (y = 0; y < linesPerPin; y++) { if ((y & 1) == (layout ? 0 : 1)) { // even numbered rows are left to right xbegin = 0; xend = image.getWidth(); xinc = 1; } else { // odd numbered rows are right to left xbegin = image.getWidth() - 1; xend = -1; xinc = -1; } for (x = xbegin; x != xend; x += xinc) { for (int i=0; i < 8; i++) { int temploc = x + (y + linesPerPin * i) * image.getWidth(); pixel[i] = colors[temploc].getHex(); pixel[i] = colorWiring(pixel[i]); } // convert 8 pixels to 24 bytes for (mask = 0x800000; mask != 0; mask >>= 1) { unsigned char b = 0; for (int i=0; i < 8; i++) { if ((pixel[i] & mask) != 0) b |= (1 << i); } data[offset++] = b; } } } }
void RunningDraw::drawTitle(ofImage title){ Settings* settings = Settings::getInstance(); float title_x= settings->getWidth() / 2 - title.getWidth() * SCALE/2; float title_y = settings->getTitleY(); title.draw(title_x, title_y, title.getWidth() * SCALE, title.getHeight() * SCALE); }
void draw() { ofBackgroundGradient(64, 0); if(reflect || sreflect) env.draw(0,0,env.getWidth()/8,env.getHeight()/8); if(sreflect) env1.draw(env.getWidth()/8,0,env1.getWidth()/8,env1.getHeight()/8); ofEnableDepthTest(); cam.begin(); shader.begin(); if(sreflect){ // shader.setUniform3f("CameraPos",cam.getGlobalPosition().x, cam.getGlobalPosition().y, cam.getGlobalPosition().z); // shader.setUniformMatrix4f("ModelWorld4x4",cam.getGlobalTransformMatrix()); shader.setUniform3f("CameraPos",cam.getPosition().x, cam.getPosition().y, cam.getPosition().z); shader.setUniformMatrix4f("ModelWorld4x4",cam.getModelViewMatrix());//getLocalTransformMatrix()); shader.setUniformTexture("frontMap", env,1); shader.setUniformTexture("backMap", env1,2); } if(reflect){ shader.setUniformTexture("colorMap",env1,1); shader.setUniformTexture("envMap", env,2); }else if(sreflect==false){ shader.setUniformTexture("texture", img, 1); shader.setUniform1f("time", ofGetElapsedTimef()); } if(cube) ofDrawBox(200); else { ofTranslate(0,-150,0); ofRotateX(-90); ofRotateY(-90); ofRotateZ(45); model.drawFaces(); } shader.end(); cam.end(); ofDisableDepthTest(); ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20); }
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); } }
void makeThumb(string vidPath, string thumb){ ofVideoPlayer tmp; tmp.loadMovie(vidPath); tmp.play(); tmp.setPosition(0.3); ofImage img; img.setFromPixels( tmp.getPixelsRef() ); img.resize(120, 120.0f * (img.getHeight() / img.getWidth()) ); img.saveImage(thumb); }
//-------------------------------------------------------------- void testApp::setup(){ quadmesh.create(150, 50, 400, 300, 8); quadimage.loadImage("1.jpg"); quadtexture = genTex(quadimage.getWidth(), quadimage.getHeight(), quadimage.getPixels()); // if use GL_TEXTURE_RECTANGLE, change texture coord from [1,1] to [width, height] //quadmesh.ResetTextureCoords(quadimage.getWidth(), quadimage.getHeight()); }
//----------------------------------------------------- void ofxSURFTracker::detect(ofImage &img) { int inputWidth = img.getWidth(); int inputHeight = img.getHeight(); if(inputWidth < width || inputHeight < height) { return; // detection impossible, because I can't crop out of this image } detect(img.getPixels(), inputWidth, inputHeight); }
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); } }
static int getAvgBrightness(ofImage img) { int total = 0; int width = img.getWidth(); int height = img.getHeight(); for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { total += img.getPixels().getColor(i, j).getBrightness(); } } return total / (width*height); }
static ofPoint getAvgColor(ofImage img) { ofPoint total(0,0,0); int width = img.getWidth(); int height = img.getHeight(); ofPixels pixels = img.getPixels(); for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { ofColor col = pixels.getColor(i, j); total += ofPoint(col.r, col.g, col.b); } } return total / (width*height); }
//-------------------------------------------------------------- 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; }
ofTexture ofxImageTS::invert(ofImage image){ ofTexture texture; ofPixels copy; copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB); texture.allocate(image); for(int i = 0; i < image.getPixels().size()-3; i += 3){ copy[i] = 255 - image.getPixels()[i]; copy[i+1] = 255 - image.getPixels()[i+1]; copy[i+2] = 255 - image.getPixels()[i+2]; } texture.loadData(copy); return texture; }
ofTexture ofxImageTS::alterColorB(ofImage image,float B){ ofTexture texture; ofPixels copy; copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB); texture.allocate(image); for(int i = 0; i < image.getPixels().size()-3; i += 3){ copy[i] = 0; copy[i+1] = 0; copy[i+2] = image.getPixels()[i] * B; } texture.loadData(copy); return texture; }
ofTexture ofxImageTS::tanGB(ofImage image){ ofTexture texture; ofPixels copy; copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB); texture.allocate(image); float Tan; for(int i = 0; i < image.getPixels().size()-3; i += 3){ Tan = tan(i); copy[i] = image.getPixels()[i]; copy[i+1] = Tan * image.getPixels()[i+1]; copy[i+2] = Tan * image.getPixels()[i+2]; } texture.loadData(copy); return texture; }
ofTexture ofxImageTS::noise(ofImage image, float mix) { float avg; ofTexture texture; ofPixels copy; copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB); texture.allocate(image); for(int i = 0; i < image.getPixels().size()-3; i += 3){ avg = (image.getPixels()[i] + image.getPixels()[i+1] + image.getPixels()[i+2])/3.0f; copy[i] = avg * (125 - avg) * mix; copy[i+1] = avg * (125 - avg) * mix; copy[i+2] = avg * (125 - avg) * mix; } texture.loadData(copy); return texture; }
ofTexture ofxImageTS::greyScale(ofImage image) { int avg; ofTexture texture; ofPixels copy; copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB); texture.allocate(image); for(int i = 0; i < image.getPixels().size()-3; i += 3){ avg = (image.getPixels()[i] + image.getPixels()[i+1] + image.getPixels()[i+2])/3; copy[i] = avg; copy[i+1] = avg; copy[i+2] = avg; } texture.loadData(copy); return texture; }
ofTexture ofxImageTS::sinusoidal(ofImage image){ ofTexture texture; ofPixels copy; copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB); texture.allocate(image); float Sin; for(int i = 0; i < image.getPixels().size()-3; i += 3){ Sin = (sin(i) + 1)/2.0f; copy[i] = Sin * image.getPixels()[i]; copy[i+1] = Sin * image.getPixels()[i+1]; copy[i+2] = Sin * image.getPixels()[i+2]; } texture.loadData(copy); return texture; }
//-------------------------------------------------------------- void testApp::draw(){ ofSetColor(255, 255, 255); colorImg.draw(0, 0, ofGetWidth(), ofGetHeight()); glPushMatrix(); glScalef(ofGetWidth() / (float)greyImageSmall.getWidth(), ofGetHeight() / (float)greyImageSmall.getHeight(), 1); // haarTracker.draw(0, 0); ofNoFill(); for(int i = 0; i < haarFinder.blobs.size(); i++) { ofRectangle cur = haarFinder.blobs[i].boundingRect; // ofRect(cur.x, cur.y, cur.width, cur.height); int iw = cur.width * 1.4; img.draw(haarFinder.blobs[i].centroid, iw, iw * img.getHeight() / img.getWidth()); } glPopMatrix(); }
void captureApp::generateSpotlight(ofImage& img) { int diffusion = 100; img.setImageType(OF_IMAGE_GRAYSCALE); unsigned char* pixels = img.getPixels(); int w = img.getWidth(); int h = img.getHeight(); float maxDistance = (w < h ? w : h) / 2; for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { int i = y * w + x; int xrand = ofRandom(-diffusion, diffusion); int yrand = ofRandom(-diffusion, diffusion); pixels[i] = pow(ofMap(ofDist(w / 2, h / 2, x + xrand, y + yrand), 0, maxDistance, 1, 0, true), 4) * 255; } } img.update(); }
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(); }
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 update() { float time = ofGetElapsedTimef(); ocl.begin(); cl::ImageGL cl_destImage; ofxCL::convert( destImage.getTextureReference(), cl_destImage ); ofxCL::Kernel::Ref noiseKernel = noiseProgram.getKernel( methodNames.at(methodIndex) ); noiseKernel->global( destImage.getWidth(), destImage.getHeight() ); float t = time * 0.1f; // ofParameters do not seem to get passed on correctly. Todo: avoid this workaround. float tmpLacunarity = Lacunarity; float tmpIncrement = Increment; float tmpOctaves = Octaves; float tmpAmplitude = Amplitude; ofVec2f bias(0,0); if( AutoMove ) { bias.x = ofSignedNoise( t, t * -0.30f ) * AutoMoveMagnitude; bias.y = ofSignedNoise( -t, t * 0.33f ) * AutoMoveMagnitude; } float tmpScale = Scale * ScaleMultiplier; if( methodIndex == 0 ) { noiseKernel->call( cl_destImage, bias, ofVec2f(tmpScale,tmpScale), tmpAmplitude ); } else { noiseKernel->call( cl_destImage, bias, ofVec2f(tmpScale,tmpScale), tmpLacunarity, tmpIncrement, tmpOctaves, tmpAmplitude ); } ocl.end(); }
// this could also be done with OpenCV, cvResize + CV_INTER_NN // or even faster by precomputing a remap function void threadedScanLoader::resize(ofImage& from, ofImage& to, int toWidth, int toHeight) { to.allocate(toWidth, toHeight, OF_IMAGE_COLOR_ALPHA); unsigned char* fromPixels = from.getPixels(); unsigned char* toPixels = to.getPixels(); int toPosition = 0; int fromWidth = from.getWidth(); int fromHeight = from.getHeight(); for(int toy = 0; toy < toHeight; toy++) { int fromy = (toy * fromHeight) / toHeight; int fromPosition = fromy * fromWidth; for(int tox = 0; tox < toWidth; tox++) { int fromx = (tox * fromWidth) / toWidth; int cur = (fromPosition + fromx) * 4; toPixels[toPosition++] = fromPixels[cur + 0]; toPixels[toPosition++] = fromPixels[cur + 1]; toPixels[toPosition++] = fromPixels[cur + 2]; toPixels[toPosition++] = fromPixels[cur + 3]; } } }
void LutFilter::filter(ofImage& image) { if(type != image.type) { ofLog(OF_LOG_ERROR, "Image type does not match LUT type. Aborting!"); return; } int n = (int) image.getWidth() * (int) image.getHeight(); unsigned char* pixels = image.getPixels(); if(type == OF_IMAGE_COLOR) { unsigned char* end = &pixels[n * 3]; while(pixels != end) { *(pixels++) = rgbGamma[*pixels][0]; *(pixels++) = rgbGamma[*pixels][1]; *(pixels++) = rgbGamma[*pixels][2]; } } else if(type == OF_IMAGE_GRAYSCALE) { unsigned char* end = &pixels[n]; while(pixels != end) *(pixels++) = grayGamma[*pixels]; } }