From 24ddd694c7d3767c8d7eed14512ae2afef3234fc Mon Sep 17 00:00:00 2001 From: Jamie Allen Date: Wed, 22 Feb 2012 02:09:19 +0100 Subject: [PATCH] the synthesis (saving out to files) and displaying are working for all EXCEPT RelaxRateAnalysis this code awairs: * add (from david) of RelaxRate analysis synthesise and display * any learning that Tom brings back from the Middlesbrough trip tomorrow. a pretty nice little piece of code, gents! --- example/main.cpp | 2 - src/AbstractAnalysis.cpp | 64 ++++------ src/AbstractAnalysis.h | 12 +- src/CamNoiseAnalysis.cpp | 150 ++++++++++++++++------ src/CamNoiseAnalysis.h | 28 ++++- src/ColorMultiAnalysis.cpp | 141 ++++++++++++++++----- src/ColorMultiAnalysis.h | 27 +++- src/ColorSingleAnalysis.cpp | 134 ++++++++++++++++---- src/ColorSingleAnalysis.h | 27 +++- src/DiffNoiseAnalysis.cpp | 135 ++++++++++++++++---- src/DiffNoiseAnalysis.h | 28 ++++- src/IResponseAnalysis.cpp | 127 ++++++++++++++----- src/IResponseAnalysis.h | 28 ++++- src/RelaxRateAnalysis.cpp | 34 ++--- src/ShadowScapesAnalysis.cpp | 207 ++++++++++++++++++++++--------- src/ShadowScapesAnalysis.h | 2 +- src/ShapeFromShadingAnalysis.cpp | 119 ++++++++++++++---- src/ShapeFromShadingAnalysis.h | 28 ++++- src/StrobeAnalysis.cpp | 130 ++++++++++++++----- src/StrobeAnalysis.h | 27 +++- 20 files changed, 1098 insertions(+), 352 deletions(-) diff --git a/example/main.cpp b/example/main.cpp index 5eab23e..9f4b2f7 100755 --- a/example/main.cpp +++ b/example/main.cpp @@ -4,8 +4,6 @@ #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 -////also the new shit//// - int main() { ofAppGlutWindow window; diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index 921b093..ff30df1 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -1,34 +1,4 @@ -/* - - copyright (c) 2011 Copenhagen Institute of Interaction Design (CIID) - - all rights reserved. - - + redistribution and use in source and binary forms, with or without - + modification, are permitted provided that the following conditions - + are met: - + > redistributions of source code must retain the above copyright - + notice, this list of conditions and the following disclaimer. - + > redistributions in binary form must reproduce the above copyright - + notice, this list of conditions and the following disclaimer in - + the documentation and/or other materials provided with the - + distribution. - - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - + COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - + AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - + SUCH DAMAGE. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ author: dviid - ~ contact: dviid@labs.ciid.dk - */ +/* */ #include "AbstractAnalysis.h" #include "RefractiveIndex.h" @@ -36,7 +6,7 @@ // this is the main threaded loop for a given analysis void AbstractAnalysis::do_synthesize() { - _saved_filenames.clear(); + _saved_filenames_analysis.clear(); _state = STATE_ACQUIRING; acquire(); if(_state == STATE_STOP) goto exit; @@ -45,7 +15,7 @@ void AbstractAnalysis::do_synthesize() { if(_state == STATE_STOP) goto exit; _state = STATE_DISPLAY_RESULTS; displayresults(); -exit: + exit: ofNotifyEvent(_synthesize_cb, _name); } @@ -72,15 +42,27 @@ void AbstractAnalysis::create_dir() } } - ofxFileHelper fileHelper; - _whole_file_path = ANALYSIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime ; - //cout << "_whole_file_path = " << _whole_file_path << endl; + ofxFileHelper fileHelperAnalysis; + ofxFileHelper fileHelperSynthesis; - if(!fileHelper.doesDirectoryExist(_whole_file_path)){ - fileHelper.makeDirectory(ANALYSIS_PATH); - fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location); - fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name); - fileHelper.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime); + _whole_file_path_analysis = ANALYSIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime ; + + //cout << "_whole_file_path_analysis = " << _whole_file_path_analysis << endl; + + if(!fileHelperAnalysis.doesDirectoryExist(_whole_file_path_analysis)){ + fileHelperAnalysis.makeDirectory(ANALYSIS_PATH); + fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location); + fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name); + fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime); + } + + _whole_file_path_synthesis = SYNTHESIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime; + + if(!fileHelperSynthesis.doesDirectoryExist(_whole_file_path_synthesis)){ + fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH); + fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location); + fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name); + fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime); } //////////////////////////////END DIRECTORY CREATION ////////////////////////////////////////////////// diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index d6a29b1..760b985 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -10,6 +10,7 @@ #include #define ANALYSIS_PATH "analysis/" +#define SYNTHESIS_PATH "synthesis/" #define STATE_ACQUIRING 0x1111 #define STATE_SYNTHESISING 0x2222 @@ -24,10 +25,11 @@ public: // generic function to set up the camera virtual void setup(int camWidth, int camHeight){_cam_w = camWidth; _cam_h = camHeight;} + // this is the main threaded loop for a given analysis void do_synthesize(); - // ofx + // show the results to the screen virtual void draw() = 0; protected: @@ -39,8 +41,9 @@ protected: // analysis + synthesize images - all the children (see - do_synthesize) virtual void synthesise() = 0; - virtual void displayresults() = 0; + // display the results from disk + virtual void displayresults() = 0; public: string _name; @@ -50,8 +53,9 @@ public: protected: int _cam_w, _cam_h; - string _whole_file_path; - vector _saved_filenames; + string _whole_file_path_analysis, _whole_file_path_synthesis; + vector _saved_filenames_analysis; + vector _saved_filenames_synthesis; int _state; diff --git a/src/CamNoiseAnalysis.cpp b/src/CamNoiseAnalysis.cpp index b2bed40..5b0d2d7 100755 --- a/src/CamNoiseAnalysis.cpp +++ b/src/CamNoiseAnalysis.cpp @@ -18,9 +18,8 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight) int acq_run_time = 20; // 20 seconds of acquiring per run - DELTA_T_SAVE = 2*(10*acq_run_time/2); - // for 20 seconds, we want this to be around 200 files - // or 10 times per second = every 100 ms + DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files + // or 5 times per second = every 200 ms _frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames @@ -29,19 +28,35 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight) _frame_cnt = 0; c = 0; - int anim_time = 5; // 10 seconds + int anim_time = 10; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames create_dir(); + _show_image = false; _image_shown = false; - //for an ofxOpenCv.h image i would like to use..." - //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 - image1.setUseTexture(false); - image2.setUseTexture(true); + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + //cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + //cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + } @@ -57,7 +72,7 @@ void CamNoiseAnalysis::acquire() _run_cnt = i; - cout << "RUN NUM = " << i; + //cout << "RUN NUM = " << i; save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files save_timer->start(save_callback); @@ -76,33 +91,87 @@ void CamNoiseAnalysis::acquire() void CamNoiseAnalysis::synthesise() { - // _saved_filenames has all the file names of all the saved images + //cout << "CamNoiseAnalysis::saving synthesis...\n"; + if(_state == STATE_STOP) return; + + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + //cout << "CamNoiseAnalysis::synthesis FOR LOOP...\n"; + + //cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + //cout << "LOADED image1!!!" << endl; + //if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + cvGrayImage1 = cvColorImage1; + //cvGrayImage2 = cvColorImage2; + + //cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + //cvGrayDiff1.erode(); + //cvGrayDiff1.contrastStretch(); + //cvGrayDiff1.blur(5); + //cvGrayDiff1.dilate(); + //cvGrayDiff1.contrastStretch(); + + cvGrayImage1.threshold(255.0*i/_saved_filenames_analysis.size()); //random threshold for the moment + cvGrayImage1.blur(10); + cvGrayImage1.contrastStretch(); + cvGrayImage1.blur(10); + + /////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + file_name = ofToString(_synth_save_cnt, 2)+"_CamNoiseAnalysis_"+ofToString(_run_cnt,2)+".jpg"; + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + //ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + //} + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); - } void CamNoiseAnalysis::displayresults() { - - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + if(_state == STATE_STOP) return; + + //cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; while(!_image_shown){ Thread::sleep(2); //cout << "!_image_shown" << endl; } - - if(!image1.loadImage(_saved_filenames[i])){ + if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image cout << "didn't load image" << endl; } - - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; @@ -133,35 +202,38 @@ void CamNoiseAnalysis::draw() float _frames_per_level = _frame_cnt_max / _number_of_grey_levels; ofColor someColor; + /* if (_frame_cnt < _fade_in_frames) { aColour.set(255, 255, 255, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)); ofSetColor(aColour); ofRect(0, 0, ofGetWidth(), ofGetHeight()); //cout << "FADE IN STROBE TIME " << endl; } - - if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){ + */ + //if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max)){ - for(int i=0;i<_number_of_grey_levels;i++){ - if (_frame_cnt>= _frames_per_level *( i-1) && +_frame_cnt < _frames_per_level * (i) ) { + for(int i=1;i<_number_of_grey_levels;i++){ + if ( _frame_cnt >= _frames_per_level*(i-1) && +_frame_cnt < _frames_per_level * (i+1) ) { //set colour to current grey level c=255-( 255.0 * ( i /_number_of_grey_levels)); + //cout << "c: " << c << endl; someColor.set(c); } + ofSetColor(someColor); ofRect(0, 0, ofGetWidth(), ofGetHeight()); } - } - + //} + /* if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) { - aColour.set(0, 0, 0, 255-ofMap(_frame_cnt-(_frame_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255)); + aColour.set(0, 0, 0, ofMap(_frame_cnt-(_frame_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255)); ofSetColor(aColour); ofRect(0, 0, ofGetWidth(), ofGetHeight()); // cout << "FADE OUT STROBE TIME " << endl; } - + */ ofDisableAlphaBlending(); @@ -179,7 +251,7 @@ void CamNoiseAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + //cout << "CamNoiseAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -200,7 +272,7 @@ void CamNoiseAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + //cout << "CamNoiseAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -229,9 +301,9 @@ void CamNoiseAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + //cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + //cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ @@ -261,6 +333,8 @@ void CamNoiseAnalysis::draw() case STATE_DISPLAY_RESULTS: { + //cout << "STATE_DISPLAY_RESULTS...\n" << endl; + if (_frame_cnt > 2) { _image_shown = true; @@ -271,10 +345,12 @@ void CamNoiseAnalysis::draw() if (_show_image) { + //cout << "_show_image...\n" << endl; + ofEnableAlphaBlending(); - ofSetColor(255, 255, 255, 255); - image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); image2.draw(0,0, ofGetWidth(), ofGetHeight()); ofDisableAlphaBlending(); @@ -283,10 +359,9 @@ void CamNoiseAnalysis::draw() // display results of the synthesis _RUN_DONE = true; break; - + } - default: break; } @@ -312,8 +387,7 @@ void CamNoiseAnalysis::save_cb(Timer& timer) string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/CamNoiseAnalysis.h b/src/CamNoiseAnalysis.h index ae4a202..d50d31b 100755 --- a/src/CamNoiseAnalysis.h +++ b/src/CamNoiseAnalysis.h @@ -33,11 +33,31 @@ protected: bool _RUN_DONE; - int _run_cnt, _save_cnt, _anim_cnt; + int _run_cnt, _save_cnt, _synth_save_cnt,_anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; - ofImage image1; - ofImage image2; - + ofImage image1; + ofImage image2; + ofImage image3; + ofImage image4; + ofImage image5; + ofImage image6; + + ofxCvColorImage cvColorImage1; + ofxCvColorImage cvColorImage2; + ofxCvColorImage cvColorImage3; + ofxCvColorImage cvColorImage4; + ofxCvColorImage cvColorImage5; + ofxCvColorImage cvColorImage6; + + ofxCvGrayscaleImage cvGrayDiff1; + ofxCvGrayscaleImage cvGrayDiff2; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayImage2; + ofxCvGrayscaleImage cvGrayImage3; + ofxCvGrayscaleImage cvGrayImage4; + + ofxCvContourFinder cvContourFinder1; }; diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index b541ef6..990b78e 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -10,17 +10,15 @@ using Poco::TimerCallback; using Poco::Thread; - void ColorMultiAnalysis::setup(int camWidth, int camHeight) { - NUM_RUN = 1; int acq_run_time = 35; - DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files - // or 10 times per second = every 100 ms + DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files + // or 10 times per second = every 100 ms _frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames @@ -29,7 +27,7 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight) _frame_cnt = 0; c = 0; - int anim_time = 5; // 10 seconds + int anim_time = 10; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames create_dir(); @@ -39,9 +37,29 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight) //for an ofxOpenCv.h image i would like to use..." //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); + + _show_image = false; + _image_shown = false; - image1.setUseTexture(false); - image2.setUseTexture(true); + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 + + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + //cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + //cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); } @@ -57,7 +75,7 @@ void ColorMultiAnalysis::acquire() _run_cnt = i; - cout << "RUN NUM = " << i; + //cout << "RUN NUM = " << i; save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files save_timer->start(save_callback); @@ -76,39 +94,98 @@ void ColorMultiAnalysis::acquire() void ColorMultiAnalysis::synthesise() { - // _saved_filenames has all the file names of all the saved images + + //cout << "ColorMultiAnalysis::saving synthesis...\n"; + if(_state == STATE_STOP) return; + + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + //cout << "ColorMultiAnalysis::synthesis FOR LOOP...\n"; + + //cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + //cout << "LOADED image1!!!" << endl; + //if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + //cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + //cvGrayImage1 = cvColorImage1; + //cvGrayImage2 = cvColorImage2; + + //cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + //cvGrayDiff1.erode(); + //cvGrayDiff1.contrastStretch(); + //cvGrayDiff1.blur(5); + //cvGrayDiff1.dilate(); + //cvGrayDiff1.contrastStretch(); + + cvColorImage1.contrastStretch(); + cvColorImage1.blur(5); + cvColorImage1.erode(); + cvColorImage1.erode(); + cvColorImage1.dilate(); + cvColorImage1.blur(5); + cvColorImage1.dilate(); + cvColorImage1.dilate(); + cvColorImage1.dilate(); + cvColorImage1.dilate(); + + /////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg"; + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvColorImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + // } + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } void ColorMultiAnalysis::displayresults() { - - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ if(_state == STATE_STOP) return; - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + //cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; while(!_image_shown){ Thread::sleep(2); //cout << "!_image_shown" << endl; } - - if(!image1.loadImage(_saved_filenames[i])){ + if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image cout << "didn't load image" << endl; } - - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; } - } + } } @@ -134,7 +211,7 @@ void ColorMultiAnalysis::draw() ofSetColor(aColor); ofRect(0, 0, ofGetWidth(), ofGetHeight()); - cout << "FADING IN..." << endl; + //cout << "FADING IN..." << endl; } @@ -158,7 +235,7 @@ void ColorMultiAnalysis::draw() ofSetColor(aColor); ofRect(0, 0, ofGetWidth(), ofGetHeight()); - cout << "FADING OUT..." << endl; + //cout << "FADING OUT..." << endl; } @@ -177,7 +254,7 @@ void ColorMultiAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + //cout << "ColorMultiAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -198,7 +275,7 @@ void ColorMultiAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + //cout << "ColorMultiAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -227,9 +304,9 @@ void ColorMultiAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + //cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + //cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ @@ -258,6 +335,9 @@ void ColorMultiAnalysis::draw() case STATE_DISPLAY_RESULTS: { + //cout << "STATE_DISPLAY_RESULTS...\n" << endl; + + if (_frame_cnt > 2) { _image_shown = true; @@ -268,10 +348,13 @@ void ColorMultiAnalysis::draw() if (_show_image) { + //cout << "_show_image...\n" << endl; + ofEnableAlphaBlending(); - ofSetColor(255, 255, 255, 255); - image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR); + //image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); image2.draw(0,0, ofGetWidth(), ofGetHeight()); ofDisableAlphaBlending(); @@ -280,7 +363,7 @@ void ColorMultiAnalysis::draw() // display results of the synthesis _RUN_DONE = true; break; - + } @@ -310,9 +393,9 @@ void ColorMultiAnalysis::save_cb(Timer& timer) string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/ColorMultiAnalysis.h b/src/ColorMultiAnalysis.h index 9799ee4..b8fc504 100755 --- a/src/ColorMultiAnalysis.h +++ b/src/ColorMultiAnalysis.h @@ -27,11 +27,32 @@ protected: bool _RUN_DONE; - int _run_cnt, _save_cnt, _fade_cnt, _anim_cnt; + int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; - ofImage image1; - ofImage image2; + ofImage image1; + ofImage image2; + ofImage image3; + ofImage image4; + ofImage image5; + ofImage image6; + + ofxCvColorImage cvColorImage1; + ofxCvColorImage cvColorImage2; + ofxCvColorImage cvColorImage3; + ofxCvColorImage cvColorImage4; + ofxCvColorImage cvColorImage5; + ofxCvColorImage cvColorImage6; + + ofxCvGrayscaleImage cvGrayDiff1; + ofxCvGrayscaleImage cvGrayDiff2; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayImage2; + ofxCvGrayscaleImage cvGrayImage3; + ofxCvGrayscaleImage cvGrayImage4; + + ofxCvContourFinder cvContourFinder1; }; diff --git a/src/ColorSingleAnalysis.cpp b/src/ColorSingleAnalysis.cpp index 8798949..c9806a8 100755 --- a/src/ColorSingleAnalysis.cpp +++ b/src/ColorSingleAnalysis.cpp @@ -16,10 +16,10 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight) NUM_RUN = 1; - int acq_run_time = 20; // 20 seconds of acquiring per run + int acq_run_time = 25; // 20 seconds of acquiring per run - DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files - // or 10 times per second = every 100 ms + DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files + // or 10 times per second = every 100 ms _frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames @@ -28,7 +28,7 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight) _frame_cnt = 0; c = 0; - int anim_time = 5; // 10 seconds + int anim_time = 10; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames create_dir(); @@ -45,11 +45,25 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight) _show_image = false; _image_shown = false; - //for an ofxOpenCv.h image i would like to use..." - //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 - image1.setUseTexture(false); - image2.setUseTexture(true); + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + //cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + //cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); } @@ -65,7 +79,7 @@ void ColorSingleAnalysis::acquire() _run_cnt = i; - cout << "RUN NUM = " << i; + //cout << "RUN NUM = " << i; save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files save_timer->start(save_callback); @@ -83,39 +97,100 @@ void ColorSingleAnalysis::acquire() void ColorSingleAnalysis::synthesise() { - // _saved_filenames has all the file names of all the saved images + + //cout << "ColorSingleAnalysis::saving synthesis...\n"; + if(_state == STATE_STOP) return; + + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + //cout << "ColorSingleAnalysis::synthesis FOR LOOP...\n"; + + //cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + //cout << "LOADED image1!!!" << endl; + //if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + //cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + //cvGrayImage1 = cvColorImage1; + //cvGrayImage2 = cvColorImage2; + + //cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + //cvGrayDiff1.erode(); + //cvGrayDiff1.contrastStretch(); + //cvGrayDiff1.blur(5); + //cvGrayDiff1.dilate(); + //cvGrayDiff1.contrastStretch(); + + cvColorImage1.contrastStretch(); + cvColorImage1.blur(5); + cvColorImage1.erode(); + cvColorImage1.erode(); + cvColorImage1.dilate(); + cvColorImage1.blur(5); + cvColorImage1.erode(); + cvColorImage1.erode(); + cvColorImage1.erode(); + cvColorImage1.erode(); + + /////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + file_name = ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".jpg"; + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvColorImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + // } + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); + } void ColorSingleAnalysis::displayresults() { - - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ if(_state == STATE_STOP) return; - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + //cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; while(!_image_shown){ Thread::sleep(2); //cout << "!_image_shown" << endl; } - - if(!image1.loadImage(_saved_filenames[i])){ + if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image cout << "didn't load image" << endl; } - - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; } } + } @@ -190,7 +265,7 @@ void ColorSingleAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + //cout << "ColorSingleAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -211,7 +286,7 @@ void ColorSingleAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + // cout << "ColorSingleAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -240,9 +315,9 @@ void ColorSingleAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + //cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + //cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ @@ -272,6 +347,9 @@ void ColorSingleAnalysis::draw() case STATE_DISPLAY_RESULTS: { + //cout << "STATE_DISPLAY_RESULTS...\n" << endl; + + if (_frame_cnt > 2) { _image_shown = true; @@ -282,10 +360,13 @@ void ColorSingleAnalysis::draw() if (_show_image) { + //cout << "_show_image...\n" << endl; + ofEnableAlphaBlending(); - ofSetColor(255, 255, 255, 255); - image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR); + //image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); image2.draw(0,0, ofGetWidth(), ofGetHeight()); ofDisableAlphaBlending(); @@ -295,6 +376,7 @@ void ColorSingleAnalysis::draw() _RUN_DONE = true; break; + } default: @@ -321,9 +403,9 @@ void ColorSingleAnalysis::save_cb(Timer& timer) string file_name =ofToString(_save_cnt,2)+"_"+fileNameTag+"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/ColorSingleAnalysis.h b/src/ColorSingleAnalysis.h index 78dadad..034701c 100755 --- a/src/ColorSingleAnalysis.h +++ b/src/ColorSingleAnalysis.h @@ -34,11 +34,32 @@ protected: string fileNameTag; float r,g,b; - int _run_cnt, _save_cnt, _fade_cnt, _anim_cnt; + int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; - ofImage image1; - ofImage image2; + ofImage image1; + ofImage image2; + ofImage image3; + ofImage image4; + ofImage image5; + ofImage image6; + + ofxCvColorImage cvColorImage1; + ofxCvColorImage cvColorImage2; + ofxCvColorImage cvColorImage3; + ofxCvColorImage cvColorImage4; + ofxCvColorImage cvColorImage5; + ofxCvColorImage cvColorImage6; + + ofxCvGrayscaleImage cvGrayDiff1; + ofxCvGrayscaleImage cvGrayDiff2; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayImage2; + ofxCvGrayscaleImage cvGrayImage3; + ofxCvGrayscaleImage cvGrayImage4; + + ofxCvContourFinder cvContourFinder1; }; diff --git a/src/DiffNoiseAnalysis.cpp b/src/DiffNoiseAnalysis.cpp index 0873c1f..a8b30d5 100755 --- a/src/DiffNoiseAnalysis.cpp +++ b/src/DiffNoiseAnalysis.cpp @@ -18,7 +18,7 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight) int acq_run_time = 20; // 20 seconds of acquiring per run - DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files + DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files // or 10 times per second = every 100 ms _frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames @@ -28,7 +28,7 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight) _frame_cnt = 0; c = 0; - int anim_time = 5; // 10 seconds + int anim_time = 10; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames create_dir(); @@ -39,8 +39,29 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight) //for an ofxOpenCv.h image i would like to use..." //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); - image1.setUseTexture(false); - image2.setUseTexture(true); + _show_image = false; + _image_shown = false; + + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 + + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + //cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + //cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + } @@ -57,7 +78,7 @@ void DiffNoiseAnalysis::acquire() _run_cnt = i; - cout << "RUN NUM = " << i; + //cout << "RUN NUM = " << i; save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files save_timer->start(save_callback); @@ -74,40 +95,99 @@ void DiffNoiseAnalysis::acquire() void DiffNoiseAnalysis::synthesise() { - // _saved_filenames has all the file names of all the saved images + + //cout << "DiffNoiseAnalysis::saving synthesis...\n"; + if(_state == STATE_STOP) return; + + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + //cout << "DiffNoiseAnalysis::synthesis FOR LOOP...\n"; + + //cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + //cout << "LOADED image1!!!" << endl; + //if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + //cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + //cvGrayImage1 = cvColorImage1; + //cvGrayImage2 = cvColorImage2; + + //cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + //cvGrayDiff1.erode(); + //cvGrayDiff1.contrastStretch(); + //cvGrayDiff1.blur(5); + //cvGrayDiff1.dilate(); + //cvGrayDiff1.contrastStretch(); + + cvColorImage1.contrastStretch(); + cvColorImage1.invert(); + cvColorImage1.blur(5); + cvColorImage1.erode(); + cvColorImage1.blur(5); + cvColorImage1.erode(); + cvColorImage1.contrastStretch(); + + //////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + file_name = ofToString(_synth_save_cnt, 2)+"_DiffNoiseAnalysis_"+ofToString(_run_cnt,2)+".jpg"; + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvColorImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + // } + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); - + } void DiffNoiseAnalysis::displayresults() { - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ if(_state == STATE_STOP) return; - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + //cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; while(!_image_shown){ Thread::sleep(2); //cout << "!_image_shown" << endl; } - - if(!image1.loadImage(_saved_filenames[i])){ + if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image cout << "didn't load image" << endl; } - - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; } - } + } + + } @@ -195,7 +275,7 @@ void DiffNoiseAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + //cout << "DiffNoiseAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -216,7 +296,7 @@ void DiffNoiseAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + //cout << "DiffNoiseAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -245,9 +325,9 @@ void DiffNoiseAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + //cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + //cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ @@ -277,6 +357,8 @@ void DiffNoiseAnalysis::draw() case STATE_DISPLAY_RESULTS: { + //cout << "STATE_DISPLAY_RESULTS...\n" << endl; + if (_frame_cnt > 2) { @@ -288,10 +370,13 @@ void DiffNoiseAnalysis::draw() if (_show_image) { + //cout << "_show_image...\n" << endl; + ofEnableAlphaBlending(); - ofSetColor(255, 255, 255, 255); - image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR); + //image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); image2.draw(0,0, ofGetWidth(), ofGetHeight()); ofDisableAlphaBlending(); @@ -300,13 +385,11 @@ void DiffNoiseAnalysis::draw() // display results of the synthesis _RUN_DONE = true; break; - - } + } default: break; } - } // this runs at save_cb timer rate = DELTA_T_SAVE @@ -327,9 +410,9 @@ void DiffNoiseAnalysis::save_cb(Timer& timer) string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); _save_cnt++; diff --git a/src/DiffNoiseAnalysis.h b/src/DiffNoiseAnalysis.h index 837409b..64e428f 100755 --- a/src/DiffNoiseAnalysis.h +++ b/src/DiffNoiseAnalysis.h @@ -32,11 +32,31 @@ protected: bool _RUN_DONE; - int _run_cnt, _save_cnt, _fade_cnt, _anim_cnt; + int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; - ofImage image1; - ofImage image2; - + ofImage image1; + ofImage image2; + ofImage image3; + ofImage image4; + ofImage image5; + ofImage image6; + + ofxCvColorImage cvColorImage1; + ofxCvColorImage cvColorImage2; + ofxCvColorImage cvColorImage3; + ofxCvColorImage cvColorImage4; + ofxCvColorImage cvColorImage5; + ofxCvColorImage cvColorImage6; + + ofxCvGrayscaleImage cvGrayDiff1; + ofxCvGrayscaleImage cvGrayDiff2; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayImage2; + ofxCvGrayscaleImage cvGrayImage3; + ofxCvGrayscaleImage cvGrayImage4; + + ofxCvContourFinder cvContourFinder1; }; diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index bf9f071..baf9724 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -27,17 +27,32 @@ void IResponseAnalysis::setup(int camWidth, int camHeight) _frame_cnt = 0; c = 0; - int anim_time = 5; // 10 seconds + int anim_time = 10; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames _show_image = false; _image_shown = false; - //for an ofxOpenCv.h image i would like to use..." - //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 + + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + //cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + //cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); - image1.setUseTexture(false); - image2.setUseTexture(true); } @@ -54,11 +69,11 @@ void IResponseAnalysis::acquire() _run_cnt = i; - cout << "RUN NUM = " << i; + //cout << "RUN NUM = " << i; save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files save_timer->start(save_callback); - _RUN_DONE = false; + _frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; while(!_RUN_DONE && _state != STATE_STOP) @@ -73,35 +88,85 @@ void IResponseAnalysis::acquire() void IResponseAnalysis::synthesise() { - // _saved_filenames has all the file names of all the saved images + + //cout << "IResponseAnalysis::saving synthesis...\n"; + if(_state == STATE_STOP) return; + + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + //cout << "IResponseAnalysis::synthesis FOR LOOP...\n"; + + //cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + //cout << "LOADED image1!!!" << endl; + if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + cvGrayImage1 = cvColorImage1; + cvGrayImage2 = cvColorImage2; + + cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + cvGrayDiff1.erode(); + cvGrayDiff1.contrastStretch(); + //cvGrayDiff1.blur(5); + //cvGrayDiff1.dilate(); + //cvGrayDiff1.contrastStretch(); + + /////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + file_name = ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".jpg"; + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + } + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); + + } void IResponseAnalysis::displayresults() { - - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ if(_state == STATE_STOP) return; - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + //cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; while(!_image_shown){ Thread::sleep(2); //cout << "!_image_shown" << endl; } - - if(!image1.loadImage(_saved_filenames[i])){ + if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image - cout << "didn't load image" << endl; + // cout << "didn't load image" << endl; } - - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; @@ -122,7 +187,7 @@ void IResponseAnalysis::draw() ofEnableAlphaBlending(); ofColor aColour; int _fade_in_frames = _frame_cnt_max/10; - cout<< "_fade_in_frames" << _fade_in_frames<< endl; + //cout<< "_fade_in_frames" << _fade_in_frames<< endl; if (_frame_cnt < _fade_in_frames) { @@ -159,7 +224,7 @@ void IResponseAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + // cout << "IResponse = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -180,7 +245,7 @@ void IResponseAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + //cout << "IResponse STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -209,9 +274,9 @@ void IResponseAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + //cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + //cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ @@ -231,6 +296,7 @@ void IResponseAnalysis::draw() _RUN_DONE = true; _anim_cnt=0; } + ofPopMatrix(); ofSetRectMode(OF_RECTMODE_CORNER); ofDisableAlphaBlending(); @@ -241,6 +307,8 @@ void IResponseAnalysis::draw() case STATE_DISPLAY_RESULTS: { + //cout << "STATE_DISPLAY_RESULTS...\n" << endl; + if (_frame_cnt > 2) { @@ -252,19 +320,21 @@ void IResponseAnalysis::draw() if (_show_image) { + //cout << "_show_image...\n" << endl; + ofEnableAlphaBlending(); - ofSetColor(255, 255, 255, 255); - image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); image2.draw(0,0, ofGetWidth(), ofGetHeight()); - + ofDisableAlphaBlending(); } // display results of the synthesis _RUN_DONE = true; break; - + } default: @@ -291,7 +361,6 @@ void IResponseAnalysis::save_cb(Timer& timer) string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/IResponseAnalysis.h b/src/IResponseAnalysis.h index 72677bf..ca7a41d 100755 --- a/src/IResponseAnalysis.h +++ b/src/IResponseAnalysis.h @@ -31,11 +31,31 @@ public: protected: bool _RUN_DONE; - int _run_cnt, _save_cnt, _anim_cnt; + int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; - ofImage image1; - ofImage image2; - + ofImage image1; + ofImage image2; + ofImage image3; + ofImage image4; + ofImage image5; + ofImage image6; + + ofxCvColorImage cvColorImage1; + ofxCvColorImage cvColorImage2; + ofxCvColorImage cvColorImage3; + ofxCvColorImage cvColorImage4; + ofxCvColorImage cvColorImage5; + ofxCvColorImage cvColorImage6; + + ofxCvGrayscaleImage cvGrayDiff1; + ofxCvGrayscaleImage cvGrayDiff2; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayImage2; + ofxCvGrayscaleImage cvGrayImage3; + ofxCvGrayscaleImage cvGrayImage4; + + ofxCvContourFinder cvContourFinder1; }; diff --git a/src/RelaxRateAnalysis.cpp b/src/RelaxRateAnalysis.cpp index 61cc838..0c88130 100755 --- a/src/RelaxRateAnalysis.cpp +++ b/src/RelaxRateAnalysis.cpp @@ -54,7 +54,7 @@ void RelaxRateAnalysis::acquire() _run_cnt = i; - cout << "RUN NUM = " << i; + //cout << "RUN NUM = " << i; save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files save_timer->start(save_callback); @@ -72,8 +72,8 @@ void RelaxRateAnalysis::acquire() void RelaxRateAnalysis::synthesise() { - - // _saved_filenames has all the file names of all the saved images + + // _saved_filenames_analysis has all the file names of all the saved images while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); @@ -82,11 +82,11 @@ void RelaxRateAnalysis::synthesise() void RelaxRateAnalysis::displayresults() { - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_analysis.size();i++){ if(_state == STATE_STOP) return; - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + // cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; while(!_image_shown){ Thread::sleep(2); @@ -94,14 +94,14 @@ void RelaxRateAnalysis::displayresults() } - if(!image1.loadImage(_saved_filenames[i])){ + if(!image1.loadImage(_saved_filenames_analysis[i])){ //couldn't load image cout << "didn't load image" << endl; } - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image1.loadImage(_saved_filenames_analysis[i])){ + image1.loadImage(_saved_filenames_analysis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; @@ -152,7 +152,7 @@ void RelaxRateAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + //cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -173,7 +173,7 @@ void RelaxRateAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + //cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -190,7 +190,7 @@ void RelaxRateAnalysis::draw() if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){ - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = MIDDLE OF ANIMATION...\n"; + //cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = MIDDLE OF ANIMATION...\n"; for (int i=0; i <= 15; i++){ c_anim = 255; @@ -206,16 +206,16 @@ void RelaxRateAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADE OUT OF ANIMATION...\n"; + //cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADE OUT OF ANIMATION...\n"; - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + //cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + //cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ c_anim = (17*i); - cout << "c_anim = " << c_anim << endl; + //cout << "c_anim = " << c_anim << endl; aColour.set(c_anim, c_anim, c_anim, 255-fade); ofSetColor(aColour); ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i); @@ -288,7 +288,7 @@ void RelaxRateAnalysis::save_cb(Timer& timer) string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/ShadowScapesAnalysis.cpp b/src/ShadowScapesAnalysis.cpp index b59bffa..edb4bbf 100755 --- a/src/ShadowScapesAnalysis.cpp +++ b/src/ShadowScapesAnalysis.cpp @@ -18,7 +18,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight) { NUM_RUN = 1; - int acq_run_time = 5; // 10 seconds of acquiring per run + int acq_run_time = 15; // 10 seconds of acquiring per run int screenSpan; if (_dir == V) screenSpan = ofGetHeight(); @@ -30,29 +30,33 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight) // 40 pixels per second should give us a 20 second scan at 800 pixels wide - DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files - // or 10 times per second = every 100 ms + DELTA_T_SAVE = 3*(10*acq_run_time/2); // for 20 seconds, we want this to be around 100 files + // or 5 times per second = every 200 ms - create_dir(); + create_dir(); // this makes both synth and analysis folder structures _scanLineWidth = 100.0; _run_cnt = 0; _save_cnt = 0; + _synth_save_cnt = 0; - int anim_time = 1; // 10 seconds + int anim_time = 10; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames _show_image = false; _image_shown = false; - //for an ofxOpenCv.h image i would like to use..." - //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 + + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); - image1.setUseTexture(false); - image2.setUseTexture(false); - - cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; - cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + //cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + //cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); @@ -91,19 +95,103 @@ void ShadowScapesAnalysis::acquire() void ShadowScapesAnalysis::synthesise() { + //cout << "ShadowScapesAnalysis::saving synthesis...\n"; - // _saved_filenames has all the file names of all the saved images - while(!_RUN_DONE && _state != STATE_STOP) + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + // cout << "ShadowScapesAnalysis::synthesis FOR LOOP...\n"; + + // cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + + if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + cvGrayImage1 = cvColorImage1; + cvGrayImage2 = cvColorImage2; + + cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + cvGrayDiff1.erode(); + cvGrayDiff1.contrastStretch(); + cvGrayDiff1.blur(5); + cvGrayDiff1.dilate(); + cvGrayDiff1.contrastStretch(); + + /////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + if(_dir == H) { + file_name = ofToString(_synth_save_cnt, 2)+"_H_ShadowScapesSynthesis"+ofToString(_run_cnt,2)+".jpg"; + } + + if(_dir == V) { + file_name = ofToString(_synth_save_cnt, 2)+"_V_ShadowScapesSynthesis"+ofToString(_run_cnt,2)+".jpg"; + } + + if(_dir == D) { + file_name = ofToString(_synth_save_cnt, 2)+"_D_ShadowScapesSynthesis"+ofToString(_run_cnt,2)+".jpg"; + } + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + } + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder + while(!_RUN_DONE && _state != STATE_STOP) Thread::sleep(3); } void ShadowScapesAnalysis::displayresults() { - - for(float i=1;i<_saved_filenames.size()-1;i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ - // cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + if(_state == STATE_STOP) return; + + // cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; + + while(!_image_shown){ + Thread::sleep(2); + //cout << "!_image_shown" << endl; + } + + if(!image3.loadImage(_saved_filenames_synthesis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); + //cout << "_show_image = true;" << endl; + _show_image = true; + _image_shown = false; + } + } + + + // THE OLD SHIT /// +/* + for(float i=1;i<_saved_filenames_synthesis.size()-1;i++){ + + // cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; if(_state == STATE_STOP) return; @@ -112,29 +200,26 @@ void ShadowScapesAnalysis::displayresults() //cout << "!_image_shown" << endl; } - if(!image1.loadImage(_saved_filenames[i])){ + if(!image1.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image cout << "didn't load image" << endl; } - image1.loadImage(_saved_filenames[2]); + + if(image1.loadImage(_saved_filenames_analysis[i])){ + + image1.loadImage(_saved_filenames_analysis[i]); + cout << "loaded filenames[i] - " << _saved_filenames_analysis[i] << endl; - if(image1.loadImage(_saved_filenames[i])){ - - //image1.loadImage(_saved_filenames[i]); - - image2.loadImage(_saved_filenames[i]); - cout << "loaded filenames[i] - " << _saved_filenames[i] << endl; - -// image2.loadImage(_saved_filenames[i+1]); - - cout << "loaded filenames[i+1] -" << _saved_filenames[i+1] << endl; - + image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); + //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; + } } +*/ } @@ -211,7 +296,6 @@ void ShadowScapesAnalysis::draw() if(_dir == V && int(_line) >= (ofGetHeight()+4*_scanLineWidth)){ //cout << "VERTICAL IS DONE - _line >= (ofGetHeight()+4*_scanLineWidth) is TRUE" << endl; - //_state = STATE_SYNTHESISING; _RUN_DONE = true; } @@ -219,14 +303,13 @@ void ShadowScapesAnalysis::draw() if(_dir == H && int(_line) >= (ofGetWidth()+4*_scanLineWidth)) { //cout << "HORIZONTAL IS DONE - _line >= (ofGetWidth()+4*_scanLineWidth)) is TRUE" << endl; - //_state = STATE_SYNTHESISING; _RUN_DONE = true; } if(_dir == D && int(_line) >= (1.5*ofGetHeight()+4*_scanLineWidth)) { //cout << "DIAGONAL IS DONE - _line >= (1.5*ofGetHeight()+4*_scanLineWidth)) is TRUE" << endl; - //_state = STATE_SYNTHESISING; + _RUN_DONE = true; } @@ -235,7 +318,7 @@ void ShadowScapesAnalysis::draw() case STATE_SYNTHESISING: { - cout << "ShadowScapesAnalysis = STATE_SYNTHESISING...\n"; + // cout << "ShadowScapesAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -256,7 +339,7 @@ void ShadowScapesAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + // cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -303,9 +386,7 @@ void ShadowScapesAnalysis::draw() _anim_cnt++; } else { - _RUN_DONE = true; - //_state = STATE_DISPLAY_RESULTS; _anim_cnt=0; } ofPopMatrix(); @@ -317,6 +398,8 @@ void ShadowScapesAnalysis::draw() case STATE_DISPLAY_RESULTS: { + //cout << "STATE_DISPLAY_RESULTS...\n" << endl; + if (_frame_cnt > 2) { @@ -328,40 +411,44 @@ void ShadowScapesAnalysis::draw() if (_show_image) { - //ofEnableAlphaBlending(); + // cout << "_show_image...\n" << endl; - ofSetColor(255, 255, 255, 255); + ofEnableAlphaBlending(); + + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); + image2.draw(0,0, ofGetWidth(), ofGetHeight()); + + ofDisableAlphaBlending(); + + //cvGrayDiff1.draw(0,0, ofGetWidth(), ofGetHeight()); + + + // THE OLD SHIT + /* + ofEnableAlphaBlending(); + + ofSetColor(255, 255, 255, 200); image3.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); image4.setFromPixels(image2.getPixels(),image2.width,image2.height, OF_IMAGE_COLOR); - // image3.draw(0,0, ofGetWidth(), ofGetHeight()); - // image4.draw(0,0, ofGetWidth(), ofGetHeight()); - - /* - cvColorImage1.allocate(image3.width, image3.height); - cvGrayImage1.allocate(image3.width, image3.height); - - cvColorImage2.allocate(image4.width, image4.height); - cvGrayImage2.allocate(image4.width, image4.height); - */ - + cvColorImage1.setFromPixels(image3.getPixels(), image3.width, image3.height); cvColorImage2.setFromPixels(image4.getPixels(), image4.width, image4.height); - // image3.setFromPixels(cvColorImage1.getPixels(),cvColorImage1.width,cvColorImage1.height, OF_IMAGE_COLOR); - // image4.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR); - // cvColorImage1.draw(0,0, ofGetWidth(), ofGetHeight()); - cvGrayImage1 = cvColorImage1; cvGrayImage2 = cvColorImage2; cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); - cvGrayDiff1.dilate(); cvGrayDiff1.contrastStretch(); - + cvGrayDiff1.dilate(); cvGrayDiff1.draw(0,0, ofGetWidth(), ofGetHeight()); - //ofDisableAlphaBlending(); + ofDisableAlphaBlending(); + */ + + //image2.draw(0,0, ofGetWidth(), ofGetHeight()); + } // display results of the synthesis @@ -390,7 +477,7 @@ void ShadowScapesAnalysis::save_cb(Timer& timer) return; } - //cout << "ShadowScapesAnalysis::saving...\n"; + //cout << "ShadowScapesAnalysis::saving analysis...\n"; string file_name; @@ -406,8 +493,8 @@ void ShadowScapesAnalysis::save_cb(Timer& timer) file_name = ofToString(_save_cnt, 2)+"_D_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg"; } - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/ShadowScapesAnalysis.h b/src/ShadowScapesAnalysis.h index ab4c6b8..ed3256a 100755 --- a/src/ShadowScapesAnalysis.h +++ b/src/ShadowScapesAnalysis.h @@ -38,7 +38,7 @@ protected: float _scanLineWidth; // pix per second float _step; shadow_type _dir; - int _run_cnt, _save_cnt, _anim_cnt; + int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; diff --git a/src/ShapeFromShadingAnalysis.cpp b/src/ShapeFromShadingAnalysis.cpp index d41fed0..a6cecb8 100755 --- a/src/ShapeFromShadingAnalysis.cpp +++ b/src/ShapeFromShadingAnalysis.cpp @@ -29,14 +29,30 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight) int anim_time = 5; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames + _show_image = false; _image_shown = false; - //for an ofxOpenCv.h image i would like to use..." - //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 + + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + // cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + // cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); - image1.setUseTexture(false); - image2.setUseTexture(true); } @@ -53,7 +69,7 @@ void ShapeFromShadingAnalysis::acquire() _run_cnt = i; - cout << "RUN NUM = " << i; + //cout << "RUN NUM = " << i; save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files save_timer->start(save_callback); @@ -90,33 +106,82 @@ void ShapeFromShadingAnalysis::acquire() void ShapeFromShadingAnalysis::synthesise() { + // cout << "ShapeFromShadingAnalysis::saving synthesis...\n"; + if(_state == STATE_STOP) return; + + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + // cout << "ShapeFromShadingAnalysis::synthesis FOR LOOP...\n"; + + // cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + // cout << "LOADED image1!!!" << endl; + if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + cvGrayImage1 = cvColorImage1; + cvGrayImage2 = cvColorImage2; + + cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + cvGrayDiff1.erode(); + cvGrayDiff1.contrastStretch(); + //cvGrayDiff1.blur(5); + //cvGrayDiff1.dilate(); + //cvGrayDiff1.contrastStretch(); + + /////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + file_name = ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingSynthesis_"+ofToString(_run_cnt,2)+".jpg"; + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + } + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder while(!_RUN_DONE && _state != STATE_STOP) - Thread::sleep(3); + Thread::sleep(3); + } void ShapeFromShadingAnalysis::displayresults() { - - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ if(_state == STATE_STOP) return; - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + // cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; while(!_image_shown){ Thread::sleep(2); //cout << "!_image_shown" << endl; } - - if(!image1.loadImage(_saved_filenames[i])){ + if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image cout << "didn't load image" << endl; } - - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; @@ -347,7 +412,7 @@ void ShapeFromShadingAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + // cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -368,7 +433,7 @@ void ShapeFromShadingAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + //cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -397,9 +462,9 @@ void ShapeFromShadingAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + //cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + //cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ @@ -430,6 +495,8 @@ void ShapeFromShadingAnalysis::draw() case STATE_DISPLAY_RESULTS: { + // cout << "STATE_DISPLAY_RESULTS...\n" << endl; + if (_frame_cnt > 2) { _image_shown = true; @@ -440,18 +507,21 @@ void ShapeFromShadingAnalysis::draw() if (_show_image) { + // cout << "_show_image...\n" << endl; + ofEnableAlphaBlending(); - ofSetColor(255, 255, 255, 255); - image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); - image2.draw(0,0, ofGetWidth(), ofGetHeight()); + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); + image2.draw(0,0, ofGetWidth(), ofGetHeight()); ofDisableAlphaBlending(); } - + // display results of the synthesis _RUN_DONE = true; break; + } @@ -480,8 +550,7 @@ void ShapeFromShadingAnalysis::save_cb(Timer& timer) string file_name = ofToString(_save_cnt,2)+"_"+ quad +"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - - _saved_filenames.push_back(_whole_file_path+"/"+file_name); + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/ShapeFromShadingAnalysis.h b/src/ShapeFromShadingAnalysis.h index 7f3498e..31c5fed 100755 --- a/src/ShapeFromShadingAnalysis.h +++ b/src/ShapeFromShadingAnalysis.h @@ -51,11 +51,31 @@ protected: int _animation_cnt16; int _animation_reset; // this reset part didn't get working - so using 16 different counters! yay! - int _run_cnt, _save_cnt, _anim_cnt; + int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; - ofImage image1; - ofImage image2; - + ofImage image1; + ofImage image2; + ofImage image3; + ofImage image4; + ofImage image5; + ofImage image6; + + ofxCvColorImage cvColorImage1; + ofxCvColorImage cvColorImage2; + ofxCvColorImage cvColorImage3; + ofxCvColorImage cvColorImage4; + ofxCvColorImage cvColorImage5; + ofxCvColorImage cvColorImage6; + + ofxCvGrayscaleImage cvGrayDiff1; + ofxCvGrayscaleImage cvGrayDiff2; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayImage2; + ofxCvGrayscaleImage cvGrayImage3; + ofxCvGrayscaleImage cvGrayImage4; + + ofxCvContourFinder cvContourFinder1; }; diff --git a/src/StrobeAnalysis.cpp b/src/StrobeAnalysis.cpp index 08dbbc5..d806a56 100755 --- a/src/StrobeAnalysis.cpp +++ b/src/StrobeAnalysis.cpp @@ -14,14 +14,14 @@ void StrobeAnalysis::setup(int camWidth, int camHeight) { NUM_RUN = 1; - int acq_run_time = 20; // 20 seconds of acquiring per run + int acq_run_time = 25; // 20 seconds of acquiring per run - DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files - // or 10 times per second = every 100 ms + DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 100 files + // or 5 times per second = every 200 ms _frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames - _strobe_interval = 1500; //every 1 seconds, or every thirty frames 30 frames + _strobe_interval = 1750; //every 1 seconds, or every thirty frames 30 frames // The British Health and Safety Executive recommend that a net flash rate for a bank of strobe lights does not exceed 5 flashes per second, at which only 5% of photosensitive epileptics are at risk. It also recommends that no strobing effect continue for more than 30 seconds, due to the potential for discomfort and disorientation. @@ -30,14 +30,29 @@ void StrobeAnalysis::setup(int camWidth, int camHeight) int anim_time = 5; // 5 seconds for the animation _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames + _show_image = false; _image_shown = false; - //for an ofxOpenCv.h image i would like to use..." - //image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h); + // images use for drawing the synthesized files to the screen /// + image1.setUseTexture(false); // the non texture image that is needed to first load the image + image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1 - image1.setUseTexture(false); - image2.setUseTexture(true); + // images used for re-loading and saving out the synthesized files /// + image3.setUseTexture(false); + image4.setUseTexture(false); + image5.setUseTexture(false); + + // cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl; + // cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl; + + cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + + cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); + cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); } @@ -75,39 +90,93 @@ void StrobeAnalysis::acquire() void StrobeAnalysis::synthesise() { - // _saved_filenames has all the file names of all the saved images + // cout << "StrobeAnalysis::saving synthesis...\n"; + if(_state == STATE_STOP) return; + + for(float i=1;i<_saved_filenames_analysis.size()-1;i++){ + + // cout << "StrobeAnalysis::synthesis FOR LOOP...\n"; + + // cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl; + + if(_state == STATE_STOP) return; + + if(!image1.loadImage(_saved_filenames_analysis[i])){ + //couldn't load image + // cout << "didn't load image" << endl; + } + + if(image1.loadImage(_saved_filenames_analysis[i])){ + // cout << "LOADED image1!!!" << endl; + //if(image5.loadImage(_saved_filenames_analysis[i+1])){ + + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + + cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); + cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height); + + cvGrayImage1 = cvColorImage1; + //cvGrayImage2 = cvColorImage2; + + //cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); + //cvGrayDiff1.erode(); + //cvGrayDiff1.contrastStretch(); + //cvGrayDiff1.blur(5); + //cvGrayDiff1.dilate(); + //cvGrayDiff1.contrastStretch(); + + cvGrayImage1.contrastStretch(); + cvGrayImage1.blur(10); + cvGrayImage1.dilate(); + + /////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// + string file_name; + + file_name = ofToString(_synth_save_cnt, 2)+"_StrobeAnalysis_"+ofToString(_run_cnt,2)+".jpg"; + + //image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR); + + ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + //ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name); + _synth_save_cnt++; + + //} + } + } + + // _saved_filenames_synthesis has processed all the files in the analysis images folder while(!_RUN_DONE && _state != STATE_STOP) - Thread::sleep(3); + Thread::sleep(3); } void StrobeAnalysis::displayresults() { - for(float i=1;i<_saved_filenames.size();i++){ + for(float i=1;i<_saved_filenames_synthesis.size();i++){ if(_state == STATE_STOP) return; - cout << "_saved_filenames[i]" << _saved_filenames[i] << endl; + // cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl; while(!_image_shown){ Thread::sleep(2); //cout << "!_image_shown" << endl; } - - if(!image1.loadImage(_saved_filenames[i])){ + if(!image3.loadImage(_saved_filenames_synthesis[i])){ //couldn't load image - cout << "didn't load image" << endl; + // cout << "didn't load image" << endl; } - - if(image1.loadImage(_saved_filenames[i])){ - image1.loadImage(_saved_filenames[i]); + if(image3.loadImage(_saved_filenames_synthesis[i])){ + image3.loadImage(_saved_filenames_synthesis[i]); //cout << "_show_image = true;" << endl; _show_image = true; _image_shown = false; } } + } @@ -124,7 +193,7 @@ void StrobeAnalysis::draw() ofEnableAlphaBlending(); ofColor aColour; int _fade_in_frames = _frame_cnt_max/10; - cout<< "_fade_in_frames" << _fade_in_frames<< endl; + // cout<< "_fade_in_frames" << _fade_in_frames<< endl; if (_frame_cnt < _fade_in_frames) { @@ -179,7 +248,7 @@ void StrobeAnalysis::draw() { // display animation of something while the synthesis in on-going... - cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n"; + // cout << "StrobeAnalysis = STATE_SYNTHESISING...\n"; // display animation of something while the synthesis in on-going... ofEnableAlphaBlending(); @@ -200,7 +269,7 @@ void StrobeAnalysis::draw() //ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360)); if (_anim_cnt < _fade_in_frames) { - cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; + // cout << "StrobeAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n"; fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255); @@ -229,9 +298,9 @@ void StrobeAnalysis::draw() if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) { - cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; + // cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl; fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255); - cout << "fade down = " << fade << endl; + // cout << "fade down = " << fade << endl; for (int i=0; i <= 15; i++){ @@ -261,6 +330,8 @@ void StrobeAnalysis::draw() case STATE_DISPLAY_RESULTS: { + // cout << "STATE_DISPLAY_RESULTS...\n" << endl; + if (_frame_cnt > 2) { _image_shown = true; @@ -271,10 +342,12 @@ void StrobeAnalysis::draw() if (_show_image) { + // cout << "_show_image...\n" << endl; + ofEnableAlphaBlending(); - ofSetColor(255, 255, 255, 255); - image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); + ofSetColor(255, 255, 255); + image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE); image2.draw(0,0, ofGetWidth(), ofGetHeight()); ofDisableAlphaBlending(); @@ -284,6 +357,7 @@ void StrobeAnalysis::draw() _RUN_DONE = true; break; + } @@ -311,9 +385,7 @@ void StrobeAnalysis::save_cb(Timer& timer) string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(_strobe_on) +"_"+ofToString(_run_cnt,2)+".jpg"; - ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST); - - _saved_filenames.push_back(_whole_file_path+"/"+file_name); - + ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST); + _saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name); } diff --git a/src/StrobeAnalysis.h b/src/StrobeAnalysis.h index 8eab5fc..dfb4fd7 100755 --- a/src/StrobeAnalysis.h +++ b/src/StrobeAnalysis.h @@ -37,11 +37,32 @@ protected: int _strobe_interval; bool _strobe_on; - int _run_cnt, _save_cnt, _anim_cnt; + int _run_cnt, _save_cnt,_synth_save_cnt, _anim_cnt; float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max; bool _show_image, _image_shown; - ofImage image1; - ofImage image2; + ofImage image1; + ofImage image2; + ofImage image3; + ofImage image4; + ofImage image5; + ofImage image6; + + ofxCvColorImage cvColorImage1; + ofxCvColorImage cvColorImage2; + ofxCvColorImage cvColorImage3; + ofxCvColorImage cvColorImage4; + ofxCvColorImage cvColorImage5; + ofxCvColorImage cvColorImage6; + + ofxCvGrayscaleImage cvGrayDiff1; + ofxCvGrayscaleImage cvGrayDiff2; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayImage2; + ofxCvGrayscaleImage cvGrayImage3; + ofxCvGrayscaleImage cvGrayImage4; + + ofxCvContourFinder cvContourFinder1; };