Compare commits

...

64 Commits

Author SHA1 Message Date
dviid
884e55abd4 MAXBLOBS RelaxRate 2012-03-01 08:52:32 +01:00
dviid
46d02b4166 running app for edinburgh
Tom please test :-)
2012-03-01 07:31:59 +01:00
Jamie Allen
a0483636ac Revert "Revert ebe29d2c8a6544abf5acd8d94be130ec02748f34^..HEAD"
This reverts commit b39f191936473ddc46ca9aa1cc596ea112e22dd8.
2012-03-01 00:30:40 +01:00
Jamie Allen
b39f191936 Revert ebe29d2c8a6544abf5acd8d94be130ec02748f34^..HEAD 2012-03-01 00:21:14 +01:00
dviid
7d4f7ec18c fixed the zoom problem 2012-02-29 11:11:28 +01:00
dviid
d31fd93932 merge tom's grayscale saving code 2012-02-29 10:58:59 +01:00
Jamie Allen
ebe29d2c8a sorry - this is the actual possible windows fix... get this one TOM! 2012-02-27 20:28:33 +01:00
Jamie Allen
86769bfc5f possible Windows saving greyscale fix (convert to COLOR before saving) 2012-02-27 20:23:08 +01:00
Jamie Allen
1f23d167c2 converting cv images properly (thanks Tom) and possible fix for Windows saving of greyscale images
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);

cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
2012-02-27 20:08:54 +01:00
dviid
0d62dbd135 readme fixes 2012-02-27 19:43:19 +01:00
dviid
c653d96c77 new readme with proper deps 2012-02-27 19:42:37 +01:00
dviid
5693046ad9 fix exit procedure 2012-02-27 19:39:57 +01:00
Jamie Allen
81f37f8274 just added some comments to our windows save-out issue... this has david's new RelaxRate code 2012-02-27 19:34:07 +01:00
dviid
ff7d3b6476 relaxrate new contour synthesis
added a rficv folder where we can change ofxcv as needed
2012-02-27 19:26:21 +01:00
Jamie Allen
7b8dcd0940 commit prior to trying to revert to david's branches 2012-02-27 19:26:11 +01:00
Jamie Allen
476ab8cfd9 Revert "Revert "Revert 7da4b4b47a01c19f5059bea111c2edb7c2ddefd8^..HEAD""
This reverts commit f10aeefaef714547fd6baab1b67321187853df3c.
2012-02-27 19:17:18 +01:00
Jamie Allen
f10aeefaef Revert "Revert 7da4b4b47a01c19f5059bea111c2edb7c2ddefd8^..HEAD"
This reverts commit cd49615cfc50e554847ffb8a31269fd5a82c7171.
2012-02-27 18:50:12 +01:00
Jamie Allen
cd49615cfc Revert 7da4b4b47a01c19f5059bea111c2edb7c2ddefd8^..HEAD 2012-02-27 18:47:40 +01:00
dviid
3b9bdde619 relaxrate new contour synthesis
added a rficv folder where we can change ofxcv as needed
2012-02-27 18:14:36 +01:00
dviid
25a423f4ea working on RelaxRate 2012-02-27 16:06:37 +01:00
Jamie Allen
7da4b4b47a #ifdef back in 2012-02-27 03:11:26 +01:00
Jamie Allen
7cd4da7341 cleaned up the windows code there were some mistakes
had to comment out the #ifdef TARGET_OSX   for a bit to see that there
were some windows errors - think i got all of them... have a look Tom
2012-02-27 03:06:40 +01:00
Jamie Allen
5d48d6ef6a small fix - analysis and synthesis were writing to the same folder - better now 2012-02-27 02:46:18 +01:00
Jamie Allen
7a7614d02d put in image.clear() and ofCvImage.clear() statements before allocation and after use of these
trying to solve windows (mostly) crash, which seems to stem from
"OF_WARNING: in allocate, reallocating a ofxCvImage" - hopefully this
is the one!
2012-02-27 02:41:25 +01:00
Jamie Allen
38ec4da627 ALLOCATING the saved images
* moved the synthesis saving to an abstract function called
saveImageSynthesis()
* allocating the images we're saving out in a renamed
create_dir_allocate_images()
* MAKE SURE TO PUT THE CONFIG FILE IN /data/
2012-02-26 19:12:34 +01:00
Jamie Allen
8fe367b47b RUN_NUM and analysis_time for each analysis now set in the config file 2012-02-26 18:01:30 +01:00
Jamie Allen
c8de799215 added config file to the repo - this needs to go in /data/ folder 2012-02-26 17:33:59 +01:00
Jamie Allen
60e51a84f2 this code has consolidated save function in abstract analysis - un-commented the analyses so they all run - 2012-02-26 16:58:18 +01:00
dviid
44c900e060 moved save functionality to AbstractAnalysis 2012-02-26 15:28:27 +01:00
Jamie Allen
51c0098d27 windows compatibility for saving images
* the save functions for image should work on both windows and osx now
(although we might want to move the creation of these images outside
the thread later)
* params for each analysis timing in the XML config
* minor warning / bug fixes in AbstractAnalysis.cpp and
RefractiveIndex.cpp
* cleaned up the use of OF_IMAGE_COLOR/OF_IMAGE_GRAYSCALE in all
analysis classes
2012-02-23 01:22:14 +00:00
Jamie Allen
5564329916 NUM_RUN now set using XML config 2012-02-22 20:48:24 +01:00
Jamie Allen
245d67cf8f the NUM_RUN is now set using the xml config.refindx in each class 2012-02-22 19:41:16 +01:00
Jamie Allen
a51a98a099 _synth_save_cnt = 0 wasn't in the acquire() loop - fixed 2012-02-22 18:35:35 +01:00
Jamie Allen
fe35f843ef cvGrayDiff1 was not being generated properly in RelaxRate - fixed 2012-02-22 16:20:40 +01:00
Jamie Allen
2f0415952e _synth_save_cnt = 0; needed to be reset! 2012-02-22 16:17:24 +01:00
Jamie Allen
1117e632c6 small file saving "_" fix
basically a safety commit - the big changes were in the last one :)
2012-02-22 15:39:49 +01:00
Jamie Allen
2f2b38019e added proper looping structure - fixed up some un-initialised variables
the looping structure for RUN_NUM now occurs in AbstractAnalysis, so
that the sequencing is correct - a few related variables were not reset
- so those are fixed now too.
2012-02-22 15:36:22 +01:00
Jamie Allen
24ddd694c7 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!
2012-02-22 02:09:19 +01:00
Jamie Allen
763d88b115 key presses working for all - still working on opencv imagery 2012-02-21 21:45:18 +01:00
Jamie Allen
b0464c5632 added opencv images - showing but work in progress...
prior to adding david's looping and key control code
2012-02-21 21:20:58 +01:00
dviid
3c13d95bc4 key input controls 2012-02-21 21:18:25 +01:00
Jamie Allen
2903c7a969 david commit 19:31 2012-02-21 19:31:58 +01:00
Jamie Allen
117eaca232 commit for david tues 21st 17:51 2012-02-21 17:51:14 +01:00
Jamie Allen
9fd244dcc1 added openCV.h to each class 2012-02-21 17:26:16 +01:00
Jamie Allen
adbe746afc removed xml shit from the main.cpp 2012-02-21 16:56:38 +01:00
Jamie Allen
5df657051d removed the xml shit in main.cpp 2012-02-21 16:48:39 +01:00
Jamie Allen
7dc3e305a8 next day still working commit 2012-02-21 12:04:49 +01:00
Jamie Allen
7bb2f2c1e1 removed a few extraneous comments 2012-02-21 02:05:47 +01:00
Jamie Allen
0cd3bca7c0 cleanups, a few comments, and cout commented out 2012-02-21 02:01:01 +01:00
Jamie Allen
78c2edc0ac couple of todos added
//TODO:  Needs to return to a black screen - not to exit...

    // i.e.: operational sequence
    //    1) starts in a black screen
    //    2) we 'start' with keypress "s" the entire set of analyses
    //    3) at any point we need to be able to restart /
stop-return-to-black / trigger each analysis individually
    //    4) should end in black screen as well
    //    5) final kill button
