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++; } } }
void makeTransparent(ofImage &img) { img.setImageType(OF_IMAGE_COLOR_ALPHA); //make sure it can have alphas for(int i = 3; i < img.height*img.width*4; i+=4){ if(img.getPixels()[i-1]==0) { //if blue is 0 make pixel transparent img.getPixels()[i]=0; } } img.update(); }
//-------------------------------------------------------------- // create a visual representation of the simulation void Rd::getImage(ofImage & image, const ofColor & c1, const ofColor & c2){ unsigned char * pixels = image.getPixels(); for(int indexImg = 0, indexA = 0; indexA < A.size(); indexImg += 3, indexA++){ ofColor c = c1.getLerped(c2, A[indexA] * A[indexA]); pixels[indexImg] = c.r; pixels[indexImg + 1] = c.b; pixels[indexImg + 2] = c.g; } image.update(); }
void ofApp::update() { step(); unsigned char* pixels = buffer.getPixels(); int n = num * num; for (int i = 0; i < n; i++) { pixels[i] = 128 + 100*grid[i]; } buffer.update(); }
void convert(ofxCvGrayscaleImage &src, ofImage &dst) { for(int i = 0; i < src.height*src.width; i += 1) { if(src.getPixels()[i]==0) { dst.getPixels()[i*4] = 0; } else { dst.getPixels()[i*4] = 0xffffffff; } } dst.update(); }
void testApp::normalizeImage(ofImage& img, ofImage& normalized) { srcTracker.update(toCv(img)); if(srcTracker.getFound()) { drawNormalized(srcTracker, img, srcNormalized); normalized.allocate(normalizedWidth, normalizedHeight, OF_IMAGE_COLOR); srcNormalized.readToPixels(normalized.getPixelsRef()); normalized.update(); } else { ofLogWarning() << "couldn't find the face" << endl; } }
//-------------------------------------------------------------- void testApp::update(){ unsigned char * pixels = img2.getPixels(); for(int x = 0;x<600;++x){ for(int y=0;y<200;++y){ char brightess = ofMap(ofNoise(x*faktor,y*faktor,ofGetFrameNum()*faktor),0,1,0,255); pixels[y*600+x] = brightess; } } unsigned char * rgbPixels = img3.getPixels(); for(int x = 0;x<600;++x){ for(int y=0;y<200;++y){ for(int c=0;c<3;++c){ rgbPixels[(y*600+x)*3+c] = ofMap(ofNoise(x*faktor,y*faktor,c,ofGetFrameNum()*faktor),0,1,0,255); } } } img2.update(); img3.update(); }
void ofxDepthImageCompressor::convertTo8BitImage(unsigned short* buf, ofImage& image){ int nearPlane = 500; int farPlane = 7000; unsigned char* pix = image.getPixels(); int stride = image.getPixelsRef().getNumChannels(); for(int i = 0; i < 640*480; i++){ //ofMap(buf[i], nearPlane, farPlane, 255, 0, true); unsigned char value = buf[i] == 0 ? 0 : 255 - (255 * (buf[i] - nearPlane) ) / farPlane;// + ofMap(buf[i], nearPlane, farPlane, 255, 0, true); for(int c = 0; c < stride; c++){ pix[i*stride+c] = value; } } image.update(); }
void update(){ grayImg = colorImg; grayImg.threshold( ofMap(ofGetMouseX(), 0, 900, 0, 255) ); Canny(grayImg, cannyImg, 120, 120, 3); thin(cannyImg); cannyImg.update(); cannyInvertImg = cannyImg; invert(cannyInvertImg); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetFrameRate(60); img.allocate(600,200,OF_IMAGE_GRAYSCALE); img2.allocate(600,200,OF_IMAGE_GRAYSCALE); img3.allocate(600,200,OF_IMAGE_COLOR); unsigned char * pixels = img.getPixels(); for(int x = 0;x<600;++x){ for(int y=0;y<200;++y){ char brightess = ofMap(ofNoise(x*faktor,y*faktor),0,1,0,255); pixels[y*600+x] = brightess; } } 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 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 synthImage() { const int num_pixels = w * h; unsigned char *synth_pixels = synth.getPixels(); unsigned char *img1_pixels = img1.getPixels(); // amount for (int i=0; i<num_pixels; i++) avarage_pixel_value += img1_pixels[i]; // calc avarage avarage_pixel_value /= num_pixels; // set to synth image for (int i=0; i<num_pixels; i++) synth_pixels[i] = avarage_pixel_value; // update texture synth.update(); }
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(); }