void ModeFour::setup( ofVideoGrabber &vidGrabber, vector<MovingBackground> &bkgListFour ) { width = ofGetWindowWidth(); height = ofGetWindowHeight(); //setting up lines and control points int numLines = ofGetWindowWidth() / 10; int numBreaks = ofGetWindowHeight() / 8; for (int i = -15; i <numLines+15; i++){ ofPolyline line; lineList.push_back(line); for (int j = -15; j < numBreaks+15; j++){ Curtain c; c.setup(ofVec2f (i*10, j*8)); pList.push_back(c); lineList[i+15].addVertex(ofVec2f(c.pos.x,c.pos.y)); } } background.loadImage("tint.jpg"); //setting up flowsolver flowSolver.setup(vidGrabber.getWidth(), vidGrabber.getHeight(), 0.5, 3, 10, 1, 7, 1.5, false, false); bkgListFour[0].setup("bkg_modeFour_0.png"); bkgListFour[1].setup("bkg_modeFour_1.png"); bkgListFour[2].setup("bkg_modeFour_2.png"); bkgListFour[3].setup("bkg_modeFour_3.png"); }
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 ofApp::setup(){ //we can now get back a list of devices. vector<ofVideoDevice> devices = vidGrabber.listDevices(); for(int i = 0; i < devices.size(); i++){ cout << devices[i].id << ": " << devices[i].deviceName; if( devices[i].bAvailable ){ cout << endl; }else{ cout << " - unavailable " << endl; } } vidGrabber.setDeviceID(1); vidGrabber.setVerbose(true); vidGrabber.initGrabber(width, height); recorded = (unsigned char*)malloc(3 * height * width * record_size); tmp = (unsigned char*)malloc(3 * height * width); back = (unsigned char*)malloc(3 * height * width); merged = (unsigned char*)malloc(3 * height * width); show = vidGrabber.getPixels(); udpConnection.Create(); udpConnection.Bind(1511); udpConnection.SetNonBlocking(true); for (int i = 0; i < trackers_cnt; i++) { tracker t = tracker(i); trackers.push_back(t); } outfile.open("/users/yui/desktop/yellow_imgs/teacher/log.txt", std::ios_base::app); }
FREObject updateCameraFrame(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { gGrabber.update(); if( !gGrabber.isFrameNew() ) return NULL; FREObject as3Bitmap = argv[0]; FREBitmapData bitmapData; FREAcquireBitmapData(as3Bitmap, &bitmapData); // do something uint32_t r = rand() % 255; uint32_t g = rand() % 255; uint32_t b = rand() % 255; unsigned char *pixel = gGrabber.getPixels(); uint32_t* ptr = bitmapData.bits32; int offset = bitmapData.lineStride32 - bitmapData.width; int alpha = 255; for( uint32_t j = 0; j < bitmapData.height; j++ ){ ptr = bitmapData.bits32 + bitmapData.lineStride32*(bitmapData.height-j-1); for( uint32_t i = 0; i < bitmapData.width; i++ ){ r = *pixel++; g = *pixel++; b = *pixel++; *ptr++ = (alpha << 24) | (r << 16) | (g << 8) | b; } } FREInvalidateBitmapDataRect(as3Bitmap, 0, 0, bitmapData.width, bitmapData.height); FREReleaseBitmapData(as3Bitmap); return NULL; }
void update() { cam.update(); if(cam.isFrameNew()) { Mat camMat = toCv(cam); tracker.update(camMat); trackerDataSave.load(tracker); } }
void update() { // Update our little offset thingy. offset += 0.01; if (offset > 1) { offset = 0; } // Update our camera. grabber.update(); // If the camera has a new frame to offer us ... if (grabber.isFrameNew()) { // Make a copy of our grabber pixels in the colorImage. colorImage.setFromPixels(grabber.getPixelsRef()); // When we assign a color image to a grayscale image, it is converted automatically. grayscaleImage = colorImage; // If we set learnBackground to true using the keyboard, we'll take a snapshot of // the background and use it to create a clean foreground image. if (learnBackground == true) { // We assign the grayscaleImage to the grayscaleBackgroundImage. grayscaleBackgroundImage = grayscaleImage; // Now we set learnBakground so we won't set a background unless // explicitly directed to with a keyboard command. learnBackground = false; } // Create a difference image by comparing the background and the current grayscale images. grayscaleAbsoluteDifference.absDiff(grayscaleBackgroundImage, grayscaleImage); // Assign grayscaleAbsoluteDifference to the grayscaleBinary image. grayscaleBinary = grayscaleAbsoluteDifference; // Then threshold the grayscale image to create a binary image. grayscaleBinary.threshold(threshold, invert); // Find contours (blobs) that are between the size of 20 pixels and // 1 / 3 * (width * height) of the camera. Also find holes. contourFinder.findContours(grayscaleBinary, 100, (width * height) / 3.0, 10, true); // Get the biggest blob and use it to draw. if (contourFinder.nBlobs > 0) { holePositions.addVertex(contourFinder.blobs[0].boundingRect.getCenter()); } else { holePositions.clear(); } } }
void update() { ofSetWindowTitle(ofToString(ofGetFrameRate())); cam.update(); if(cam.isFrameNew()) { if(ofGetKeyPressed()) { results = ccv.classifyFace(cam); } } }
void setup() { ofSetFrameRate(60); ofSetVerticalSync(true); ofBackground(0); video.initGrabber(1280, 720); isf.setup(1280, 720, GL_RGB32F); isf.load("isf-test"); isf.setImage("inputImage", video.getTexture()); }
void update() { vid.update(); if(vid.isFrameNew()) { unsigned char* pix = vid.getPixels(); int j = 0; for(int i = 0; i < n; i++) { unsigned char& r = pix[j++]; unsigned char& g = pix[j++]; unsigned char& b = pix[j++]; mesh.setVertex(i, ofVec3f(r+20, g+20, b+20)); mesh.setColor(i, ofColor(r+20, g+20, b+20)); } } }
void setup() { ofSetFrameRate(60); ofSetVerticalSync(true); ofBackground(0); video.initGrabber(1280, 720); chain.setup(1280, 720); chain.load("ZoomBlur.fs"); chain.load("CubicLensDistortion.fs"); chain.setImage(video.getTextureReference()); }
//-------------------------------------------------------------- void testApp::update(){ vidGrabber.grabFrame(); if(vidGrabber.isFrameNew()) { colorImg.setFromPixels(vidGrabber.getPixels(), vidGrabber.getWidth(), vidGrabber.getHeight()); colorImg.mirror(false, true); greyImage = colorImg; greyImageSmall.scaleIntoMe(greyImage); haarFinder.findHaarObjects(greyImageSmall); } }
void setup() { vid.initGrabber(w, h); mesh.setMode(OF_PRIMITIVE_POINTS); mesh.addVertices(vector<ofVec3f>(n)); mesh.addColors(vector<ofFloatColor>(n)); }
FREObject openCamera(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { gGrabber.initGrabber(1280, 720); return NULL; }
FREObject getCameraFrameSize(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { int w = gGrabber.getWidth(); int h = gGrabber.getHeight(); FREObject fX,fY; FRENewObjectFromInt32(w,&fX); FRENewObjectFromInt32(h,&fY); FREObject value = argv[0]; FRESetObjectProperty(value,(const uint8_t*)"w",fX,NULL); FRESetObjectProperty(value,(const uint8_t*)"h",fY,NULL); return NULL; }
void update() { video.update(); float t = ofGetElapsedTimef() * 2; isf.setUniform<float>("blurAmount", ofNoise(1, 0, 0, t) * 1.5); isf.update(); }
void draw() { ofPushMatrix(); float screenWidth = config["screen"]["width"]; float screenHeight = config["screen"]["height"]; float camWidth = config["camera"]["width"]; float camHeight = config["camera"]["height"]; ofTranslate(screenWidth / 2, screenHeight / 2); ofRotateZDeg(config["camera"]["rotate"]); ofTranslate(-camWidth / 2, -camHeight / 2); if(cam->isInitialized()) { cam->draw(0,0); } clipping.draw(0, 0); ofPopMatrix(); if(cam->isInitialized()) { drawHistogram(cam->getPixels(), mouseY); } }
// Called every frame. void update() { // Update our camera. grabber.update(); // If the camera has a new frame to offer us ... if (grabber.isFrameNew()) { // Get a reference (denoted by &) to the camera's pixels. Getting a // reference means that we won't have to make a copy of all of the // frame's pixels (since we only need one column anyway). This means our // program requires less processing power. // // const prevents us from accidentally modifying the cameras's pixels. const ofPixels& cameraPixels = grabber.getPixelsRef(); // Choose a slit location. In this case we'll collect slits from the // column in the middle of the camera feed. int slitPositionX = grabber.getWidth() / 2; // Cycle through each pixel in the selected column and place that pixel // at a position x = xPosition and y = to the same position as the // oritinal. for (int y = 0; y < grabber.getHeight(); y++) { // Get the pixel as a color at x / y from the grabber. ofColor pixelFromGrabber = cameraPixels.getColor(slitPositionX, y); // Set that pixel color to the x / y position in the output pixels. pixels.setColor(xPosition, y, pixelFromGrabber); } // Increment our xPosition so next update we'll draw a colum shifted to // the right by one pixel. xPosition = xPosition + 1; // If our xPosition is greater than or equal to the width of the display // pixels, reset our x position to 0. if (xPosition >= pixels.getWidth()) { xPosition = 0; } } }
void draw() { ofSetColor(255); cam.draw(0, 0); tracker.draw(); glPointSize(4); ofSetColor(ofColor::red); trackerDataSave.draw(); ofSetColor(ofColor::blue); trackerDataLoad.draw(); }
void setup() { ofSetVerticalSync(true); ofBackground(0); config = ofLoadJson("../../../SharedData/shared/config.json"); float camWidth = config["camera"]["width"]; float camHeight = config["camera"]["height"]; float camFrameRate = config["camera"]["framerate"]; device = config["camera"]["device"]; if (device == "blackmagic") { cam = &blackmagicGrabber; } else { cam = &videoGrabber; } cam->setDesiredFrameRate(camFrameRate); cam->setup(camWidth, camHeight); clipping.allocate(camWidth, camHeight, OF_IMAGE_COLOR_ALPHA); toggleGrayscale = false; updateWindowShape(); }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(50, 50, 50); // dump everything to console ofSetLogLevel(OF_LOG_VERBOSE); // disable vsync (to allow >60fps) ofSetVerticalSync(false); // init grabber videoGrabber.initGrabber(640, 480); vidWidth = videoGrabber.getWidth(); vidHeight = videoGrabber.getHeight(); // allocate temp buffer pixels = new unsigned char[vidWidth * vidHeight * 4]; // init OpenCL from OpenGL context to enable GL-CL data sharing openCL.setupFromOpenGL(); // create OpenCL textures and related OpenGL textures clImage[0].initWithTexture(vidWidth, vidHeight, GL_RGBA); clImage[1].initWithTexture(vidWidth, vidHeight, GL_RGBA); // load and compile OpenCL program openCL.loadProgramFromFile("MSAOpenCL/ImageProcessing.cl"); // load kernels openCL.loadKernel("msa_boxblur"); openCL.loadKernel("msa_flipx"); openCL.loadKernel("msa_flipy"); openCL.loadKernel("msa_greyscale"); openCL.loadKernel("msa_invert"); openCL.loadKernel("msa_threshold"); }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ switch(key) { case 'b': doBlur ^= true; break; case 'x': doFlipX ^= true; break; case 'y': doFlipY ^= true; break; case 'g': doGreyscale ^= true; break; case 'i': doInvert ^= true; break; case 't': doThreshold ^= true; break; case 's': videoGrabber.videoSettings(); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': blurAmount = key - '0'; break; case '[': threshLevel -= 0.05; if(threshLevel<0) threshLevel = 0; break; case ']': threshLevel += 0.05; if(threshLevel>1) threshLevel = 1; break; } }
void setup() { ofSetWindowShape(width, height); // Set the window size. grabber.initGrabber(width, height); // Set the grabber size. // Allocate each of our helper images. colorImage.allocate(width, height); grayscaleImage.allocate(width, height); grayscaleBackgroundImage.allocate(width, height); grayscaleAbsoluteDifference.allocate(width, height); grayscaleBinary.allocate(width, height); }
void draw() { cam.draw(0, 0); ofPushStyle(); ofNoFill(); ofSetLineWidth(2); for(int i = 0; i < results.size(); i++) { ofDrawRectangle(results[i]); ofDrawBitmapStringHighlight(ofToString(i), results[i].getPosition() + ofPoint(-5,-5)); } ofPopStyle(); ofDrawBitmapStringHighlight("press any key to track", 10,20); }
void ModeFour::update( ofVideoGrabber &vidGrabber ) { for (int i = 0; i < lineList.size(); i++) { for (int j = 0; j < lineList[i].getVertices().size(); j++) { int particleIndex = lineList[i].getVertices().size()*i + j; pList[particleIndex].update(flowSolver); lineList[i].getVertices()[j].set(pList[particleIndex].pos); } } //optical flow if(vidGrabber.isFrameNew()){ flowSolver.update(vidGrabber); } }
//-------------------------------------------------------------- void testApp::setup(){ vidGrabber.setVerbose(true); vidGrabber.initGrabber(640, 480); colorImg.allocate(vidGrabber.getWidth(), vidGrabber.getHeight()); greyImage.allocate(vidGrabber.getWidth(), vidGrabber.getHeight()); greyImageSmall.allocate(120, 90); haarFinder.setup("haarcascade_frontalface_alt2.xml"); img.loadImage("stevejobs.png"); img.setAnchorPercent(0.5, 0.5); ofEnableAlphaBlending(); }
//-------------------------------------------------------------- void testApp::draw(){ videoGrabber.draw(0, 200); // make sure all OpenCL kernels have finished executing before drawing openCL.finish(); // draw the OpenGL texture (which was mapped to the OpenCL image) clImage[activeImageIndex].getTexture().draw(vidWidth, 200); ofDrawBitmapString( " app FPS : " + ofToString(ofGetFrameRate(), 2) + "\n capture FPS : " + ofToString(captureFPS, 2) + "\n" + "\n doBlur (b) : " + (doBlur ? "X" : "") + "\n blurAmount (1-9) : " + ofToString(blurAmount) + "\n doFlipX (x) : " + (doFlipX ? "X" : "") + "\n doFlipY (y) : " + (doFlipY ? "X" : "") + "\n doGreyscale (g) : " + (doGreyscale ? "X" : "") + "\n doInvert (i) : " + (doInvert ? "X" : "") + "\n doThreshold (t) : " + (doThreshold ? "X" : "") + "\n threshLevel ([]) : " + ofToString(threshLevel, 2) , 30, 30); }
void ofApp::setup() { ofEnableSmoothing(); ofEnableAlphaBlending(); ofSetFrameRate(60); ofSetVerticalSync(true); ofEnableDepthTest(); ofEnableAntiAliasing(); memset( dmxData_, 0, DMX_DATA_LENGTH ); //open the device dmxInterface_ = ofxGenericDmx::createDevice(DmxDevice::DMX_DEVICE_RAW); bool opened = dmxInterface_->open(); if ( dmxInterface_ == 0 || !opened ) { printf( "No FTDI Device Found\n" ); } else { printf( "isOpen: %i\n", dmxInterface_->isOpen() ); } printf("ofxGenericDmx addon version: %s.%s\n", ofxGenericDmx::VERSION_MAJOR, ofxGenericDmx::VERSION_MINOR); std::string file = "Lightweave_loops2.json"; std::string columnsFile = "Lightweave_columns2.json"; std::string facesFile = "Lightweave_faces2.json"; bool parsingSuccessful = result.open(file); bool parsingSuccessfulColumn = columnGeometry.open(columnsFile); bool parsingSuccessfulFaces = faceGeometry.open(facesFile); for (int region = 0; region < 6; region++) { string blah = "region" + ofToString(region); for (int rings = 0; rings < result[blah].size(); rings++) { string ring = "ring" + ofToString(rings); for (int pointPos = 0; pointPos < 3; pointPos++) { string point = "point" + ofToString(pointPos); } } } //setupUDP(); camWidth = 320; camHeight = 240; vector<ofVideoDevice> devices = vidGrabber.listDevices(); for (int i = 0; i < devices.size(); i++) { if (devices[i].bAvailable) { ofLogNotice() << devices[i].id << ": " << devices[i].deviceName; } else { ofLogNotice() << devices[i].id << ": " << devices[i].deviceName << " - unavailable "; } } for (int i = 0; i < devices.size(); i++) { if (!devices[i].deviceName.find("USB")) { cout << devices[i].id << endl; pcCams.push_back(devices[i].id); } } vidGrabber.setDeviceID(pcCams[0]); // vidGrabber.setDeviceID(0); vidGrabber.initGrabber(320,240); vidGrabber1.setDeviceID(pcCams[1]); // vidGrabber1.setDeviceID(0); vidGrabber1.initGrabber(320,240); colorImg1.allocate(320,240); grayImage1.allocate(320,240); grayBg1.allocate(320,240); grayDiff1.allocate(320,240); colorImg.allocate(320,240); grayImage.allocate(320,240); grayBg.allocate(320,240); grayDiff.allocate(320,240); bLearnBackground = true; bLearnBackground1 = true; threshold = 80; drawOne = false; bottomSwarm.a = 1.1f; bottomSwarm.b = (curWidth/4.0); bottomSwarm.c = 100.0; bottomSwarm.bVel = 1.0; xPos = 0; yPos = 0; zPos = 0; cam.setPosition(result["region0"]["ring0"]["point0"][0].asFloat(),result["region0"]["ring0"]["point0"][1].asFloat(),result["region0"]["ring0"]["point0"][2].asFloat()); cam.lookAt(ofVec3f(result["region0"]["ring1"]["point0"][0].asFloat(),result["region0"]["ring1"]["point0"][1].asFloat(),result["region0"]["ring1"]["point0"][2].asFloat())); cam.rotate(ofRadToDeg(PI/2), 1.0, 0.0, 0.0); cam.setFov(32.0); sphereZPos = 25.9297; sphereXPos = 364.928; for (int i = 0; i < 20; i++) { spheresXPos[i] = ofRandom(result["region0"]["ring0"]["point0"][0].asFloat()-500, result["region0"]["ring0"]["point0"][0].asFloat()+500.0); spheresZPos[i] = ofRandom(result["region0"]["ring0"]["point0"][2].asFloat()-100.0, result["region0"]["ring0"]["point0"][2].asFloat()+100.0); } /* LIGHTING */ ofSetSmoothLighting(true); pointLight.setDiffuseColor( ofColor(0.f, 255.f, 0.f)); pointLight.setSpecularColor( ofColor(255.f, 255.f, 255.f)); pointLight.setPosition(result["region0"]["ring0"]["point0"][0].asFloat(),result["region0"]["ring0"]["point0"][1].asFloat(),result["region0"]["ring0"]["point0"][2].asFloat()); material.setShininess( 64 ); colorHue = ofRandom(0, 250); colorHue2 = ofRandom(0, 250); lightColor.setBrightness( 180.f ); lightColor.set(250,250,210); materialColor.setBrightness(250.f); materialColor.set(100,100,100); lightColor.setHue(colorHue); pointLight.setDiffuseColor(lightColor); materialColor.setHue(colorHue); material.setSpecularColor(materialColor); materialColor.set(255.0,0.0,0.0); columnMaterial.setSpecularColor(materialColor); materialColor.set(55.0,55.0,55.0); peopleMaterial.setSpecularColor(materialColor); cameraColor1.set(0.0, 0.0, 255.0); cameraColor2.set(0.0, 0.0, 255.0); columnColor.set(255, 0, 0); activeColor.set(0.0,0.0,255.0); }
void ofApp::draw() { ofBackground(0.0, 0.0, 0.0); ofSetColor(255.0,255.0,255.0); ofFill(); for (int i = 0; i < 10; i++) { ofDrawBitmapString(verbalInstructions[i], 10, (i*20)+600); } if (cameraInfoIsOn) { ofSetColor(255.0, 255.0, 255.0); ofFill(); /* drawing cameras */ ofSetColor(255.0,0.0,0.0); ofDrawBitmapString("Active column", 10, 30+10); ofSetColor(0.0,0.0,255.0); ofDrawBitmapString("Active camera #", 10, 50+10); ofSetColor(255,105,180); ofDrawBitmapString("# of Pedestrians", 10, 60+20); ofSetColor(255.0, 255.0, 255.0); int cnt = 0; for (int i = 300-70; i <= 300+700; i+=70) { if (cnt == 4 || cnt == 5 ) { ofSetColor(cameraColor1); ofDrawBitmapString("["+ofToString(cnt+1)+"]", i+22, 50+10); ofSetColor(255,105,180); ofDrawBitmapString((int)micLevelsTopNew[cnt], i+35, 60+10); cout << i+35 << endl; ofSetColor(255.0, 255.0, 255.0); } else { if (simulationIsOn) { ofSetColor(255,105,180); } else { ofSetColor(100,100,100); } ofDrawBitmapString((int)micLevelsTopNew[cnt], i+35, 60+10); cout << i+35 << endl; ofSetColor(255.0, 255.0, 255.0); ofDrawBitmapString("["+ofToString(cnt+1)+"]", i+22, 50+10); } cnt++; } cout << "" << endl; /* Draw Columns */ cnt = 0; ofFill(); ofSetColor(100.0, 100.0, 100.0); for (int i = 300; i <= 300+700; i+=70) { if (cnt == 4) { ofSetColor(columnColor); ofDrawCircle(i, 45, 7); ofSetColor(100.0, 100.0, 100.0); } else { ofDrawCircle(i, 45, 7); } cnt++; } int max_pos = 0; int max_element = -1000; for (int i = 0; i < 12; i++) { if (micLevelsTopNew[i] > max_element) { max_pos = i; max_element = micLevelsTopNew[i]; } } //ofVec2f btm = absColumnPositionTop[max_pos]; ofVec2f btm = cameraPositionsTop[max_pos]; ofVec2f desired = btm - swarmPosition; float d = sqrt((desired.x*desired.x) + (desired.y+desired.y)); float r = ofMap(ofClamp(d, 0.0, 700.0), 0.0, 700.0, 25.0, 76.5); ofColor swarmColor = ofColor(255.0, 0.0, 255.0); ofSetColor(swarmColor); ofDrawRectangle(swarmPosition.x, 45, 10, 50); ofSetColor(columnColor); ofFill(); ofDrawCircle(578, 270, 14); for (int i = 0; i < contourFinder.nBlobs; i++){ contourFinder.blobs[i].draw(238, 150); ofSetColor(255); if(contourFinder.blobs[i].hole){ ofDrawBitmapString("hole", contourFinder.blobs[i].boundingRect.getCenter().x + 360, contourFinder.blobs[i].boundingRect.getCenter().y + 540); } } ofNoFill(); ofSetColor(cameraColor1); ofDrawBitmapString("Camera 5", 238, 140); ofDrawRectangle(238, 150, 340, 240); ofSetColor(255,255,255,50.0); colorImg.draw(238, 150); for (int i = 0; i < contourFinder1.nBlobs; i++){ contourFinder1.blobs[i].draw(578, 150); // draw over the centroid if the blob is a hole ofSetColor(255); if(contourFinder1.blobs[i].hole){ ofDrawBitmapString("hole", contourFinder1.blobs[i].boundingRect.getCenter().x + 360, contourFinder1.blobs[i].boundingRect.getCenter().y + 540); } } ofNoFill(); ofSetColor(cameraColor2); ofDrawBitmapString("Camera 6", 578, 140); ofDrawRectangle(578, 150, 340, 240); ofSetColor(255,255,255,50.0); colorImg1.draw(578, 150); } ofEnableLighting(); pointLight.enable(); material.begin(); ofPushMatrix(); cam.begin(); peopleMaterial.begin(); if (simulationIsOn) { for (int i = 0; i < 20; i++) { ofSpherePrimitive cyl; cyl.setPosition(spheresXPos[i]+=ofRandom(1.5), spheresZPos[i], 10.9297); cyl.set(10, 10); cyl.draw(); if (spheresXPos[i] >= 0.0) { spheresXPos[i] = ofRandom(result["region0"]["ring0"]["point0"][0].asFloat()-500, result["region0"]["ring0"]["point0"][0].asFloat()+500.0); } } } peopleMaterial.end(); ofSetColor(100.0); ofFill(); int ct = 0; for (int region = 0; region < 3; region++) { string reg = "region" + ofToString(region); for (int pointPos = 0; pointPos < 4; pointPos++) { if (region == 1 && pointPos == 3) { } else { string point = "point" + ofToString(pointPos); ofCylinderPrimitive cyl; cyl.setPosition(columnGeometry[reg][point][0].asFloat(), columnGeometry[reg][point][1].asFloat(), columnGeometry[reg][point][2].asFloat()-90); cyl.set(2.0, 130.0); cyl.rotate(90, ofVec3f(1.0, 0.0, 0.0)); if (ct == 4) { columnMaterial.begin(); cyl.draw(); columnMaterial.end(); } else { cyl.draw(); } ct++; } } } material.end(); ofDisableLighting(); newDrawRegion(gaussianBottom, 0, 3, false); ofSetColor(155.0, 155.0, 155.0); ofFill(); for (int face = 0; face < 5; face++) { string fac = "face" + ofToString(face); ofPoint p1; ofPoint p2; ofPoint p3; ofPoint p4; p1.set(ofVec3f(faceGeometry[fac]["point0"][0].asFloat(),faceGeometry[fac]["point0"][1].asFloat(),faceGeometry[fac]["point0"][2].asFloat())); p2.set(ofVec3f(faceGeometry[fac]["point1"][0].asFloat(),faceGeometry[fac]["point1"][1].asFloat(),faceGeometry[fac]["point1"][2].asFloat())); p3.set(ofVec3f(faceGeometry[fac]["point2"][0].asFloat(),faceGeometry[fac]["point2"][1].asFloat(),faceGeometry[fac]["point2"][2].asFloat())); p4.set(ofVec3f(faceGeometry[fac]["point3"][0].asFloat(),faceGeometry[fac]["point3"][1].asFloat(),faceGeometry[fac]["point3"][2].asFloat())); ofDrawLine(p1, p2); ofDrawLine(p2, p3); ofDrawLine(p3, p4); ofDrawLine(p4, p1); } cam.end(); ofPopMatrix(); sendToDMX(); vector<ofVideoDevice> devices = vidGrabber.listDevices(); //ofDrawBitmapString(pcCams[0], 400, 50); //ofDrawBitmapString(pcCams[1], 400, 100); }
void ofApp::update() { if (ofGetElapsedTimeMillis() - lastTime >= timeToReset) { lastTime = ofGetElapsedTimeMillis(); bLearnBackground = true; bLearnBackground1 = true; } micLevelsTopNew[4] = contourFinder.nBlobs; micLevelsTopNew[5] = contourFinder1.nBlobs; /* NEW CAMERA CODE */ bool bNewFrame = false; bool bNewFrame1 = false; vidGrabber.update(); bNewFrame = vidGrabber.isFrameNew(); vidGrabber1.update(); bNewFrame1 = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); grayImage = colorImg; if (bLearnBackground == true){ grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading) bLearnBackground = false; } grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); } if (bNewFrame1){ colorImg1.setFromPixels(vidGrabber1.getPixels(), 320,240); grayImage1 = colorImg1; if (bLearnBackground1 == true){ grayBg1 = grayImage1; bLearnBackground1 = false; } grayDiff1.absDiff(grayBg1, grayImage1); grayDiff1.threshold(threshold); contourFinder1.findContours(grayDiff1, 20, (340*240)/3, 10, true); } switch (ANIMATION_STATE) { case ACTIVATED: { int max_pos = 0; int max_element = -1000; for (int i = 0; i < 12; i++) { if (micLevelsTopNew[i] > max_element) { max_pos = i; max_element = micLevelsTopNew[i]; } } for (int x = 0; x < 1280; x++) { float top = pow(x-bottomSwarm.b,2); float bottom = 2*pow(bottomSwarm.c,2); bottomSwarm.curve[x] = bottomSwarm.a*exp(-(top/bottom)); } ofVec2f norm = swarmPosition; bottomSwarm.b = norm.normalize().x*1280-160; // ofVec2f btm = absColumnPositionTop[max_pos]; ofVec2f btm = cameraPositionsTop[max_pos]; ofVec2f desired = btm - swarmPosition; float d = sqrt((desired.x*desired.x) + (desired.y+desired.y)); desired.normalize(); if (d < 100) { float m = ofMap(d, 0.0, 100.0, 0.0, 4.0); desired *= m; } else { desired *= 4.0; } swarmPosition += desired; /* UPDATE WAVES */ for (int x = 0; x < 1280; x++) { gaussianBottom[x] = ofMap(bottomSwarm.curve[x], 0.0, 1.1, ambientLevel, 255.0); } break; } case DEACTIVATED: { for (int x = 0; x < 1280; x++) { float top = pow(x-bottomSwarm.b,2); float bottom = 2*pow(bottomSwarm.c,2); bottomSwarm.curve[x] = bottomSwarm.a*exp(-(top/bottom)); } swarmPosition += swarmVector; if (swarmPosition.x >= 300+770 || swarmPosition.x <= 300) { swarmVector *= -1.0; } ofVec2f norm = swarmPosition; bottomSwarm.b = norm.normalize().x*1280.0-160; for (int x = 0; x < 1280; x++) { gaussianBottom[x] = ofMap(bottomSwarm.curve[x], 0.0, 1.1, ambientLevel, 255.0); } break; } } int cnt = 0; for (int i = 0; i < 12; i++) { if (i == 4 || i == 5) { } else { micLevelsTopNew[i] = 0.0; } } if (simulationIsOn) { int cntN = 0; for (int region = 3; region < 6; region++) { string reg = "region" + ofToString(region); int numCols; if (region == 4) { numCols = 3; } else { numCols = 4; } /* TODO: Did this get f****d up? */ for (int pointPos = 0; pointPos < numCols; pointPos++) { string point = "point" + ofToString(pointPos); float colX = columnGeometry[reg][point][0].asFloat(); for (int i = 0; i < 20; i++) { if (i == 4 || i == 5) { } else { if (abs(spheresXPos[i]-columnGeometry[reg][point][0].asFloat()) < 100) { micLevelsTopNew[cntN]++; } } } cntN++; } } } }
//-------------------------------------------------------------- void ofApp::update(){ show = vidGrabber.getPixels(); vidGrabber.update(); }