void ofImage_<PixelType>::saveImage(string fileName, ofImageQualityType qualityLevel){ ofSaveImage(pixels, fileName, qualityLevel); }
void ofImage_<PixelType>::save(ofBuffer & buffer, ofImageQualityType qualityLevel){ ofSaveImage(pixels, buffer, qualityLevel); }
void ofImage_<PixelType>::save(const ofFile & file, ofImageQualityType compressionLevel){ ofSaveImage(pixels,file.getAbsolutePath(),compressionLevel); }
bool ofImage_<PixelType>::save(const std::filesystem::path& fileName, ofImageQualityType qualityLevel) const { return ofSaveImage(pixels, fileName, qualityLevel); }
bool ofImage_<PixelType>::save(ofBuffer & buffer, ofImageFormat imageFormat, ofImageQualityType qualityLevel) const { return ofSaveImage(pixels, buffer, imageFormat, qualityLevel); }
//-------------------------------------------------------------- void ofApp::draw(){ ofClear(0,255); if( !fbo.isAllocated() || fbo.getWidth() != ofGetWidth() || fbo.getHeight() != ofGetHeight() ){ int w = ofGetWidth(); int h = ofGetHeight(); if( exporting ){ // no need to do anything, fbo is managed by someone else } else if( w == 0 || h == 0 ){ //what is happening??? while( globals.player.left192.totalLength > 4096 && globals.player.right192.totalLength > 4096 ){ globals.player.left192.peel(4096); globals.player.right192.peel(4096); } } else{ cout << "allocating framebuffer with " << w << ", " << h << endl; fbo.allocate(ofGetWidth(), ofGetHeight(),GL_RGBA); fbo.begin(); ofClear(0,255); fbo.end(); } } if( changed && globals.player.isPlaying ){ fbo.begin(); ofEnableBlendMode(OF_BLENDMODE_MULTIPLY); ofSetColor( 0, (1-globals.afterglow)*255 ); ofFill(); ofRect( 0, 0, fbo.getWidth(), fbo.getHeight() ); ofEnableAlphaBlending(); ofMatrix4x4 viewMatrix = getViewMatrix(); // TODO: draw the cross section // ofSetColor(255, 0, 0, 25); // ofDrawLine( -10, 0, 10, 0 ); // ofDrawLine( 0, -10, 0, 10 ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); shader.begin(); shader.setUniform1f("uSize", globals.strokeWeight / 1000.0); shader.setUniform1f("uIntensity", globals.intensity); shader.setUniformMatrix4f("uMatrix", viewMatrix); shader.setUniform1f("uHue", globals.hue ); ofSetColor(255); shapeMesh.draw(); shader.end(); ofEnableAlphaBlending(); fbo.end(); } ofSetColor(255); fbo.draw(0,0); if( exporting >= 2 ){ string filename = ofToDataPath(exportDir + "/" + ofToString(exportFrameNum, 5, '0') + ".png"); ofPixels pixels; fbo.readToPixels(pixels); ofSaveImage(pixels, filename); } if( showInfo || exporting > 0 ){ ofSetColor(exporting>0?255:100); ofDrawBitmapString("Dropped: " + ofToString(dropped), 10, 20 ); ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate(),0), 10, 40 ); if( exporting > 0 ){ unsigned long long totalFrames = 1+globals.player.duration*globals.exportFrameRate/1000; int pct = exportFrameNum*100/totalFrames; ofDrawBitmapString("Format: " + ofToString(globals.exportWidth) + " x " + ofToString(globals.exportHeight) + " @ " + ofToString(globals.exportFrameRate) + "fps (change in data/settings.txt)", 10, 60); ofDrawBitmapString("Export: " + ofToString(pct) + "% (" + ofToString(exportFrameNum) + "/" + ofToString(totalFrames) + ")", 10, 80 ); if( (exportFrameNum%10) < 5 ){ ofSetColor(255,0,0); } else{ ofSetColor(255); } ofFill(); ofEllipse(20, 100, 20, 20); } } }
//-------------------------------------------------------------- void ofApp::drawCubeMap(){ ofTexture pp, pp2, pp3, pp4, pp5, pp6; saveFbo.begin(); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[0], axis[0])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp = postProcess(cubeFbo.getTexture()); pp.draw(cubeSize, cubeSize, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[1], axis[1])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp2 = postProcess(cubeFbo.getTexture()); pp2.draw(cubeSize, 0, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[2], axis[2])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp3 = postProcess(cubeFbo.getTexture()); pp3.draw(cubeSize, cubeSize*2, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[3], axis[3])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp4 = postProcess(cubeFbo.getTexture()); pp4.draw(cubeSize*2, cubeSize, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[4], axis[4])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp5 = postProcess(cubeFbo.getTexture()); pp5.draw(cubeSize*3, cubeSize, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[5], axis[5])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp6 = postProcess(cubeFbo.getTexture()); pp6.draw(0,cubeSize, cubeSize, cubeSize); saveFbo.end(); saveFbo.readToPixels(savePix); ofSaveImage(savePix, "cubeImages/final/ch13_"+ofToString(inc)+".tga"); inc++; saveFbo.draw(0,0, w, h); //video.nextFrame(); }
//-------------------------------------------------------------- void ofApp::setup() { ofDirectory dir; ofVideoPlayer player; int edge = 2; ofxXmlSettings settings; settings.loadFile("settings.xml"); ofVec2f movieSize(settings.getValue("movieSize:width", 128) + edge, settings.getValue("movieSize:height", 128) + edge); ofVec2f texSize(settings.getValue("texSize:width", 1024), settings.getValue("texSize:height", 1024)); float duration = settings.getValue("duration", 1.0); float fps = settings.getValue("fps", 1.0); int numFrames = duration * fps; int numMovies = dir.listDir("movies"); int totalFrames = numFrames * numMovies; float movieRatio = movieSize.x / movieSize.y; float texArea = texSize.x * texSize.y; float fitArea = texArea / (float)totalFrames; float fitHeight = sqrt(fitArea/movieRatio); float fitWidth = fitArea/fitHeight; ofVec2f fitSize(fitWidth, fitHeight); ofVec2f numUnits(ceil(texSize.x / fitSize.x), ceil(texSize.y / fitSize.y)); ofVec2f size = texSize / numUnits; ofVec2f scale = movieSize / size; ofFile::removeFile("sprite.js"); ofstream js; js.open (ofToDataPath("sprite.js").c_str(), std::ios::out | std::ios::app); js << "var sprite={coordinates:["; ofFbo fbo; fbo.allocate(texSize.x, texSize.y); fbo.begin(); ofClear(0, 0, 0, 0); fbo.end(); float column = -1; float row = -1; int frameIndex = 0; for (float i = 0; i < numMovies; i++) { player.loadMovie(dir.getPath(i)); cout << dir.getPath(i) << endl; int playerNumFrames = player.getTotalNumFrames(); float offset = (float)playerNumFrames / (float)numFrames; js << "["; for (float j = 0; j < numFrames; j++) { column = frameIndex % (int)numUnits.x; if(column == 0) row++; js << "\"-" << (column * movieSize.x) << "px -" << (row * movieSize.y) << "px\""; if(j < numFrames-1) js << ","; player.setFrame(j * offset+1); player.update(); fbo.begin(); player.draw(floor(column * size.x), floor(row * size.y), ceil(size.x), ceil(size.y)); fbo.end(); frameIndex++; } js << "]"; if(i < numMovies-1) js << ","; } js << "]"; js << ",duration:" << duration; js << ",image:\"sprite.png\""; js << ",numFrames:" << numFrames; js << ",numMovies:" << numMovies; js << ",width:" << movieSize.x - edge; js << ",height:" << movieSize.y - edge; js << ",backgroundSize:\"" << (texSize.x * scale.x) << "px " << (texSize.y * scale.y)<< "px\""; js << "};"; js.close(); ofPixels pixels; pixels.allocate(texSize.x, texSize.y, 4); fbo.readToPixels(pixels); ofSaveImage(pixels, "sprite.png"); ofExit(0); }
void ofxJpegGlitch::setPixels(ofPixelsRef pix) { ofSaveImage(pix, buf, OF_IMAGE_FORMAT_JPEG); }
void ofxJpegGlitch::setImage(ofImage &image) { ofSaveImage(image.getPixelsRef(), buf, OF_IMAGE_FORMAT_JPEG); }
//-------------------------------------------------------------- void testApp::update(){ this->guiRecordStateLabel->setLabel(Stream::Recorder::toString(this->recorder.getState())); this->guiDeviceStateLabel->setLabel(toString(grabber.getDeviceState())); this->guiRecordCountLabel->setLabel("Frame count: " + ofToString(this->recorder.size())); if (this->toggleRecord != this->recorder.getIsRecording()) { if (this->toggleRecord) { this->recorder.start(); } else { this->recorder.stop(); } } if (this->bangClear) { this->recorder.clear(); this->selectionView.clear(); } if (this->bangClearBefore) { auto it = this->recorder.lower_bound(this->selectionTimestamp); while (it != this->recorder.end()) { this->recorder.erase(it); it = this->recorder.lower_bound(this->selectionTimestamp); } } if (this->bangClearAfter) { auto it = this->recorder.upper_bound(this->selectionTimestamp); while (it != this->recorder.end()) { this->recorder.erase(it); it = this->recorder.upper_bound(this->selectionTimestamp); } } if (this->bangSavePipets) { ofFile file; file.open("pipets.txt", ofFile::WriteOnly, false); for (auto it : this->recorder) { file << it.first << "\t"; for (auto pipet : this->pipets) { file << (int) this->getValue(it.first, pipet) << "\t"; } file << endl; } file.close(); } if (!this->recorder.getIsRecording()) { this->grabber.update(); } if (this->toggleSave) { auto & pixels = this->recorder[this->selectionTimestamp].getPixelsRef(); ofSaveImage(pixels, ofToString(this->selectionTimestamp) + ".png"); } if (this->toggleProgress && ! this->recorder.empty()) { auto nextFrame = this->recorder.upper_bound(this->selectionTimestamp); if (nextFrame == this->recorder.end()) { nextFrame = this->recorder.begin(); } this->selectionTimestamp = nextFrame->first; this->loadSelection(); } else { this->toggleSave = false; } }
void testApp::update() { // for (int deviceID = 0; deviceID < numDevices; deviceID++){ // if(openNIDevices[deviceID]->update()){ // cout << "UPDATED " << deviceID << endl; // } // } front.update(); if(front.isFrameNew()){ compressor.convertTo8BitImage(front.getRawDepth(), depthImage1); contourFinder.setThreshold(threshold); contourFinder.setMinArea(minSize); contourFinder.findContours(depthImage1); if(contourFinder.size() > 0){ int maxAreaIndex = 0; float maxArea = 0; for(int i = 0; i < contourFinder.size(); i++) { if(maxArea < contourFinder.getBoundingRect(i).area()){ maxArea = contourFinder.getBoundingRect(i).area(); maxAreaIndex = i; } } ofPoint center = ofxCv::toOf( contourFinder.getCenter(maxAreaIndex) ); areaDepth = depthImage1.getColor( center.x, center.y ).getBrightness(); //cout << "depth? " << areaDepth << endl; if(areaDepth > minTriggerDepth && areaDepth < maxTriggerDepth){ ghostFrames = 0; if(!inThreshold){ thresholdEnteredTime = ofGetElapsedTimef(); inThreshold = true; } float timeInThreshold = ofGetElapsedTimef() - thresholdEnteredTime; // cout << "time in threshold " << timeInThreshold << endl; if(timeInThreshold > requiredThresholdTime){ shouldFireCamera = true; requiredThresholdTime = 7; inThreshold = false; cout << "FIRING CAMERA!" << endl; } } else { if(ghostFrames++ > 5){ requiredThresholdTime = 2; inThreshold = false; } } } else { if(inThreshold && ghostFrames++ > 5){ inThreshold = false; requiredThresholdTime = 2; } } if( (showRGBD && alwaysUpdate) || (pullFrontRender && (ofGetElapsedTimef() - cameraFiredTime) > delay) ){ pullFrontRender = false; renderer1.update(); cout << "front renderer pulled after " << ofGetElapsedTimef() - cameraFiredTime << endl; } //cout << "found " << contourFinder.size() << endl; /* for(int y = 0; y < 640; y+=2){ for(int x = 0; x < 480; x++){ } } */ } back.update(); if(back.isFrameNew()){ compressor.convertTo8BitImage(back.getRawDepth(), depthImage2); backContourFinder.setThreshold(threshold); backContourFinder.setMinArea(minSize); backContourFinder.findContours(depthImage2); if((pullBackRender && (ofGetElapsedTimef() - cameraFiredTime) > delay) || (showRGBD && alwaysUpdate) ){ pullBackRender = false; renderer2.update(); cout << "back renderer pulled after " << ofGetElapsedTimef() - cameraFiredTime << endl; } } camera1.update(); // if(camera1.isFrameNew()) { // // process the live view with camera.getLivePixels() // pix.setFromPixels(camera1.getLivePixels()); // } if(renderer1.shift.x != xshift || renderer1.shift.y != yshift || renderer1.edgeClip != edgeClip || renderer2.edgeClip != edgeClip) { renderer1.edgeClip = edgeClip; renderer2.edgeClip = edgeClip; renderer1.shift = ofVec2f(xshift,yshift); filler.close(renderer1.getDepthImage()); renderer1.update(); } if(camera1.isPhotoNew()) { // process the photo with camera.getPhotoPixels() // or just save the photo to disk (jpg only): cout << "saved camera 1 photo" << endl; if(renderer1.hasTriangles && renderer2.hasTriangles){ camera1.getPhotoPixels().resize(696, 464); ofSaveImage(camera1.getPhotoPixels(), currentSaveDirectory + "/photo.jpg"); saveCombinedMesh( currentSaveDirectory + "/mesh.obj" ); ofxOscMessage m; m.setAddress("/mesh"); m.addStringArg("file://"+currentSaveDirectory); sender.sendMessage(m); //camera1.savePhoto(currentSaveDirectory + "/photo.jpg"); cout << "*** Message finally sent after " << ofGetElapsedTimef() - cameraFiredTime << endl; } if(showRGBD){ photoPreview.setFromPixels(camera1.getPhotoPixels()); renderer1.update(); } inThreshold = false; } /* camera2.update(); if(camera2.isFrameNew()) { // process the live view with camera.getLivePixels() pix.setFromPixels(camera2.getLivePixels()); } if(camera2.isPhotoNew()) { // process the photo with camera.getPhotoPixels() // or just save the photo to disk (jpg only): cout << "saved camera 2 photo" << endl; camera2.savePhoto(ofToString(ofGetFrameNum()) + ".jpg"); } */ if(autoFire && shouldFireCamera){ fireCamera(); } }