2012-02-21 01:50:47 +01:00
Jamie Allen
680e22ccf9 tuesday 2 AM commit -
big priorities -
* figure out why its writing so many black images
* fix the double-run that occurs when the first anlysis runs
* do something pretty with the incoming image
2012-02-21 01:39:27 +01:00
Jamie Allen
3eef15a14b added image playout for all classes 2012-02-21 01:34:24 +01:00
Jamie Allen
e17a3a0d91 now able to show images in the analysis classes!!
wooo hooo!!!
2012-02-21 01:01:49 +01:00
Jamie Allen
51c71bdc15 added vid grab to IResponse 2012-02-20 20:28:12 +01:00
Jamie Allen
2bd7704f38 put the RefractiveIndex::_vidGrabber.grabFrame(); // in each class
david's solution for the black frames...
2012-02-20 20:24:25 +01:00
Jamie Allen
e1e4e15529 safety commit 2012-02-20 20:10:32 +01:00
Jamie Allen
b514c12a53 fixed timings so everything is on the second-basis, fixed David's flags so that each section in the classes terminates on RUN_DONE 2012-02-20 19:48:43 +01:00
Jamie Allen
12d210327b added STATE_SYNTHESISING - animation loop - for each analysis - comments needs cleaning up but they all seem to work...
NOT SURE I'M USING THE STATES CORRECTLY!?
2012-02-20 03:40:38 +01:00
Jamie Allen
b045f44bf1 fixed fades and added the animation for ShadowScapesAnalysis (which will be the same for all analyses - just havne't copied it over yet)
also tried to add a key-press trigger for each analysis but wasn't able to turn off prior analyses without hanging the whole programme
2012-02-20 01:47:46 +01:00
Jamie Allen
f2593aed49 tried to add a keypress function - got almost there... need to figure out how to turn off the Analyses from RefractiveIndex.cpp... without blocking 2012-02-19 23:34:48 +01:00
Jamie Allen
d536774cc8 REDO of the cleanup of the save callbacks so i can put the fucking latency code in...
(git hub did something weird)
2012-02-19 23:00:34 +01:00
Jamie Allen
6395b1c0a0 Revert 85ce9c2e6729fc1cee394b46ac868e4086d476f9^..HEAD 2012-02-19 22:47:55 +01:00
Tom Schofield
7bb5734eed added image loading and display results stuff- changes all commented in code 2012-02-19 22:47:44 +01:00
Jamie Allen
85ce9c2e67 cleaned up the save_cb on all analyses 2012-02-19 21:45:28 +01:00
28 changed files with 3811 additions and 712 deletions

6
README
View File

@ -1,10 +1,10 @@
WARNING: WORK IN PROGRESS...
configuring OpenFrameworks
-----------------
configuring OpenFrameworks under Xcode
---------------------------------------
these files are configured according to OpenFrameworks addons - http://ofxaddons.com/howto
(1) drag-drop "ReflectiveIndex" folder into your OpenFrameworks project
(2) Install depedencies: {ofxDirList, ofxControlPanel, ofxXmlSettings};
(2) Install depedencies: {ofxXmlSettings, ofxOpenCV, ofxFileHelper};
(3) Press Play!

45
config.refindx Normal file
View File

@ -0,0 +1,45 @@
<!-- THIS FILE NEEDS TO GO IN THE APPLICATION /data/ folder -->
<config>
<camera>
<id>1</id>
<width>640</width>
<height>480</height>
</camera>
<display>
<fps>30</fps>
</display>
<locale>
<name>SWANSEA</name>
</locale>
<analysis_NUM_RUN>
<NUM_RUN_shadowscapes> 3 </NUM_RUN_shadowscapes>
<NUM_RUN_relaxrate> 3 </NUM_RUN_relaxrate>
<NUM_RUN_iresponse> 3 </NUM_RUN_iresponse>
<NUM_RUN_shapefromshading> 3 </NUM_RUN_shapefromshading>
<NUM_RUN_strobe> 5 </NUM_RUN_strobe>
<NUM_RUN_camnoise> 5 </NUM_RUN_camnoise>
<NUM_RUN_colorsingle> 5 </NUM_RUN_colorsingle>
<NUM_RUN_colormulti> 5 </NUM_RUN_colormulti>
<NUM_RUN_diffnoise> 3 </NUM_RUN_diffnoise>
</analysis_NUM_RUN>
<analysis_time>
<acquiretime_shadowscapes> 30 </acquiretime_shadowscapes>
<acquiretime_relaxrate> 30 </acquiretime_relaxrate>
<acquiretime_iresponse> 30 </acquiretime_iresponse>
<acquiretime_shapefromshading> 30 </acquiretime_shapefromshading>
<acquiretime_strobe> 30 </acquiretime_strobe>
<acquiretime_camnoise> 30 </acquiretime_camnoise>
<acquiretime_colorsingle> 40 </acquiretime_colorsingle>
<acquiretime_colormulti> 40 </acquiretime_colormulti>
<acquiretime_diffnoise> 30 </acquiretime_diffnoise>
</analysis_time>
<relaxrate>
<treshold>51</treshold>
<maxblobs>25</maxblobs>
</relaxrate>
</config>

View File

@ -1,12 +1,5 @@
/*
todo:
(1) Look at warinings about the #define which get over written
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
////also the new shit////
#include "RefractiveIndex.h"
@ -22,7 +15,7 @@
#include "ofxXmlSettings.h"
#define CAMERA_ID 1
#define CAMERA_ID 0
#define CAMERA_ACQU_WIDTH 640
#define CAMERA_ACQU_HEIGHT 480
@ -43,22 +36,26 @@ bool RefractiveIndex::_vid_stream_open;
bool RefractiveIndex::_vid_toggle_on;
string RefractiveIndex::_location;
ofxXmlSettings XML;
ofxXmlSettings RefractiveIndex::XML;
void RefractiveIndex::setup()
{
bool save_config = false;
cout << "Loading configuration..." << endl;
if(!XML.loadFile("../data/config.refindx")) {
if(XML.loadFile("config.refindx") == false) {
ofLog(OF_LOG_ERROR) << "error loading config - using default.";
save_config = true;
} else {
XML.loadFile("config.refindx");
}
// <camera>
_vid_id = XML.getValue("config:camera:id", CAMERA_ID);
_vid_w = XML.getValue("config:camera:width", CAMERA_ACQU_WIDTH);
_vid_h = XML.getValue("config:camera:height", CAMERA_ACQU_HEIGHT);
cout << "_vid_id: " << _vid_id << endl;
_vid_w = XML.getValue("config:camera:width", CAMERA_ACQU_WIDTH);
_vid_h = XML.getValue("config:camera:height", CAMERA_ACQU_HEIGHT);
// <display>
int fps = XML.getValue("config:display:fps", 30);
@ -71,6 +68,7 @@ void RefractiveIndex::setup()
// display
cout << "> display" << endl;
ofSetFrameRate(fps);
if(fps > 30) {
ofSetVerticalSync(FALSE);
} else {
@ -93,16 +91,18 @@ void RefractiveIndex::setup()
//getting a warning from the OFlog that the pixels aren't allocated
//void ofPixels::allocate(int w, int h, ofImageType type)
_pixels.allocate(_vid_w, _vid_h, OF_IMAGE_COLOR);
//TODO: whichever one of these is first - it always runs twice ?
_analysisVector.push_back(new ShadowScapesAnalysis(V));
_analysisVector.push_back(new ShadowScapesAnalysis(V));
_analysisVector.push_back(new ShadowScapesAnalysis(H));
_analysisVector.push_back(new ShadowScapesAnalysis(D));
_analysisVector.push_back(new RelaxRateAnalysis());
_analysisVector.push_back(new IResponseAnalysis());
_analysisVector.push_back(new ShapeFromShadingAnalysis());
@ -115,13 +115,15 @@ void RefractiveIndex::setup()
_analysisVector.push_back(new ColorMultiAnalysis());
_analysisVector.push_back(new DiffNoiseAnalysis());
_currentAnalysisIndx = 0;
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx);
_analysisVector.push_back(new DiffNoiseAnalysis());
_state = ISTATE_START;
//_currentAnalysisIndx = 0;
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
//_state = ISTATE_START;
_currentAnalysis = NULL;
_state = ISTATE_UNDEF;
}
@ -161,7 +163,9 @@ void RefractiveIndex::state_analysis()
case ISTATE_TRANSITION:
if(_currentAnalysisIndx >= _analysisVector.size()) {
_currentAnalysisIndx = 0;
_state = ISTATE_END;
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
_state = ISTATE_START;
//_state = ISTATE_END;
} else {
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
_state = ISTATE_START;
@ -183,20 +187,18 @@ void RefractiveIndex::state_analysis()
}
void RefractiveIndex::update()
{
{
state_analysis();
RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera
if (_vidGrabber.isFrameNew())
{
_pixels = _vidGrabber.getPixelsRef(); //get ofPixels from the camera
}
}
void RefractiveIndex::draw()
{
// refractive mauve - this doesn't work... looks weird in various places.
//ofBackground(113, 110, 136);
// black
ofBackground(0, 0, 0);
if(_currentAnalysis)
_currentAnalysis->draw();
}
@ -204,16 +206,22 @@ void RefractiveIndex::draw()
void RefractiveIndex::setup_camera()
{
stop_camera();
// THIS IS LOADED IN FROM THE XML FILE SETTINGS
_vidGrabber.setDeviceID(_vid_id);
_vidGrabber.listDevices();
if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) {
ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber";
return;
}
_vidGrabber.listDevices();
_vidGrabber.setVerbose(true);
_vidGrabber.setVerbose(true);
_vidGrabber.setUseTexture(false);
_vid_stream_open = true;
_vidGrabber.setDeviceID(_vid_id);
cout << "CAMERA SETUP " << endl;
return;
}
void RefractiveIndex::stop_camera()
@ -228,9 +236,167 @@ void RefractiveIndex::keyPressed (int key)
{
if( key =='f')
ofToggleFullscreen();
/* TODO: complete the below... would be good to trigger the Analysis from keypresses if needed... */
// currently this doesn't work... the save_cb's in the individual
// tried to add a stop_analysis(); call but it blocks the whole programme
// i.e.: ask david how to shut off the prior Analysis if it's not finished running from here?
if(key == 'x')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysis = NULL;
_state = ISTATE_UNDEF;
}
else if(key == '1')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 0;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '2')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 1;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '3')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 2;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '4')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 3;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '5')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 4;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '6')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 5;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '7')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 6;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '8')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 7;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '9')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 8;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == '0')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 9;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
else if(key == 'q')
{
if(_currentAnalysis)
_analysisAdapator->stop();
_currentAnalysisIndx = 10;
if(!_currentAnalysis)
_state = ISTATE_TRANSITION;
}
/*
TO DO: add a file dialog so we can save images to another hard drive...
e.g.: http://dev.openframeworks.cc/pipermail/of-dev-openframeworks.cc/2011-April/003125.html
>> case 's':
>> doSave ^= true;
>> doLoad = false;
>> if(doSave) {
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to save to", true);
>> if(r.bSuccess) {
>> saveCounter = 0;
>> savePath = r.getPath();
>> ofDirectory::createDirectory(savePath + "/color/");
>> ofDirectory::createDirectory(savePath + "/depth/");
>> printf("SAVE %s %s\n", r.getPath().c_str(), r.getName().c_str());
>> } else {
>> doSave = false;
>> }
>>
>> }
>> break;
>>
>> case 'l':
>> doLoad ^= true;
>> doSave = false;
>> if(doLoad) {
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to load from", true);
>> if(r.bSuccess) {
>> loadCounter = 0;
>> loadPath = r.getPath();
>> ofDirectory dir;
>> loadMaxFiles = MAX(dir.listDir(loadPath + "/color"), dir.listDir(loadPath + "/depth"));
>> printf("LOAD %i %s %s\n", loadMaxFiles, r.getPath().c_str(), r.getName().c_str());
>> } else {
>> doLoad = false;
>> }
>>
>> }
>> break;
*/
}
void RefractiveIndex::exit()
{
if(_currentAnalysis)
_analysisAdapator->stop();
stop_camera();
}

