> sequence: acquire -> synthesise -> display results
This commit is contained in:
dviid 2012-02-15 08:43:43 +01:00
parent 65c625ad1e
commit 7109c65d63
21 changed files with 462 additions and 350 deletions

View File

@ -11,7 +11,6 @@
#include "RefractiveIndex.h"
#include "IResponseAnalysis.h"
#include "StrobeAnalysis.h"
#include "ShadowScapesAnalysis.h"
#include "ColorMultiAnalysis.h"
#include "ColorSingleAnalysis.h"
@ -98,7 +97,6 @@ void RefractiveIndex::setup()
// setup analysis
_analysisVector.push_back(new ShadowScapesAnalysis());
_analysisVector.push_back(new StrobeAnalysis());
_analysisVector.push_back(new IResponseAnalysis());
_analysisVector.push_back(new ColorMultiAnalysis());
_analysisVector.push_back(new CamFrameRateAnalysis());

View File

@ -33,8 +33,13 @@
#include "AbstractAnalysis.h"
#include "RefractiveIndex.h"
// this is the main threaded loop for a given analysis
void AbstractAnalysis::do_synthesize() {
synthesize();
_state = STATE_ACQUIRING;
acquire();
_state = STATE_SYNTHESISING;
synthesise();
_state = STATE_DISPLAY_RESULTS;
ofNotifyEvent(_synthesize_cb, _name);
}

View File

@ -11,6 +11,9 @@
#define ANALYSIS_PATH "analysis/"
#define STATE_ACQUIRING 0x1111
#define STATE_SYNTHESISING 0x2222
#define STATE_DISPLAY_RESULTS 0x3333
#define STATE_STOP 0xDEADBEEF
class AbstractAnalysis {
@ -21,6 +24,7 @@ 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
@ -30,9 +34,12 @@ protected:
virtual void create_dir();
// the runnable function in the thread
virtual void synthesize() = 0;
// this means that this function needs to be overwritten by children that inherit this class
// acquire images - all the children (see - do_synthesize)
virtual void acquire() = 0;
// analysis + synthesize images - all the children (see - do_synthesize)
virtual void synthesise() = 0;
public:
string _name;
@ -42,8 +49,10 @@ public:
protected:
int _cam_w, _cam_h;
int _state;
string _whole_file_path;
vector<string> _saved_filenames;
int _state;
float DELTA_T_SAVE;
int NUM_PHASE;

View File

@ -31,7 +31,7 @@ void CamFrameRateAnalysis::setup(int camWidth, int camHeight)
}
void CamFrameRateAnalysis::synthesize()
void CamFrameRateAnalysis::acquire()
{
Timer* save_timer;
@ -57,9 +57,18 @@ void CamFrameRateAnalysis::synthesize()
}
}
void CamFrameRateAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void CamFrameRateAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
@ -81,6 +90,26 @@ void CamFrameRateAnalysis::draw()
cout<<_frame_cnt<<endl;
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
@ -94,8 +123,11 @@ void CamFrameRateAnalysis::save_cb(Timer& timer)
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);
ofSaveImage(RefractiveIndex::_pixels, file, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file);
if(_save_cnt >= NUM_SAVE_PER_RUN)
_RUN_DONE = true;

View File

@ -19,7 +19,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);

View File

@ -31,7 +31,7 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
}
void CamNoiseAnalysis::synthesize()
void CamNoiseAnalysis::acquire()
{
Timer* save_timer;
@ -57,10 +57,20 @@ void CamNoiseAnalysis::synthesize()
}
}
void CamNoiseAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void CamNoiseAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
@ -80,11 +90,28 @@ void CamNoiseAnalysis::draw()
ofSetColor(someColor);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
@ -96,9 +123,12 @@ void CamNoiseAnalysis::save_cb(Timer& timer)
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;

View File

@ -18,7 +18,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);

View File

@ -56,7 +56,7 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
c = 0;
}
void ColorMultiAnalysis::synthesize()
void ColorMultiAnalysis::acquire()
{
Timer* save_timer;
@ -83,9 +83,18 @@ void ColorMultiAnalysis::synthesize()
}
void ColorMultiAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
void ColorMultiAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
if (_frame_cnt < _frame_cnt_max) {
ofColor aColor;
aColor.setHsb(c, 255, 255);
@ -95,6 +104,27 @@ void ColorMultiAnalysis::draw()
c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max);
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
@ -110,9 +140,12 @@ void ColorMultiAnalysis::save_cb(Timer& timer)
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;
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;
}

View File

@ -13,7 +13,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);

View File

@ -32,7 +32,7 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
}
void ColorSingleAnalysis::synthesize()
void ColorSingleAnalysis::acquire()
{
Timer* save_timer;
@ -58,9 +58,18 @@ void ColorSingleAnalysis::synthesize()
}
}
void ColorSingleAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
void ColorSingleAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
float one_third_of_frame_count_max=_frame_cnt_max/3;
if (_frame_cnt < one_third_of_frame_count_max){
r=255.0;
@ -86,6 +95,26 @@ void ColorSingleAnalysis::draw()
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
@ -98,8 +127,12 @@ void ColorSingleAnalysis::save_cb(Timer& timer)
cout << "ColorSingleAnalysis::saving...\n";
string file_name =ofToString(_frame_cnt,2)+"_"+ofToString((int)r,2)+"_"+ofToString((int)g,2)+"_"+ofToString((int)b,2)+"_"+ofToString(_run_cnt,2)+".jpg";
string file = _whole_file_path+"/"+file_name;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(file);
cout<<_whole_file_path+"/"+file_name<<endl;
if(_save_cnt >= NUM_SAVE_PER_RUN)

View File

@ -18,7 +18,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);

