@FreddyGump wrote:
I’m trying to create a GUI that holds some basic image “filters”
I load an image from my system and then store it in an vector from the example fileOpenSaveDialogExample. After this I want to invert that image when the toggle is “true”.
Currently it’s not working properly, because I have the invert code in “on mouse click”. When I then press the toggle click on the actual image afterwards, then it inverts. This is obviously one click too much as it should just invert when the toggle is clicked.
I have it this way because when I put the invert method in the draw() , it continuously flashes between the original image and the inverted version.My code:
_ofApp.h_ // Gui setup and main window ofxPanel gui; ofxToggle inverseSwitch;
ofApp.cpp
void ofApp::setup(){ // for easy terminal output ofSetLogLevel(OF_LOG_VERBOSE); // Gui gui.setup(); gui.add(inverseSwitch.setup("invert image", false)); } void ofApp::draw(){ ofBackground(255); // Loads image from file ofDrawBitmapString("Press spacebar to open an image, \"s\" to save the processed output", 20, 15); // Invert Example for Main Window for (int i=0; i<loadedImages.size(); i++){ loadedImages[i].draw(0,20); } // Drawing the gui gui.draw(); } void ofApp::mousePressed(int x, int y, int button){ if(inverseSwitch){ for (int i=0; i<loadedImages.size(); i++){ // loadedImages[i].setColor(0, 20, color); loadedImages[i] = invertImage(loadedImages[i]); loadedImages[i].draw(0,20); } } } ofImage ofApp::invertImage(ofImage img){ Mat temp; temp = toCv(img); for(int i = 0; i < ((temp.cols)*(temp.rows))*3; i++){ temp.data[i] = 255 - temp.data[i]; } toOf(temp, img); img.update(); return img; }
Posts: 2
Participants: 2