View File

@ -1,8 +1,3 @@
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#pragma once
@ -13,6 +8,8 @@
#include "AbstractAnalysis.h"
#include "AnalysisAdaptor.h"
#include "ofxOpenCv.h"
#include "ofxXmlSettings.h"
class RefractiveIndex : public ofBaseApp
{
@ -65,6 +62,6 @@ public:
// this should be in xml
static string _location;
static ofxXmlSettings XML; // made this static so we can access RUN_NUM in the analyses
};

View File

@ -1,35 +1,27 @@
#include "ofAppGlutWindow.h"
#include "RefractiveIndex.h"
#include "ofxXmlSettings.h"
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
/////////////////////////dis is the new shit///////////
/////////////////////////dis is the new shit///////////
/////////////////////////dis is the new shit///////////
/////////////////////////dis is the new shit///////////
int main() {
ofAppGlutWindow window;
ofxXmlSettings XML;
XML.loadFile("../data/config.refindx");
bool fullscreen = (XML.getValue("config:display:fullscreen", "false") == "true" ? true : false);
int screen_w = XML.getValue("config:display:width", SCREEN_WIDTH);
int screen_h = XML.getValue("config:display:height", SCREEN_HEIGHT);
ofAppGlutWindow window;
bool fullscreen;
//fullscreen = true;
fullscreen = false;
cout << "> display configuration" << endl;
cout << "* fullscreen: " << (fullscreen ? "yes" : "no") << endl;
if(!fullscreen) {
cout << "* screen width: " << screen_w << endl;
cout << "* screen height: " << screen_h << endl;
cout << "* screen width: " << SCREEN_WIDTH << endl;
cout << "* screen height: " << SCREEN_HEIGHT << endl;
}
ofSetupOpenGL(&window, screen_w, screen_h, (fullscreen ? OF_FULLSCREEN : OF_WINDOW));
ofSetupOpenGL(&window, SCREEN_WIDTH, SCREEN_HEIGHT, (fullscreen ? OF_FULLSCREEN : OF_WINDOW));
ofRunApp(new RefractiveIndex());
}

View File

@ -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,15 +6,29 @@
// this is the main threaded loop for a given analysis
void AbstractAnalysis::do_synthesize() {
_state = STATE_ACQUIRING;
acquire();
_state = STATE_SYNTHESISING;
synthesise();
_state = STATE_DISPLAY_RESULTS;
for(int i = 0; i < NUM_RUN; i++) {
cout << "NUM_RUN: " << i << endl;
_saved_filenames_analysis.clear();
_saved_filenames_synthesis.clear();
_state = STATE_ACQUIRING;
acquire();
if(_state == STATE_STOP) goto exit;
_state = STATE_SYNTHESISING;
synthesise();
if(_state == STATE_STOP) goto exit;
_state = STATE_DISPLAY_RESULTS;
displayresults();
}
exit:
ofNotifyEvent(_synthesize_cb, _name);
}
void AbstractAnalysis::create_dir()
void AbstractAnalysis::create_dir_allocate_images()
{
// HERE IS WHERE WE SETUP THE DIRECTORY FOR ALL THE SAVED IMAGES
@ -67,17 +51,133 @@ 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)){
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH))
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH);
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location))
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location);
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name))
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name);
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime))
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
}
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
_whole_file_path_synthesis = SYNTHESIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime;
if(!fileHelperSynthesis.doesDirectoryExist(_whole_file_path_synthesis)){
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH))
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH);
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location))
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location);
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name))
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name);
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime))
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
}
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
//////////////////////////////ALLOCATE IMAGES //////////////////////////////////////////////////
myColorImage1.clear();
myColorImage1.setUseTexture(false);
myColorImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
myColorImage2.clear();
myColorImage2.setUseTexture(false);
myColorImage2.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
myGrayImage1.clear();
myGrayImage1.setUseTexture(false);
myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE);
//////////////////////////////END ALLOCATE IMAGES //////////////////////////////////////////////////
}
void AbstractAnalysis::saveImageAnalysis(string filename)
{
RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera
if (RefractiveIndex::_vidGrabber.isFrameNew())
{
RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
} else {
return;
}
#ifdef TARGET_OSX
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+filename, OF_IMAGE_QUALITY_BEST);
#elif defined(TARGET_WIN32)
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
unsigned char * somePixels;
ofPixels appPix = RefractiveIndex::_pixels;
somePixels = appPix.getPixels();
myColorImage1.setUseTexture(false);
myColorImage1.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
myColorImage1.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+filename);
myColorImage1.clear();
#endif
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+filename);
}
void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType)
{
#ifdef TARGET_OSX
ofSaveImage(newPixels->getPixelsRef(), _whole_file_path_synthesis+"/"+filename, OF_IMAGE_QUALITY_BEST);
#elif defined(TARGET_WIN32)
if (newType == OF_IMAGE_COLOR){
myColorImage2.setUseTexture(false);
myColorImage2.setFromPixels(newPixels->getPixels(), newPixels->getWidth(), newPixels->getHeight(), OF_IMAGE_COLOR);
myColorImage2.saveImage(_whole_file_path_synthesis+"/"+filename);
}
if (newType == OF_IMAGE_GRAYSCALE){
myGrayImage1.setUseTexture(false);
// THIS IS HOW YOU HAVE TO SAVE OUT THE GREYSCALE IMAGES on WINDOWS FOR SOME REASON --> i.e.: as an OF_IMAGE_COLOR
// But they don't save properly - they're spatially translated and generally f'd up
myGrayImage1.setFromPixels(newPixels->getPixels(), newPixels->getWidth(), newPixels->getHeight(), OF_IMAGE_COLOR);
myGrayImage1.setImageType(OF_IMAGE_COLOR);
myGrayImage1.saveImage(_whole_file_path_synthesis+"/"+filename);
//myGrayImage1.clear();
}
#endif
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+filename);
}

View File

@ -7,9 +7,11 @@
#include "ofMain.h"
#include "ofEvents.h"
#include "ofxOpenCv.h"
#include <string>
#define ANALYSIS_PATH "analysis/"
#define SYNTHESIS_PATH "synthesis/"
#define STATE_ACQUIRING 0x1111
#define STATE_SYNTHESISING 0x2222
@ -24,15 +26,19 @@ 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:
virtual void create_dir();
virtual void create_dir_allocate_images();
virtual void saveImageAnalysis(string filename);
virtual void saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType);
// acquire images - all the children (see - do_synthesize)
virtual void acquire() = 0;
@ -40,6 +46,8 @@ protected:
// analysis + synthesize images - all the children (see - do_synthesize)
virtual void synthesise() = 0;
// display the results from disk
virtual void displayresults() = 0;
public:
string _name;
@ -49,11 +57,18 @@ public:
protected:
int _cam_w, _cam_h;
string _whole_file_path;
vector<string> _saved_filenames;
string _whole_file_path_analysis, _whole_file_path_synthesis;
vector<string> _saved_filenames_analysis;
vector<string> _saved_filenames_synthesis;
int _state;
ofImage myColorImage1;
ofImage myColorImage2;
ofImage myGrayImage1;
//int _run_cnt;
float DELTA_T_SAVE;
int NUM_PHASE;
int NUM_RUN;

View File

@ -21,19 +21,23 @@ public:
void start()
{
_stopping = false;
_runnable = new RunnableAdapter<AbstractAnalysis>(*_analysis, &AbstractAnalysis::do_synthesize);
_worker.start(*_runnable);
}
void stop()
{
if(_stopping) return;
_stopping = true;
_analysis->_state = STATE_STOP;
_worker.join();
_worker.join();
}
protected:
AbstractAnalysis* _analysis;
Thread _worker; //
RunnableAdapter<AbstractAnalysis>* _runnable;
RunnableAdapter<AbstractAnalysis>* _runnable;
bool _stopping;
};