View File

@ -30,7 +30,7 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
}
void DiffNoiseAnalysis::synthesize()
void DiffNoiseAnalysis::acquire()
{
Timer* save_timer;
@ -56,9 +56,18 @@ void DiffNoiseAnalysis::synthesize()
}
}
void DiffNoiseAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void DiffNoiseAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
@ -74,6 +83,25 @@ void DiffNoiseAnalysis::draw()
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
@ -97,8 +125,12 @@ void DiffNoiseAnalysis::save_cb(Timer& timer)
// 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)

View File

@ -18,7 +18,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);

View File

@ -29,7 +29,7 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
}
void IResponseAnalysis::synthesize()
void IResponseAnalysis::acquire()
{
Timer* save_timer;
@ -55,10 +55,20 @@ void IResponseAnalysis::synthesize()
}
}
void IResponseAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void IResponseAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
@ -69,8 +79,28 @@ void IResponseAnalysis::draw()
ofRect(0, 0, ofGetWidth(), ofGetHeight());
c = 255.0 * (_frame_cnt_max - _frame_cnt)/(_frame_cnt_max);
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
@ -91,8 +121,12 @@ void IResponseAnalysis::save_cb(Timer& timer)
// 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);
if(_save_cnt >= NUM_SAVE_PER_RUN)
_RUN_DONE = true;

View File

@ -18,7 +18,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);

View File

@ -30,7 +30,7 @@ void LatencyTestAnalysis::setup(int camWidth, int camHeight)
}
void LatencyTestAnalysis::synthesize()
void LatencyTestAnalysis::acquire()
{
Timer* save_timer;
@ -56,9 +56,19 @@ void LatencyTestAnalysis::synthesize()
}
}
void LatencyTestAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// this runs at frame rate = 33 ms for 30 FPS
void LatencyTestAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
/// *** TODO *** ///
// still need to deal with latency frames here - i.e.: there are frames
/// *** TODO *** ///
@ -89,6 +99,25 @@ void LatencyTestAnalysis::draw()
}
_frame_cnt++;
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}
@ -109,8 +138,12 @@ void LatencyTestAnalysis::save_cb(Timer& timer)
// 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);
if(_save_cnt >= NUM_SAVE_PER_RUN)
_RUN_DONE = true;

View File

@ -18,7 +18,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void save_cb(Poco::Timer& timer);

View File

@ -50,7 +50,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
_speed = 300;
}
void ShadowScapesAnalysis::synthesize()
void ShadowScapesAnalysis::acquire()
{
int w;
if(_dir == H) w = ofGetWidth();
@ -79,10 +79,19 @@ void ShadowScapesAnalysis::synthesize()
}
void ShadowScapesAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
}
// the animation draw - and the output draw
void ShadowScapesAnalysis::draw()
{
switch (_state) {
case STATE_ACQUIRING:
{
static int _pos;
if(_state == STATE_ANALYSIS) {
@ -104,6 +113,27 @@ void ShadowScapesAnalysis::draw()
}
break;
}
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
break;
}
default:
break;
}
}

View File

@ -50,7 +50,8 @@ public:
public:
void setup(int camWidth, int camHeight);
void synthesize();
void acquire();
void synthesise();
void draw();
void scan_cb(Poco::Timer& timer);

View File

@ -1,108 +0,0 @@
/*
- 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 "StrobeAnalysis.h"
#include "ofMain.h"
#include "Poco/Timer.h"
#include "Poco/Thread.h"
#include "RefractiveIndex.h"
using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
#define STATE_STROBE 0
#define STATE_ANALYSIS 1
void StrobeAnalysis::setup(int camWidth, int camHeight)
{
create_dir();
}
void StrobeAnalysis::synthesize()
{
Timer strobe_timer(0, 70);
TimerCallback<StrobeAnalysis> strobe_callback(*this, &StrobeAnalysis::strobe_cb);
_state = STATE_STROBE;
_darkness = true;
_strobe_cnt = 0;
strobe_timer.start(strobe_callback);
while(_state != STATE_ANALYSIS)
Thread::sleep(5);
strobe_timer.stop();
// do analysis here
/*
while(_state != STATE_STOP)
Thread::sleep(100);
*/
}
void StrobeAnalysis::draw()
{
if(_state == STATE_ANALYSIS) {
ofSetColor(0, 200, 0);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
return;
}
if(_darkness) {
ofSetColor(0, 0, 0);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
} else {
ofSetColor(255, 255, 255);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
}
}
void StrobeAnalysis::strobe_cb(Timer& timer)
{
cout << "IResponseAnalysis::saving...\n";
_strobe_cnt++;
_darkness = !_darkness;
if(_strobe_cnt >= 20) {
_state = STATE_ANALYSIS;
}
}

View File

@ -1,57 +0,0 @@
/*
- 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
#include "AbstractAnalysis.h"
#include "Poco/Timer.h"
class StrobeAnalysis : public AbstractAnalysis
{
public:
StrobeAnalysis(): AbstractAnalysis("STROBE"){;}
virtual ~StrobeAnalysis(){;}
public:
void setup(int camWidth, int camHeight);
void synthesize();
void draw();
void strobe_cb(Poco::Timer& timer);
protected:
int _strobe_cnt;
bool _darkness;
};