View File

@ -1,8 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "CamNoiseAnalysis.h"
#include "ofMain.h"
@ -15,19 +10,88 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 200;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
create_dir();
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_camnoise", NUMBER_RUNS);
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_camnoise", ACQUIRE_TIME);
cout << "ACQUIRE_TIME CamNoiseAnalysis " << acq_run_time << endl;
//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 5 times per second = every 200 ms
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
_frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
_run_cnt = 0;
_synth_save_cnt = 0;
c = 0;
int anim_time = 10; // 10 seconds
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
//create_dir_allocate_images();
_show_image = false;
_image_shown = false;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@ -35,33 +99,139 @@ void CamNoiseAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<CamNoiseAnalysis> save_callback(*this, &CamNoiseAnalysis::save_cb);
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_run_cnt++;
_RUN_DONE = false;
create_dir_allocate_images();
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
// for(int i = 0; i < NUM_RUN; i++) {
// _run_cnt = i;
//cout << "RUN NUM = " << i;
_run_cnt = i;
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
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;
while(!_RUN_DONE)
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
// }
}
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);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
// cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
//added by tom we weren't actually setting cvgrayimage1 anywhere
// cvGrayImage1.setFromPixels(cvColorImage1.getPixels(),cvColorImage1.width,cvColorImage1.height);
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
//cvGrayImage1=cvColorImage1;
cvGrayImage1.erode();
cvGrayImage1.erode();
cvGrayImage1.erode();
cvGrayImage1.blur();
cvGrayImage1.contrastStretch();
/* cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.blur();
cvColorImage1.contrastStretch();*/
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
string file_name;
file_name = ofToString(_synth_save_cnt, 2)+"_CamNoiseAnalysis_"+ofToString(_run_cnt,2)+".jpg";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvGrayImage1.getPixels(), cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayImage1,cvGrayImage1,cvGrayImage1);
//cvConvertorImage.setFromGrayscalePlanarImages(cvColorImage1,cvColorImage1,cvColorImage1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
_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_synthesis.size();i++){
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;
}
}
}
// this runs at frame rate = 33 ms for 30 FPS
@ -73,77 +243,183 @@ void CamNoiseAnalysis::draw()
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
if (_frame_cnt < _frame_cnt_max)
{
ofEnableAlphaBlending();
ofColor aColour;
int _fade_in_frames = _frame_cnt_max/10;
float _number_of_grey_levels=10;
float _number_of_grey_levels=5;
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;
//cout << "FADE IN STROBE TIME " << endl;
}
if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){
for(int i=0;i<_number_of_grey_levels;i++){
if (_frame_cnt>= _frames_per_level *( i-1) && +_frame_cnt < _frames_per_level * (i) ) {
*/
//if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max)){
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, 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();
} else {
// _state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
//cout << "CamNoiseAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360));
if (_anim_cnt < _fade_in_frames) {
//cout << "CamNoiseAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
//cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
//_state = STATE_DISPLAY_RESULTS;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
//cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
image2.draw(0,0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
default:
break;
}
}
@ -153,15 +429,6 @@ void CamNoiseAnalysis::save_cb(Timer& timer)
_save_cnt++;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string thisLocation = RefractiveIndex::_location;
string file = _whole_file_path+"/"+file_name;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file);
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
saveImageAnalysis(file_name);
}

View File

@ -9,6 +9,9 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
class CamNoiseAnalysis : public AbstractAnalysis
{
public:
@ -20,6 +23,8 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -27,8 +32,36 @@ public:
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max,_save_cnt_max ;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -1,35 +1,3 @@
/*
- 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 "ColorMultiAnalysis.h"
#include "ofMain.h"
@ -41,52 +9,215 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 150; // the right number is about 300
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 300;
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colormulti", NUMBER_RUNS);
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colormulti", ACQUIRE_TIME);
cout << "ACQUIRE_TIME ColorMultiAnalysis " << acq_run_time << endl;
//int acq_run_time = 35;
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
//create_dir_allocate_images();
create_dir();
_frame_cnt = 0;
_fade_cnt=0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
_run_cnt = 0;
_synth_save_cnt = 0;
c = 0;
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;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
void ColorMultiAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<ColorMultiAnalysis> save_callback(*this, &ColorMultiAnalysis::save_cb);
_run_cnt++;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_RUN_DONE = false;
create_dir_allocate_images();
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
//for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = i;
// _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);
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;
while(!_RUN_DONE)
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
//}
}
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);
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";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
_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_synthesis.size();i++){
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;
}
}
}
@ -96,27 +227,29 @@ void ColorMultiAnalysis::draw()
switch (_state) {
case STATE_ACQUIRING:
{
ofEnableAlphaBlending();
if (_frame_cnt < _frame_cnt_max)
{
int _fade_in_frames = _frame_cnt_max/50;
ofColor aColor;
if (_frame_cnt < _fade_in_frames) {
ofColor aColor;
aColor.setHsb(c, ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255), ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
ofSetColor(aColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
cout << "FADING IN..." << endl;
//cout << "FADING IN..." << endl;
}
if (_frame_cnt >= _fade_in_frames && _frame_cnt < _frame_cnt_max-_fade_in_frames){
ofColor aColor;
aColor.setHsb(c, 255, 255);
ofSetColor(aColor);
@ -126,41 +259,142 @@ void ColorMultiAnalysis::draw()
ofRect(0, 0, ofGetWidth(), ofGetHeight());
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt <= _frame_cnt_max) {
ofColor aColor;
aColor.set(c, c, c, 255-int(ofMap(_frame_cnt-(_frame_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255)));
aColor.setHsb(c, 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255), 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255));
//aColor.setHsb(c, 255-ofMap(_fade_cnt- (_frame_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255), 255-(ofMap(_fade_cnt-(_frame_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255)));
ofSetColor(aColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
_fade_cnt++;
cout << "FADING OUT..." << endl;
//cout << "FADING OUT..." << endl;
}
} else {
//_state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
_frame_cnt++;
ofDisableAlphaBlending();
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
//cout << "ColorMultiAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360));
if (_anim_cnt < _fade_in_frames) {
//cout << "ColorMultiAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
//cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_state = STATE_DISPLAY_RESULTS;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
//cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
image2.draw(0,0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
@ -175,18 +409,8 @@ void ColorMultiAnalysis::draw()
void ColorMultiAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
// UPDATE THE COLOR ON THE SCREEN
//float c_last = c;
// cout << "COLORMULTIANALYSIS::saving...\n";
// cout << "c_last... " << c << endl;
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
// cout<<_whole_file_path<<endl;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//if(_save_cnt >= NUM_SAVE_PER_RUN){
// _RUN_DONE = true;
//}
saveImageAnalysis(file_name);
}

View File

@ -4,6 +4,9 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
class ColorMultiAnalysis : public AbstractAnalysis
{
public:
@ -14,7 +17,8 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -22,6 +26,37 @@ public:
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt, _fade_cnt;
float c, _frame_cnt, _frame_cnt_max;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -1,8 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "ColorSingleAnalysis.h"
#include "ofMain.h"
@ -15,23 +10,92 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 300;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colorsingle", NUMBER_RUNS);
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
create_dir();
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colorsingle", ACQUIRE_TIME);
cout << "ACQUIRE_TIME ColorSingleAnalysis " << acq_run_time << endl;
//int acq_run_time = 25; // 20 seconds of acquiring per run
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
//create_dir_allocate_images();
_run_cnt = 0;
_frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
_synth_save_cnt = 0;
c = 0;
int anim_time = 10; // 10 seconds
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
r = 0;
g = 0;
b = 0;
_fade_cnt=0;
fileNameTag = "";
_show_image = false;
_image_shown = false;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@ -41,29 +105,130 @@ void ColorSingleAnalysis::acquire()
Timer* save_timer;
TimerCallback<ColorSingleAnalysis> save_callback(*this, &ColorSingleAnalysis::save_cb);
_run_cnt++;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_RUN_DONE = false;
create_dir_allocate_images();
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
//for(int i = 0; i < NUM_RUN; i++) {
// _run_cnt = i;
//cout << "RUN NUM = " << i;
_run_cnt = 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;
while(!_RUN_DONE)
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
// }
}
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);
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";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
_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_synthesis.size();i++){
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;
}
}
}
@ -115,16 +280,17 @@ void ColorSingleAnalysis::draw()
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max){
ofSetColor(0, 0, 255-ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255));
cout << "255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255)"<< 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255) << endl;
int fade = ofMap(_fade_cnt, 0, _fade_in_frames, 0, 255);
ofSetColor(0, 0, 255-fade);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
_fade_cnt++;
fileNameTag = "FADING";
}
} else {
//_state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
@ -136,13 +302,118 @@ void ColorSingleAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
//cout << "ColorSingleAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360));
if (_anim_cnt < _fade_in_frames) {
// cout << "ColorSingleAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
//cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
//_state = STATE_DISPLAY_RESULTS;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
//cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
image2.draw(0,0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
default:
@ -156,15 +427,7 @@ void ColorSingleAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
// cout << "ColorSingleAnalysis::saving...\n";
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);
//cout<<_whole_file_path+"/"+file_name<<endl;
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
saveImageAnalysis(file_name);
}

View File

@ -9,6 +9,9 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
class ColorSingleAnalysis : public AbstractAnalysis
{
public:
@ -19,7 +22,8 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -28,6 +32,38 @@ protected:
bool _RUN_DONE;
string fileNameTag;
int _run_cnt, _save_cnt, _fade_cnt;
float r,g,b, _frame_cnt, _frame_cnt_max;
float r,g,b;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -1,8 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "DiffNoiseAnalysis.h"
#include "ofMain.h"
@ -15,51 +10,217 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 600; // right number is about 450
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 50;
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
create_dir();
_fade_cnt=0;
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_diffnoise", ACQUIRE_TIME);
cout << "ACQUIRE_TIME DiffNoiseAnalysis " << acq_run_time << endl;
//int acq_run_time = 20; // 20 seconds of acquiring per run
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
//create_dir_allocate_images();
_run_cnt = 0;
_frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
_synth_save_cnt = 0;
c = 0;
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;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
void DiffNoiseAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<DiffNoiseAnalysis> save_callback(*this, &DiffNoiseAnalysis::save_cb);
_run_cnt++;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_RUN_DONE = false;
create_dir_allocate_images();
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
//for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = i;
// _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;
while(!_RUN_DONE)
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
//}
}
void DiffNoiseAnalysis::synthesise()
{
//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);
cvColorImage1.invert();
cvColorImage1.blur(5);
cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.blur(5);
cvColorImage1.erode();
cvColorImage1.erode();
//////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
string file_name;
file_name = ofToString(_synth_save_cnt, 2)+"_DiffNoiseAnalysis_"+ofToString(_run_cnt,2)+".jpg";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvColorImage1.width, cvGrayImage1.height, OF_IMAGE_COLOR);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
_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()
{
// _saved_filenames has all the file names of all the saved images
for(float i=1;i<_saved_filenames_synthesis.size();i++){
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;
}
}
}
@ -92,12 +253,12 @@ void DiffNoiseAnalysis::draw()
}
}
cout << "FADING IN..." << endl;
//cout << "FADING IN..." << 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-_fade_in_frames)){
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
{
@ -113,29 +274,27 @@ void DiffNoiseAnalysis::draw()
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt <= _frame_cnt_max) {
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
{
for (int j=1; j < ofGetWidth(); j=j+rectSize)
{
c = ofRandom(0,255);
aColour.set(c, c, c, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
aColour.set(c, c, c, 255-ofMap(_frame_cnt-(_frame_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255));
ofSetColor(aColour);
ofRect(j, i, rectSize, rectSize);
}
}
_fade_cnt++;
cout << "FADING OUT..." << endl;
//_fade_cnt++;
//cout << "FADING OUT..." << endl;
}
ofDisableAlphaBlending();
} else {
// _state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
@ -148,51 +307,130 @@ void DiffNoiseAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
//cout << "DiffNoiseAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360));
if (_anim_cnt < _fade_in_frames) {
//cout << "DiffNoiseAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
//cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
//_state = STATE_DISPLAY_RESULTS;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
//cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
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();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
default:
break;
}
}
// this runs at save_cb timer rate = DELTA_T_SAVE
void DiffNoiseAnalysis::save_cb(Timer& timer)
{
float rand10 = ofRandom(0,10);
if (rand10 > 5.0) {
cout << "DiffNoiseAnalysis::saving...\n";
cout << "c_last... " << c << endl;
cout<<"rand10... " <<rand10<<endl;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string thisLocation = RefractiveIndex::_location;
//RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
// fileName = imageSaveFolderPath+whichAnalysis+"_"+ofToString(100.0*i*scanLineSpeed/ofGetHeight(),2)+"%_"+ofToString(i)+".jpg";
//ofSaveImage(vectorOfPixels[i], fileName, OF_IMAGE_QUALITY_BEST);
string file = _whole_file_path+"/"+file_name;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file);
}
_save_cnt++;
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
saveImageAnalysis(file_name);
}

View File

@ -9,6 +9,9 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
class DiffNoiseAnalysis : public AbstractAnalysis
{
public:
@ -19,7 +22,8 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -27,7 +31,36 @@ public:
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt, _fade_cnt;
float c, _frame_cnt, _frame_cnt_max;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -1,8 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "IResponseAnalysis.h"
#include "ofMain.h"
@ -15,17 +10,86 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
void IResponseAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_iresponse", NUMBER_RUNS);
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
create_dir();
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_iresponse", ACQUIRE_TIME);
cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl;
//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
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
//create_dir_allocate_images();
_synth_save_cnt = 0;
_run_cnt = 0;
_frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
c = 0;
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;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@ -33,31 +97,131 @@ void IResponseAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<IResponseAnalysis> save_callback(*this, &IResponseAnalysis::save_cb);
_run_cnt++;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_RUN_DONE = false;
create_dir_allocate_images();
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
//for(int i = 0; i < NUM_RUN; i++) {
//_run_cnt = i;
//cout << "RUN NUM = " << i;
_run_cnt = 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;
while(!_RUN_DONE)
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
//}
}
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);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
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";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
_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_synthesis.size();i++){
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;
}
}
}
@ -70,9 +234,18 @@ void IResponseAnalysis::draw()
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
ofEnableAlphaBlending();
ofColor aColour;
int _fade_in_frames = _frame_cnt_max/10;
//cout<< "_fade_in_frames" << _fade_in_frames<< endl;
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());
}
if (_frame_cnt < _frame_cnt_max)
{
@ -80,9 +253,18 @@ void IResponseAnalysis::draw()
ofRect(0, 0, ofGetWidth(), ofGetHeight());
c = 255.0 * (_frame_cnt_max*_frame_cnt_max - _frame_cnt*_frame_cnt)/(_frame_cnt_max*_frame_cnt_max);
} else {
_RUN_DONE = true;
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
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();
_frame_cnt++;
break;
@ -91,16 +273,119 @@ void IResponseAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
// cout << "IResponse = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360));
if (_anim_cnt < _fade_in_frames) {
//cout << "IResponse STATE_SYNTHESIZING = FADING IN ANIMATION...\n";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
//cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
//cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
image2.draw(0,0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
default:
break;
}
@ -112,17 +397,7 @@ void IResponseAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
cout << "IResponseAnalysis::saving...\n";
//cout << "c_last... " << c << endl;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string thisLocation = RefractiveIndex::_location;
//RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
// fileName = imageSaveFolderPath+whichAnalysis+"_"+ofToString(100.0*i*scanLineSpeed/ofGetHeight(),2)+"%_"+ofToString(i)+".jpg";
//ofSaveImage(vectorOfPixels[i], fileName, OF_IMAGE_QUALITY_BEST);
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
saveImageAnalysis(file_name);
}

View File

@ -9,6 +9,8 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
class IResponseAnalysis : public AbstractAnalysis
{
public:
@ -19,7 +21,9 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -27,8 +31,35 @@ public:
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -1,8 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "RelaxRateAnalysis.h"
#include "ofMain.h"
@ -15,55 +10,186 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
#define TRESHOLD 80
#define MAXBLOBS 15
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 300;
NUM_PHASE = 1;
NUM_RUN = 3;
NUM_SAVE_PER_RUN = 100;
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_relaxrate", NUMBER_RUNS);
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
create_dir();
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_relaxrate", ACQUIRE_TIME);
cout << "ACQUIRE_TIME RelaxRateAnalysis " << acq_run_time << endl;
_treshold = RefractiveIndex::XML.getValue("config:relaxrate:treshold", TRESHOLD);
cout << "TRESHOLD RelaxRateAnalysis " << _treshold << endl;
_maxblobs = RefractiveIndex::XML.getValue("config:relaxrate:maxblobs", MAXBLOBS);
cout << "MAXBLOBS RelaxRateAnalysis " << _maxblobs << endl;
//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
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
//create_dir_allocate_images();
_run_cnt = 0;
_level = 0;
_flip = 1;
_frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
c = 0;
_synth_save_cnt = 0;
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;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
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);
}
void RelaxRateAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<RelaxRateAnalysis> save_callback(*this, &RelaxRateAnalysis::save_cb);
_run_cnt++;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_RUN_DONE = false;
create_dir_allocate_images();
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = 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;
while(!_RUN_DONE)
//for(int i = 0; i < NUM_RUN; i++) {
//_run_cnt = i;
//cout << "RUN NUM = " << i;
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
}
void RelaxRateAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//cout << "IResponseAnalysis::saving synthesis...\n";
if(_state == STATE_STOP) return;
cvContourFinderVect.clear();
for(float i=1;i<_saved_filenames_analysis.size();i++){
if(_state == STATE_STOP) return;
if(image1.loadImage(_saved_filenames_analysis[i])){
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayDiff1, 1);
cvGrayDiff1.threshold(_treshold);
rfiCvContourFinder* cf = new rfiCvContourFinder();
cf->findContours(cvGrayDiff1, 20, (image1.width * image1.height) / 4, _maxblobs, true);
cvContourFinderVect.push_back(cf);
}
}
// _saved_filenames_synthesis has processed all the files in the analysis images folder
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
}
void RelaxRateAnalysis::displayresults()
{
cvContourFinderVectDisplay.clear();
for(int i=1;i<cvContourFinderVect.size();i++){
if(_state == STATE_STOP) return;
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
while(!_image_shown){
Thread::sleep(2);
if(_state == STATE_STOP) return;
//cout << "!_image_shown" << endl;
}
cvContourFinderVectDisplay.push_back(cvContourFinderVect[i]);
_show_image = true;
_image_shown = false;
}
}
// this runs at frame rate = 33 ms for 30 FPS
void RelaxRateAnalysis::draw()
{
@ -71,9 +197,6 @@ void RelaxRateAnalysis::draw()
switch (_state) {
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
if (_frame_cnt < _frame_cnt_max)
{
@ -92,13 +215,12 @@ void RelaxRateAnalysis::draw()
}
} else {
cout << "RELAXRATE RUN COMPLETED" << endl;
//_state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
_frame_cnt++;
cout << "_frame_cnt:" << _frame_cnt << endl;
//cout << "_frame_cnt:" << _frame_cnt << endl;
break;
}
@ -106,40 +228,131 @@ void RelaxRateAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
//cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//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";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
//cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = MIDDLE OF ANIMATION...\n";
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
//cout << "_anim_cnt = " << _anim_cnt << endl;
if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) {
//cout << "ShadowScapesAnalysis STATE_SYNTHESIZING = FADE OUT OF ANIMATION...\n";
//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;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
//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);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
for(int i=0;i<cvContourFinderVectDisplay.size();i++){
cvContourFinderVectDisplay[i]->draw(0,0, ofGetWidth(), ofGetHeight());
}
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
default:
break;
}
}
// this runs at save_cb timer rate = DELTA_T_SAVE
void RelaxRateAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
cout << "RelaxRateAnalysis::saving...\n";
//cout << "c_last... " << c << endl;
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string thisLocation = RefractiveIndex::_location;
string file = _whole_file_path+"/"+file_name;
ofSaveImage(RefractiveIndex::_pixels, file, OF_IMAGE_QUALITY_BEST);
saveImageAnalysis(file_name);
_saved_filenames.push_back(file);
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
}

View File

@ -1,7 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#pragma once
@ -9,6 +5,11 @@
#include "Poco/Timer.h"
#include "rfiCvContourFinder.h"
#include "ofxOpenCv.h"
class RelaxRateAnalysis : public AbstractAnalysis
{
@ -20,7 +21,9 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -29,7 +32,36 @@ protected:
bool _RUN_DONE;
float _flip, _level;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max;
int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt;
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
int _treshold;
int _maxblobs;
bool _show_image, _image_shown;
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;
vector<rfiCvContourFinder*> cvContourFinderVect;
vector<rfiCvContourFinder*> cvContourFinderVectDisplay;
};

View File

@ -1,35 +1,3 @@
/*
- 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 "ShadowScapesAnalysis.h"
#include "ofMain.h"
@ -37,59 +5,235 @@
#include "Poco/Thread.h"
#include "RefractiveIndex.h"
//#include "ofxXmlSettings.h"
#include "ofxOpenCv.h"
using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define STATE_SCAN 0
#define STATE_ANALYSIS 1
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 100;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shadowscapes", NUMBER_RUNS);
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shadowscapes", ACQUIRE_TIME);
cout << "ACQUIRE_TIME ShadowScapesAnalysis " << acq_run_time << endl;
int screenSpan;
if (_dir == V) screenSpan = ofGetHeight();
if (_dir == H) screenSpan = ofGetWidth();
if (_dir == D) screenSpan = ofGetHeight();
_step = (screenSpan/acq_run_time)/(ofGetFrameRate());
// pixel per frame = (pixels / sec) / (frame / sec)
// 40 pixels per second should give us a 20 second scan at 800 pixels wide
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();
_speed = 900.0; // 900.0 is the correct number
_scanLineWidth = 100.0;
_run_cnt = 0;
_save_cnt = 0;
_synth_save_cnt = 0;
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;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
void ShadowScapesAnalysis::acquire()
{
int w;
if (_dir == V) w = ofGetHeight();
if (_dir == H) w = ofGetWidth();
if (_dir == D) w = ofGetHeight();
Timer save_timer(0, DELTA_T_SAVE);
TimerCallback<ShadowScapesAnalysis> save_callback(*this, &ShadowScapesAnalysis::save_cb);
_step = ((w/_speed) * 1000.0) / 500.0;
_run_cnt++;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_line = 0;
_RUN_DONE = false;
create_dir_allocate_images();
save_timer.start(save_callback);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
Timer save_timer(0, DELTA_T_SAVE);
TimerCallback<ShadowScapesAnalysis> save_callback(*this, &ShadowScapesAnalysis::save_cb);
_RUN_DONE = false;
_frame_cnt = 0; _save_cnt = 0;
save_timer.start(save_callback);
while(!_RUN_DONE)
Thread::sleep(3);
save_timer.stop();
}
save_timer.stop();
}
void ShadowScapesAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//cout << "ShadowScapesAnalysis::saving synthesis...\n";
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;
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
cvGrayDiff1.erode();
cvGrayDiff1.contrastStretch();
cvGrayDiff1.blur(5);
cvGrayDiff1.dilate();
/////////////////////////////////// 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";
}
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
_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_synthesis.size();i++){
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;
}
}
}
@ -163,24 +307,22 @@ 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;
//cout << "VERTICAL IS DONE - _line >= (ofGetHeight()+4*_scanLineWidth) is TRUE" << endl;
_RUN_DONE = true;
}
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;
}
@ -189,15 +331,114 @@ void ShadowScapesAnalysis::draw()
case STATE_SYNTHESISING:
{
// cout << "ShadowScapesAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
_state = STATE_DISPLAY_RESULTS;
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//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";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
//cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
// cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
image2.draw(0,0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
@ -211,7 +452,8 @@ void ShadowScapesAnalysis::draw()
void ShadowScapesAnalysis::save_cb(Timer& timer)
{
cout << "ShadowScapesAnalysis::saving...\n";
_save_cnt++;
string file_name;
if(_dir == H) {
@ -225,8 +467,7 @@ void ShadowScapesAnalysis::save_cb(Timer& timer)
if(_dir == D) {
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);
_save_cnt++;
saveImageAnalysis(file_name);
}

View File

@ -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
*/
/* */
#pragma once
@ -36,6 +6,8 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
enum shadow_type {
H, V, D,
};
@ -51,7 +23,9 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -64,7 +38,35 @@ protected:
float _scanLineWidth; // pix per second
float _step;
shadow_type _dir;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -1,8 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "ShapeFromShadingAnalysis.h"
#include "ofMain.h"
@ -15,71 +10,238 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 20
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 300;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
{
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shapefromshading", NUMBER_RUNS);
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
create_dir();
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shapefromshading", ACQUIRE_TIME);
cout << "ACQUIRE_TIME ShapeFromShadingAnalysis " << acq_run_time << endl;
//int acq_run_time = 20; // 20 seconds of acquiring per run
_level = 0;
_flip = 1;
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
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
//create_dir_allocate_images();
_synth_save_cnt = 0;
_run_cnt = 0;
_frame_cnt = 0;
_frame_cnt_max = ofGetFrameRate() * ((DELTA_T_SAVE * NUM_SAVE_PER_RUN) / 1000);
c = 0;
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;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
// cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
// cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
void ShapeFromShadingAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<ShapeFromShadingAnalysis> save_callback(*this, &ShapeFromShadingAnalysis::save_cb);
_run_cnt++;
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
_RUN_DONE = false;
create_dir_allocate_images();
_animation_cnt1 = 0;
_animation_cnt2 = 0;
_animation_cnt3 = 0;
_animation_cnt4 = 0;
_animation_cnt5 = 0;
_animation_cnt6 = 0;
_animation_cnt7 = 0;
_animation_cnt8 = 0;
_animation_cnt9 = 0;
_animation_cnt10 = 0;
_animation_cnt11 = 0;
_animation_cnt12 = 0;
_animation_cnt13 = 0;
_animation_cnt14 = 0;
_animation_cnt15 = 0;
_animation_cnt16 = 0;
_animation_reset = false; // coundn't get this to work - so using seperate counters - shitty!
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
//for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = i;
// _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;
_animation_cnt1 = 0;
_animation_cnt2 = 0;
_animation_cnt3 = 0;
_animation_cnt4 = 0;
_animation_cnt5 = 0;
_animation_cnt6 = 0;
_animation_cnt7 = 0;
_animation_cnt8 = 0;
_animation_cnt9 = 0;
_animation_cnt10 = 0;
_animation_cnt11 = 0;
_animation_cnt12 = 0;
_animation_cnt13 = 0;
_animation_cnt14 = 0;
_animation_cnt15 = 0;
_animation_cnt16 = 0;
_animation_reset = false; // coundn't get this to work - so using seperate counters - shitty!
while(!_RUN_DONE)
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
// }
}
void ShapeFromShadingAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
// 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);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
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";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
_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 ShapeFromShadingAnalysis::displayresults()
{
for(float i=1;i<_saved_filenames_synthesis.size();i++){
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;
}
}
}
// this runs at frame rate = 33 ms for 30 FPS
@ -94,23 +256,10 @@ void ShapeFromShadingAnalysis::draw()
ofEnableAlphaBlending();
int _quarter_frame_cnt_max = _frame_cnt_max/4;
int _half_frame_cnt_max = _frame_cnt_max/2;
int _threequarters_frame_cnt_max = 3*_frame_cnt_max/4;
//TODO: put in CROSS FADES, ETC§E
/*
if (_animation_reset == true)
{
_animation_cnt1 = 0;
_animation_cnt2 = 0;
_animation_cnt3 = 0;
_animation_cnt4 = 0;
}
*/
if(_frame_cnt < _quarter_frame_cnt_max) {
quad = "QUAD1";
@ -200,7 +349,7 @@ void ShapeFromShadingAnalysis::draw()
}
}
@ -250,11 +399,7 @@ void ShapeFromShadingAnalysis::draw()
//ofRect(2.75*ofGetWidth()/4, 0, ofGetWidth()/2, ofGetHeight());
_animation_cnt12++;
}
}
@ -306,7 +451,11 @@ void ShapeFromShadingAnalysis::draw()
}
ofDisableAlphaBlending();
}
} else {
//_state = STATE_SYNTHESISING;
_frame_cnt = 0;
_RUN_DONE = true;
}
_frame_cnt++;
//cout << "_frame_cnt:" << _frame_cnt << endl;
@ -317,13 +466,117 @@ void ShapeFromShadingAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
// cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//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";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
//cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
//_state = STATE_DISPLAY_RESULTS;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
{
// cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
// cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
image2.draw(0,0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
@ -337,14 +590,9 @@ void ShapeFromShadingAnalysis::draw()
// this runs at save_cb timer rate = DELTA_T_SAVE
void ShapeFromShadingAnalysis::save_cb(Timer& timer)
{
//cout << "ShapeFromShadingAnalysis::saving...\n";
_save_cnt++;
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);
_save_cnt++;
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
saveImageAnalysis(file_name);
}

View File

@ -9,6 +9,8 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
class ShapeFromShadingAnalysis : public AbstractAnalysis
{
@ -21,6 +23,7 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -30,7 +33,6 @@ protected:
string quad;
bool _RUN_DONE;
float _flip, _level;
int _run_cnt, _save_cnt;
int _animation_cnt1;
int _animation_cnt2;
int _animation_cnt3;
@ -48,6 +50,36 @@ protected:
int _animation_cnt15;
int _animation_cnt16;
int _animation_reset; // this reset part didn't get working - so using 16 different counters! yay!
float c, _frame_cnt, _frame_cnt_max;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -1,8 +1,3 @@
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
#include "StrobeAnalysis.h"
#include "ofMain.h"
@ -15,22 +10,87 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define NUMBER_RUNS 1
#define ACQUIRE_TIME 30
void StrobeAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 100;
NUM_RUN = 1;
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_strobe", NUMBER_RUNS);
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
_strobe_cnt = 0;
_strobe_cnt_max = 20; // 40 x 500 ms = 20000 ms = 20 seconds run time
_strobe_interval = 1000; //every 0.5seconds = 15 frames
_frame_cnt_max = _strobe_cnt_max * _strobe_interval * ofGetFrameRate()/1000;
int acq_run_time; // 10 seconds of acquiring per run
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_strobe", ACQUIRE_TIME);
cout << "ACQUIRE_TIME StrobeAnalysis " << acq_run_time << endl;
//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 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 = 2000; //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.
//or 20 times, every one second...
_save_cnt_max = _strobe_cnt_max*_strobe_interval/DELTA_T_SAVE;
//create_dir_allocate_images();
_synth_save_cnt = 0;
_run_cnt = 0;
create_dir();
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;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// 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.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
// cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
// cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
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);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@ -38,35 +98,137 @@ void StrobeAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<StrobeAnalysis> save_callback(*this, &StrobeAnalysis::save_cb);
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _strobe_cnt = 0, _synth_save_cnt = 0;
_run_cnt++;
_RUN_DONE = false;
create_dir_allocate_images();
// RUN ROUTINE
for(int i = 0; i < NUM_RUN; i++) {
//for(int i = 0; i < NUM_RUN; i++) {
_run_cnt = i;
_save_cnt = 0;
_frame_cnt = 0;
//_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;
while(!_RUN_DONE)
save_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
save_timer->start(save_callback);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
save_timer->stop();
}
save_timer->stop();
//}
}
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);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
cvGrayDiff1.dilate();
cvGrayDiff1.dilate();
cvGrayDiff1.contrastStretch();
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
string file_name;
file_name = ofToString(_synth_save_cnt, 2)+"_StrobeAnalysis_"+ofToString(_run_cnt,2)+".jpg";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height,OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
_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 StrobeAnalysis::displayresults()
{
for(float i=1;i<_saved_filenames_synthesis.size();i++){
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;
}
}
}
// this runs at frame rate = 33 ms for 30 FPS
void StrobeAnalysis::draw()
{
@ -80,7 +242,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) {
@ -98,13 +260,13 @@ void StrobeAnalysis::draw()
//cout << "frame_cnt % 15: " << _frame_cnt%15 << endl;
//cout << "MAIN STROBE TIME " << endl;
if (_frame_cnt%int(ofGetFrameRate()*_strobe_interval/1000) < (ofGetFrameRate()*_strobe_interval/1000)/2)
if (int(_frame_cnt)%int(ofGetFrameRate()*_strobe_interval/1000) < (ofGetFrameRate()*_strobe_interval/1000)/2)
{
ofSetColor(255, 255, 255);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
_strobe_cnt++;
_strobe_on = 1;
} else if (_frame_cnt%int(ofGetFrameRate()*_strobe_interval/1000) >= (ofGetFrameRate()*_strobe_interval/1000)/2)
} else if (int(_frame_cnt)%int(ofGetFrameRate()*_strobe_interval/1000) >= (ofGetFrameRate()*_strobe_interval/1000)/2)
{
ofSetColor(0, 0, 0);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
@ -114,7 +276,7 @@ void StrobeAnalysis::draw()
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt < _frame_cnt_max) {
aColour.set(255, 255, 255, 255-ofMap(_frame_cnt, 0, _fade_in_frames, 0, 255));
aColour.set(255, 255, 255, 255-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;
@ -122,6 +284,7 @@ void StrobeAnalysis::draw()
ofDisableAlphaBlending();
} else {
//_state = STATE_SYNTHESISING;
_RUN_DONE = true;
}
@ -133,13 +296,117 @@ void StrobeAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
// cout << "StrobeAnalysis = STATE_SYNTHESISING...\n";
// display animation of something while the synthesis in on-going...
ofEnableAlphaBlending();
ofSetRectMode(OF_RECTMODE_CENTER);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
if(_anim_cnt < _anim_cnt_max){
ofColor aColour;
int rectSizeW = ofGetWidth()/4;
int rectSizeH = ofGetHeight()/4;
int _fade_in_frames = _anim_cnt_max/2;
int c_anim = 10;
int fade;
//ofRotate(ofMap(_anim_cnt/2.0, 0, _anim_cnt_max, 0, 360));
if (_anim_cnt < _fade_in_frames) {
// cout << "StrobeAnalysis STATE_SYNTHESIZING = FADING IN ANIMATION...\n";
fade = ofMap(_anim_cnt, 0, _fade_in_frames, 0, 255);
for (int i=0; i <= 15; i++){
c_anim = 0+17*i;
aColour.set(c_anim, c_anim, c_anim, fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
if (_anim_cnt >= _fade_in_frames && _anim_cnt <= (_anim_cnt_max-_fade_in_frames)){
for (int i=0; i <= 15; i++){
c_anim = 255;
aColour.set(c_anim, c_anim, c_anim, 255);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
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;
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
// cout << "fade down = " << fade << endl;
for (int i=0; i <= 15; i++){
c_anim = (17*i);
aColour.set(c_anim, c_anim, c_anim, 255-fade);
ofSetColor(aColour);
ofRect(0, 0, rectSizeW+10*i, rectSizeH+10*i);
ofRect(0, 0, rectSizeW-10*i, rectSizeH-10*i);
}
}
_anim_cnt++;
} else {
_RUN_DONE = true;
//_state = STATE_DISPLAY_RESULTS;
_anim_cnt=0;
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
ofDisableAlphaBlending();
break;
}
case STATE_DISPLAY_RESULTS:
{
// cout << "STATE_DISPLAY_RESULTS...\n" << endl;
if (_frame_cnt > 2)
{
_image_shown = true;
_frame_cnt=0;
}
_frame_cnt++;
if (_show_image)
{
// cout << "_show_image...\n" << endl;
ofEnableAlphaBlending();
ofSetColor(255, 255, 255);
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
image2.draw(0,0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending();
}
// display results of the synthesis
_RUN_DONE = true;
break;
}
@ -152,17 +419,9 @@ void StrobeAnalysis::draw()
// this runs at save_cb timer rate = DELTA_T_SAVE
void StrobeAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
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);
_save_cnt++;
cout << "_save_cnt" << _save_cnt << endl;
cout << "_save_cnt_max" << _save_cnt_max << endl;
//TODO: something fucked here with my calc of _save_cnt_max - new structure should fix it?
//if(_save_cnt >= _save_cnt_max-10) {
// _RUN_DONE = true;
//}
saveImageAnalysis(file_name);
}

View File

@ -9,6 +9,8 @@
#include "Poco/Timer.h"
#include "ofxOpenCv.h"
class StrobeAnalysis : public AbstractAnalysis
{
@ -20,7 +22,9 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void synthesise();
void displayresults();
void draw();
void save_cb(Poco::Timer& timer);
@ -28,10 +32,40 @@ public:
protected:
bool _RUN_DONE;
int _strobe_cnt, _run_cnt, _strobe_cnt_max;
int _save_cnt;
int _strobe_cnt, _strobe_cnt_max;
int _frame_cnt, _frame_cnt_max, _save_cnt_max ;
int _strobe_interval;
bool _strobe_on;
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 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;
//this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage;
};

View File

@ -0,0 +1,211 @@
#include "rfiCvContourFinder.h"
//--------------------------------------------------------------------------------
static bool sort_carea_compare( const CvSeq* a, const CvSeq* b) {
// use opencv to calc size, then sort based on size
float areaa = fabs(cvContourArea(a, CV_WHOLE_SEQ));
float areab = fabs(cvContourArea(b, CV_WHOLE_SEQ));
//return 0;
return (areaa > areab);
}
//--------------------------------------------------------------------------------
rfiCvContourFinder::rfiCvContourFinder() {
_width = 0;
_height = 0;
myMoments = (CvMoments*)malloc( sizeof(CvMoments) );
reset();
}
//--------------------------------------------------------------------------------
rfiCvContourFinder::~rfiCvContourFinder() {
free( myMoments );
}
//--------------------------------------------------------------------------------
void rfiCvContourFinder::reset() {
cvSeqBlobs.clear();
blobs.clear();
nBlobs = 0;
}
//--------------------------------------------------------------------------------
int rfiCvContourFinder::findContours( ofxCvGrayscaleImage& input,
int minArea,
int maxArea,
int nConsidered,
bool bFindHoles,
bool bUseApproximation) {
// get width/height disregarding ROI
IplImage* ipltemp = input.getCvImage();
_width = ipltemp->width;
_height = ipltemp->height;
reset();
// opencv will clober the image it detects contours on, so we want to
// copy it into a copy before we detect contours. That copy is allocated
// if necessary (necessary = (a) not allocated or (b) wrong size)
// so be careful if you pass in different sized images to "findContours"
// there is a performance penalty, but we think there is not a memory leak
// to worry about better to create mutiple contour finders for different
// sizes, ie, if you are finding contours in a 640x480 image but also a
// 320x240 image better to make two rfiCvContourFinder objects then to use
// one, because you will get penalized less.
if( inputCopy.getWidth() == 0 ) {
inputCopy.setUseTexture(false);
inputCopy.allocate( _width, _height );
} else if( inputCopy.getWidth() != _width || inputCopy.getHeight() != _height ) {
// reallocate to new size
inputCopy.clear();
inputCopy.setUseTexture(false);
inputCopy.allocate( _width, _height );
}
inputCopy.setROI( input.getROI() );
inputCopy = input;
CvSeq* contour_list = NULL;
contour_storage = cvCreateMemStorage( 1000 );
storage = cvCreateMemStorage( 1000 );
CvContourRetrievalMode retrieve_mode
= (bFindHoles) ? CV_RETR_LIST : CV_RETR_EXTERNAL;
cvFindContours( inputCopy.getCvImage(), contour_storage, &contour_list,
sizeof(CvContour), retrieve_mode, bUseApproximation ? CV_CHAIN_APPROX_SIMPLE : CV_CHAIN_APPROX_NONE );
CvSeq* contour_ptr = contour_list;
// put the contours from the linked list, into an array for sorting
while( (contour_ptr != NULL) ) {
float area = fabs( cvContourArea(contour_ptr, CV_WHOLE_SEQ) );
if( (area > minArea) && (area < maxArea) ) {
cvSeqBlobs.push_back(contour_ptr);
}
contour_ptr = contour_ptr->h_next;
}
// sort the pointers based on size
if( cvSeqBlobs.size() > 1 ) {
sort( cvSeqBlobs.begin(), cvSeqBlobs.end(), sort_carea_compare );
}
// now, we have cvSeqBlobs.size() contours, sorted by size in the array
// cvSeqBlobs let's get the data out and into our structures that we like
for( int i = 0; i < MIN(nConsidered, (int)cvSeqBlobs.size()); i++ ) {
blobs.push_back( ofxCvBlob() );
float area = cvContourArea( cvSeqBlobs[i], CV_WHOLE_SEQ );
CvRect rect = cvBoundingRect( cvSeqBlobs[i], 0 );
cvMoments( cvSeqBlobs[i], myMoments );
blobs[i].area = fabs(area);
blobs[i].hole = area < 0 ? true : false;
blobs[i].length = cvArcLength(cvSeqBlobs[i]);
blobs[i].boundingRect.x = rect.x;
blobs[i].boundingRect.y = rect.y;
blobs[i].boundingRect.width = rect.width;
blobs[i].boundingRect.height = rect.height;
blobs[i].centroid.x = (myMoments->m10 / myMoments->m00);
blobs[i].centroid.y = (myMoments->m01 / myMoments->m00);
// get the points for the blob:
CvPoint pt;
CvSeqReader reader;
cvStartReadSeq( cvSeqBlobs[i], &reader, 0 );
for( int j=0; j < cvSeqBlobs[i]->total; j++ ) {
CV_READ_SEQ_ELEM( pt, reader );
blobs[i].pts.push_back( ofPoint((float)pt.x, (float)pt.y) );
}
blobs[i].nPts = blobs[i].pts.size();
}
nBlobs = blobs.size();
// Free the storage memory.
// Warning: do this inside this function otherwise a strange memory leak
if( contour_storage != NULL ) { cvReleaseMemStorage(&contour_storage); }
if( storage != NULL ) { cvReleaseMemStorage(&storage); }
return nBlobs;
}
//--------------------------------------------------------------------------------
void rfiCvContourFinder::draw( float x, float y, float w, float h ) {
float scalex = 0.0f;
float scaley = 0.0f;
if( _width != 0 ) { scalex = w/_width; } else { scalex = 1.0f; }
if( _height != 0 ) { scaley = h/_height; } else { scaley = 1.0f; }
if(bAnchorIsPct){
x -= anchor.x * w;
y -= anchor.y * h;
}else{
x -= anchor.x;
y -= anchor.y;
}
ofPushStyle();
glPushMatrix();
glTranslatef( x, y, 0.0 );
glScalef( scalex, scaley, 0.0 );
ofSetHexColor(0xFFFFFF);
for( int i=0; i<(int)blobs.size(); i++ ) {
ofNoFill();
ofBeginShape();
for( int j=0; j<blobs[i].nPts; j++ ) {
ofVertex( blobs[i].pts[j].x, blobs[i].pts[j].y );
}
ofEndShape();
}
glPopMatrix();
ofPopStyle();
}
//----------------------------------------------------------
void rfiCvContourFinder::draw(const ofPoint & point){
draw(point.x, point.y);
}
//----------------------------------------------------------
void rfiCvContourFinder::draw(const ofRectangle & rect){
draw(rect.x, rect.y, rect.width, rect.height);
}
//--------------------------------------------------------------------------------
void rfiCvContourFinder::setAnchorPercent( float xPct, float yPct ){
anchor.x = xPct;
anchor.y = yPct;
bAnchorIsPct = true;
}
//--------------------------------------------------------------------------------
void rfiCvContourFinder::setAnchorPoint( int x, int y ){
anchor.x = x;
anchor.y = y;
bAnchorIsPct = false;
}
//--------------------------------------------------------------------------------
void rfiCvContourFinder::resetAnchor(){
anchor.set(0,0);
bAnchorIsPct = false;
}

View File

@ -0,0 +1,73 @@
/*
* rfiCvContourFinder.h
*
* Finds white blobs in binary images and identifies
* centroid, bounding box, area, length and polygonal contour
* The result is placed in a vector of ofxCvBlob objects.
*
*/
#ifndef RFI_CV_CONTOUR_FINDER
#define RFI_CV_CONTOUR_FINDER
#include "ofxCvConstants.h"
#include "ofxCvBlob.h"
#include "ofxCvGrayscaleImage.h"
#include <algorithm>
class rfiCvContourFinder : public ofBaseDraws {
public:
vector<ofxCvBlob> blobs;
int nBlobs; // DEPRECATED: use blobs.size() instead
rfiCvContourFinder();
virtual ~rfiCvContourFinder();
virtual float getWidth() { return _width; }; //set after first findContours call
virtual float getHeight() { return _height; }; //set after first findContours call
virtual int findContours( ofxCvGrayscaleImage& input,
int minArea, int maxArea,
int nConsidered, bool bFindHoles,
bool bUseApproximation = true);
// approximation = don't do points for all points
// of the contour, if the contour runs
// along a straight line, for example...
virtual void draw() { draw(0,0, _width, _height); };
virtual void draw( float x, float y ) { draw(x,y, _width, _height); };
virtual void draw( float x, float y, float w, float h );
virtual void draw(const ofPoint & point);
virtual void draw(const ofRectangle & rect);
virtual void setAnchorPercent(float xPct, float yPct);
virtual void setAnchorPoint(int x, int y);
virtual void resetAnchor();
//virtual ofxCvBlob getBlob(int num);
protected:
int _width;
int _height;
ofxCvGrayscaleImage inputCopy;
CvMemStorage* contour_storage;
CvMemStorage* storage;
CvMoments* myMoments;
vector<CvSeq*> cvSeqBlobs; //these will become blobs
ofPoint anchor;
bool bAnchorIsPct;
virtual void reset();
};
#endif