Compare commits

...

13 Commits

Author SHA1 Message Date
gauthiier
42d048ca04 ... 2023-09-08 08:20:39 +02:00
dviid
5c5581f16e mid-backed commit - master is dead 2012-02-21 18:06:58 +01:00
dviid
b5cebe9304 mid-commit AbstractAnalysis::saveimage 2012-02-20 14:10:20 +01:00
Tom Schofield
3649211943 merged with tom 2012-02-20 13:00:05 +00:00
Tom Schofield
bc19757de2 merge local master 2012-02-20 12:37:44 +00:00
Tom Schofield
d798394793 final check and commit before merge with master 2012-02-20 12:33:13 +00:00
Tom Schofield
bf8c630add make vector of meshes static since we only ever want to display one at a time 2012-02-20 12:00:18 +00:00
Tom Schofield
935d6414b5 tidy up 2012-02-20 11:33:26 +00:00
Tom Schofield
6b401b8424 added synthesise and display results to all analysis classes 2012-02-20 11:25:55 +00:00
Tom Schofield
3fd26c1eb4 fixed bug in color single 2012-02-19 18:51:25 +00:00
Tom Schofield
c53eb2eb6c corrected file confusion AGAIN 2012-02-19 18:25:37 +00:00
Tom Schofield
1d5d6abbde corrected file confusion 2012-02-19 18:17:45 +00:00
Tom Schofield
71e3a9a1db added image loading and display results stuff- changes all commented in code 2012-02-19 16:42:55 +00:00
23 changed files with 1201 additions and 124 deletions

10
README
View File

@ -1,10 +0,0 @@
WARNING: WORK IN PROGRESS...
configuring OpenFrameworks
-----------------
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};
(3) Press Play!

2
README.md Normal file
View File

@ -0,0 +1,2 @@
<img src="https://davidgauthier.info/rfi/img-resize/rfi3.jpg" width="100%">
<img src="https://davidgauthier.info/rfi/img-resize/rfi4.jpg" width="100%">

View File

@ -97,29 +97,29 @@ void RefractiveIndex::setup()
//TODO: whichever one of these is first - it always runs twice ?
_analysisVector.push_back(new ShadowScapesAnalysis(V));
_analysisVector.push_back(new ShadowScapesAnalysis(H));
_analysisVector.push_back(new ShadowScapesAnalysis(D));
//_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 IResponseAnalysis());
_analysisVector.push_back(new ShapeFromShadingAnalysis());
//_analysisVector.push_back(new ShapeFromShadingAnalysis());
_analysisVector.push_back(new StrobeAnalysis());
//_analysisVector.push_back(new StrobeAnalysis());
_analysisVector.push_back(new CamNoiseAnalysis());
//_analysisVector.push_back(new CamNoiseAnalysis());
_analysisVector.push_back(new ColorSingleAnalysis());
//_analysisVector.push_back(new ColorSingleAnalysis());
_analysisVector.push_back(new ColorMultiAnalysis());
//_analysisVector.push_back(new ColorMultiAnalysis());
_analysisVector.push_back(new DiffNoiseAnalysis());
//_analysisVector.push_back(new DiffNoiseAnalysis());
_currentAnalysisIndx = 0;
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx);
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
_state = ISTATE_START;
@ -209,6 +209,7 @@ void RefractiveIndex::setup_camera()
ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber";
return;
}
_vidGrabber.setUseTexture(false);
_vidGrabber.listDevices();
_vidGrabber.setVerbose(true);
_vid_stream_open = true;

View File

@ -34,6 +34,9 @@
#include "RefractiveIndex.h"
#include "ofxFileHelper.h"
vector<ofMesh> AbstractAnalysis::meshes;
// this is the main threaded loop for a given analysis
void AbstractAnalysis::do_synthesize() {
_state = STATE_ACQUIRING;
@ -41,6 +44,7 @@ void AbstractAnalysis::do_synthesize() {
_state = STATE_SYNTHESISING;
synthesise();
_state = STATE_DISPLAY_RESULTS;
display_results();
ofNotifyEvent(_synthesize_cb, _name);
}
@ -68,8 +72,8 @@ void AbstractAnalysis::create_dir()
}
ofxFileHelper fileHelper;
_whole_file_path = ANALYSIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime ;
//cout << "_whole_file_path = " << _whole_file_path << endl;
_whole_file_path = ofToDataPath("") + ANALYSIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime ;
cout << "_whole_file_path = " << _whole_file_path << endl;
if(!fileHelper.doesDirectoryExist(_whole_file_path)){
fileHelper.makeDirectory(ANALYSIS_PATH);
@ -80,4 +84,253 @@ void AbstractAnalysis::create_dir()
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
}
ofPixels AbstractAnalysis::calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison){
//zScale is the mapping factor from pixel difference to shift on the zPlane
int zScale=200;
ofPixels imagePixels1 = image1.getPixelsRef();
ofPixels imagePixels2 = image2.getPixelsRef();
ofPixels difference;
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
unsigned char * thesePixels = new unsigned char[ imagePixels1.getWidth()*imagePixels1.getHeight()*3];
//where are we in the image pixel array
int x=0;
int y=0;
//for each pixel...
for(int i=0;i<imagePixels1.size();i+=3){
//get the colour of each image at this x y location - we will use these colours for comparison according to the below criteria
ofColor colourImage1 = imagePixels1.getColor(x, y);
ofColor colourImage2 = imagePixels2.getColor(x, y);
//COMPARE THIS PIXEL'S VALUES with the first image in the sequence
int thisDiff;
//compare Red
if (whichComparison==1) {
thisDiff=ofMap((colourImage1.r-colourImage2.r),-255,255,0,zScale);
}
//compare blue
if (whichComparison==2) {
thisDiff=ofMap((colourImage1.g-colourImage2.g),-255,255,0,zScale);
}
//compare green
if (whichComparison==3) {
thisDiff=ofMap((colourImage1.b-colourImage2.b),-255,255,0,zScale);
}
//compare hue
if (whichComparison==4) {
thisDiff=ofMap((colourImage1.getHue()-colourImage2.getHue()),-255,255,0,zScale);
}
//compare brightness
if (whichComparison==5) {
thisDiff=ofMap((colourImage1.getBrightness()-colourImage2.getBrightness()),-255,255,0,zScale);
}
thesePixels[i]=thisDiff;
thesePixels[i+1]=thisDiff;
thesePixels[i+2]=thisDiff;
x++;
//new line
if(x>imagePixels1.getWidth()){
x=0;
y++;
}
}
difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
return difference;
}
ofPixels AbstractAnalysis::calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison, int colourValue){
//zScale is the mapping factor from pixel difference to shift on the zPlane
int zScale=200;
ofPixels imagePixels1 = image1.getPixelsRef();
ofPixels imagePixels2 = image2.getPixelsRef();
ofPixels difference;
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
unsigned char * thesePixels = new unsigned char[ imagePixels1.getWidth()*imagePixels1.getHeight()*3];
//where are we in the image pixel array
int x=0;
int y=0;
//for each pixel...
//for(int i=0;i<imagePixels1.size();i+=3){
for(int i=0;i<20;i+=3){
//get the colour of each image at this x y location - we will use these colours for comparison according to the below criteria
ofColor colourImage1 = imagePixels1.getColor(x, y);
ofColor colourImage2 = imagePixels2.getColor(x, y);
//COMPARE THIS PIXEL'S VALUES with the first image in the sequence
int thisDiff;
//compare Red
if (whichComparison==1) {
thisDiff=ofMap((colourImage1.r-colourImage2.r),-255,255,0,zScale);
}
//compare blue
if (whichComparison==2) {
thisDiff=ofMap((colourImage1.g-colourImage2.g),-255,255,0,zScale);
}
//compare green
if (whichComparison==3) {
thisDiff=ofMap((colourImage1.b-colourImage2.b),-255,255,0,zScale);
}
//compare hue
if (whichComparison==4) {
thisDiff=ofMap((colourImage1.getHue()-colourImage2.getHue()),-255,255,0,zScale);
}
//compare brightness
if (whichComparison==5) {
thisDiff=ofMap((colourImage1.getBrightness()-colourImage2.getBrightness()),-255,255,0,zScale);
}
thesePixels[i]=thisDiff;
thesePixels[i+1]=thisDiff;
thesePixels[i+2]=thisDiff;
x++;
//new line
if(x>imagePixels1.getWidth()){
x=0;
y++;
}
}
difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
return difference;
}
void AbstractAnalysis::setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh){
int x=0;
int y=0;
//get rid of all previous vectors and colours - uncomment if re-setting the mesh on the fly - ie live rather than saving it first
//someMesh->clear();
unsigned char * thesePixels =currentSecondImage.getPixels();
for(int i=0;i<somePixels.size();i+=3){
someMesh->addVertex(ofVec3f(x,y,- somePixels.getColor(x, y).getBrightness() ));
// add colour from current second image of two
someMesh->addColor( currentSecondImage.getColor(x, y) );
x++;
if(x>somePixels.getWidth()){
x=0;
y++;
}
}
}
vector<string>AbstractAnalysis:: getListOfImageFilePaths(string location, string whichAnalysis){
string path = ofToDataPath("")+"debug_analysis/"+location+"/"+whichAnalysis;
//ofxDirList dirList;
ofDirectory dirList;
int numDirs = dirList.listDir(path);
vector<string>directoryNames;
//get the last folder alphabetically - this should probably change to do something fancy with date to find most recent but don't want to code that until we are sure
string dirName=dirList.getName(numDirs-1);
const char *results=dirName.c_str();
ofFile file=ofFile(path+"/"+dirName);
vector<string>fileNamesToReturn;
// get
if(file.isDirectory()){
dirList.listDir(path+"/"+dirName);
//if there are no files, exit here
if(dirList.size()==0){
//if it's empty return an error warning
fileNamesToReturn.push_back("NO FILE HERE!");
cout<<"NO FILE HERE!";
return fileNamesToReturn;
}
for (int i=0; i<dirList.size(); i++) {
string fname=dirList.getName(i);
const char *results=fname.c_str();
//full path is what actually gets written into the vector
string fullPath=path+"/"+dirName+"/"+fname;
fileNamesToReturn.push_back(fullPath);
}
}
else{
cout<<"WARNING, DIRECTORY NOT FOUND";
fileNamesToReturn.push_back("NO FILE HERE!");
}
return fileNamesToReturn;
}
int AbstractAnalysis::getRecordedValueFromFileName(string str){
//split filename by underscore - there HAS to be a quicker way of doing things - its ONE LINE in java :(
char * cstr, *p;
vector<char *>tokens;
//string str ("Please split this phrase into tokens");
//make char pointer array
cstr = new char [str.size()+1];
//copy string to char pointer array
strcpy (cstr, str.c_str());
//tokenise char p array and put first results into pointer?
p=strtok (cstr,"_");
while (p!=NULL)
{
p=strtok(NULL,"_");
//push tokenised char into vector
tokens.push_back(p);
}
delete[] cstr;
char *p1;
//cstr = new char [str.size()+1];
//strcpy (cstr, str.c_str());
p1=strtok (tokens[tokens.size()-2],".");
return ofToInt(p1);
}
void AbstractAnalysis::saveimage(string filename)
{
if(RefractiveIndex::_pixels.isAllocated()) {
string fname = _whole_file_path + "/" + filename;
cout << "saving - " << fname << endl;
ofSaveImage(RefractiveIndex::_pixels, fname, OF_IMAGE_QUALITY_BEST);
_saved_filenames.push_back(fname);
} else {
ofLog(OF_LOG_ERROR) << "RefractiveIndex::_pixels NOT allocated...";
}
}

View File

@ -16,6 +16,12 @@
#define STATE_DISPLAY_RESULTS 0x3333
#define STATE_STOP 0xDEADBEEF
#define COMPARE_RED 1
#define COMPARE_BLUE 2
#define COMPARE_GREEN 3
#define COMPARE_HUE 4
#define COMPARE_BRIGHTNESS 5
class AbstractAnalysis {
public:
@ -33,6 +39,7 @@ public:
protected:
virtual void create_dir();
virtual void saveimage(string filename);
// acquire images - all the children (see - do_synthesize)
virtual void acquire() = 0;
@ -40,6 +47,26 @@ protected:
// analysis + synthesize images - all the children (see - do_synthesize)
virtual void synthesise() = 0;
//added tom s 19/2 function runs a call back exactly like acquire.
virtual void display_results() = 0;
//returns ofPixels which contain the color differences between the two images. Is overloaded to include comparison with values written in to file names for some analyses
virtual ofPixels calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison);
virtual ofPixels calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison, int colourValue);
//uses the returned pixels from make3DZmap to make a mesh of points whose Z positions are set by the brightness values in ofPixels - ofPixels is being used as a convenient container for a bunch of z coordinates
virtual void setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh);
//HELPER FUNCTIONS
//this is purely for debug/viewing purposes and loads old images from middlesborough test
virtual vector<string> getListOfImageFilePaths(string location, string whichAnalysis);
//splits up the filename and returns the recorded value eg brightness
//EG FILENAME : DIFF_NOISE_7_85.7322.jpg RETURNS : 85.7322
virtual int getRecordedValueFromFileName(string str);
static vector<ofMesh>meshes;
public:
string _name;
@ -59,5 +86,12 @@ protected:
int NUM_RUN;
int NUM_SAVE_PER_RUN;
//added Tom S 19/2/12
//each mesh in the vector is a seperate 3D point cloud which is coloured with pixel data and shifted in the z plane according to the specified type of colour difference eg red value or hue
//make this vector were static
//how fast to move from one mesh to the next
float speed;
//the index (inside the vector of meshes) of the current mesh being displayed
float whichMesh;
friend class AnalysisAdaptor;
};

View File

@ -59,9 +59,68 @@ void CamNoiseAnalysis::acquire()
void CamNoiseAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
//if you want to see what this looks like with real data ignore the new filenames and load teh old ones.
bool debug=true;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
cout<<"setting mesh"<<endl;
int _recorded_hue_value=getRecordedValueFromFileName(_saved_filenames[i]);
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_HUE,_recorded_hue_value), image2, &meshes[index]);
index++;
}
}
}
void CamNoiseAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<CamNoiseAnalysis> display_results_callback(*this, &CamNoiseAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=300;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}
// this runs at frame rate = 33 ms for 30 FPS
@ -136,6 +195,27 @@ void CamNoiseAnalysis::draw()
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
cout<<whichMesh<<" size of meshes "<<meshes.size()<<endl;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -153,15 +233,15 @@ 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);
saveimage(file_name);
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
}
void CamNoiseAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -20,15 +20,17 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max,_save_cnt_max ;
float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max;
};

View File

@ -45,10 +45,10 @@ using Poco::Thread;
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 150; // the right number is about 300
DELTA_T_SAVE = 100;//150; // the right number is about 300
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 300;
NUM_SAVE_PER_RUN = 100;//;
create_dir();
_frame_cnt = 0;
@ -86,10 +86,64 @@ void ColorMultiAnalysis::acquire()
void ColorMultiAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[0]) && image2.loadImage(_saved_filenames[i+1])){
cout<<"setting mesh"<<endl;
meshes.push_back(ofMesh());
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_HUE), image2, &meshes[index]);
index++;
}
}
}
void ColorMultiAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<ColorMultiAnalysis> display_results_callback(*this, &ColorMultiAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, DELTA_T_SAVE); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=500;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}
void ColorMultiAnalysis::draw()
{
@ -154,12 +208,31 @@ void ColorMultiAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -174,19 +247,20 @@ void ColorMultiAnalysis::draw()
// this runs at save_cb timer rate = DELTA_T_SAVE
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";
saveimage(file_name);
// cout<<_whole_file_path<<endl;
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
_save_cnt++;
//if(_save_cnt >= NUM_SAVE_PER_RUN){
// _RUN_DONE = true;
//}
}
void ColorMultiAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -15,13 +15,15 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt, _fade_cnt;
float c, _frame_cnt, _frame_cnt_max;
float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max;
};

View File

@ -18,7 +18,7 @@ using Poco::Thread;
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 300;
DELTA_T_SAVE = 100;//300;
NUM_PHASE = 1;
NUM_RUN = 1;
NUM_SAVE_PER_RUN = 100;
@ -64,9 +64,72 @@ void ColorSingleAnalysis::acquire()
void ColorSingleAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
if(i<_saved_filenames.size()/3){
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_RED), image2, &meshes[index]);
}
if(i>=_saved_filenames.size()/3 && i<2* _saved_filenames.size()/3){
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_GREEN), image2, &meshes[index]);
}
if(i>= 2* _saved_filenames.size()/3 && i<_saved_filenames.size()){
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_BLUE), image2, &meshes[index]);
}
index++;
}
}
}
void ColorSingleAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<ColorSingleAnalysis> display_results_callback(*this, &ColorSingleAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=500;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}
void ColorSingleAnalysis::draw()
{
@ -142,6 +205,25 @@ void ColorSingleAnalysis::draw()
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -154,17 +236,22 @@ void ColorSingleAnalysis::draw()
// this runs at save_cb timer rate = DELTA_T_SAVE
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";
saveimage(file_name);
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//cout<<_whole_file_path+"/"+file_name<<endl;
_save_cnt++;
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
}
void ColorSingleAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -20,14 +20,16 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
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, _frame_cnt, _frame_cnt_max , _results_cnt, _results_cnt_max;
};

View File

@ -59,11 +59,68 @@ void DiffNoiseAnalysis::acquire()
void DiffNoiseAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
cout<<"setting mesh"<<endl;
int _recorded_brightness_value=getRecordedValueFromFileName(_saved_filenames[i]);
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_HUE,_recorded_brightness_value), image2, &meshes[index]);
index++;
}
}
}
void DiffNoiseAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<DiffNoiseAnalysis> display_results_callback(*this, &DiffNoiseAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=300;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}// this runs at frame rate = 33 ms for 30 FPS
// this runs at frame rate = 33 ms for 30 FPS
void DiffNoiseAnalysis::draw()
{
switch (_state) {
@ -154,6 +211,28 @@ void DiffNoiseAnalysis::draw()
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
cout<<whichMesh<<" size of meshes "<<meshes.size()<<endl;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -178,21 +257,21 @@ void DiffNoiseAnalysis::save_cb(Timer& timer)
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);
saveimage(file_name);
}
_save_cnt++;
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
}
void DiffNoiseAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -20,14 +20,16 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt, _fade_cnt;
float c, _frame_cnt, _frame_cnt_max;
float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max;
};

View File

@ -15,6 +15,8 @@ using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
void IResponseAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 100;
@ -55,11 +57,70 @@ void IResponseAnalysis::acquire()
}
}
void IResponseAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
cout<<"setting mesh"<<endl;
int _recorded_brightness_value=getRecordedValueFromFileName(_saved_filenames[i]);
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_BRIGHTNESS,_recorded_brightness_value), image2, &meshes[index]);
index++;
}
}
}
void IResponseAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<IResponseAnalysis> display_results_callback(*this, &IResponseAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=300;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}
// this runs at frame rate = 33 ms for 30 FPS
@ -90,6 +151,7 @@ void IResponseAnalysis::draw()
case STATE_SYNTHESISING:
{
// display animation of something while the synthesis in on-going...
break;
}
@ -97,6 +159,26 @@ void IResponseAnalysis::draw()
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
cout<<whichMesh<<" size of meshes "<<meshes.size()<<endl;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -110,19 +192,21 @@ void IResponseAnalysis::draw()
// this runs at save_cb timer rate = DELTA_T_SAVE
void IResponseAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
cout << "IResponseAnalysis::saving...\n";
//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;
saveimage(file_name);
//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);
_save_cnt++;
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
}
void IResponseAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -20,15 +20,17 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
bool _RUN_DONE;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max;
float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max;
};

View File

@ -18,7 +18,7 @@ using Poco::Thread;
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
{
DELTA_T_SAVE = 300;
DELTA_T_SAVE = 130;
NUM_PHASE = 1;
NUM_RUN = 3;
NUM_SAVE_PER_RUN = 100;
@ -61,9 +61,73 @@ void RelaxRateAnalysis::acquire()
void RelaxRateAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
/*
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
cout<<"setting mesh"<<endl;
int _recorded_brightness_value=getRecordedValueFromFileName(_saved_filenames[i]);
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_BRIGHTNESS,_recorded_brightness_value), image2, &meshes[index]);
index++;
}
}
*/
}
void RelaxRateAnalysis::display_results(){
/*
Timer* display_results_timer;
TimerCallback<RelaxRateAnalysis> display_results_callback(*this, &RelaxRateAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=300;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
*/
}
// this runs at frame rate = 33 ms for 30 FPS
void RelaxRateAnalysis::draw()
{
@ -111,7 +175,30 @@ void RelaxRateAnalysis::draw()
case STATE_DISPLAY_RESULTS:
{
/*
// display results of the synthesis
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
cout<<whichMesh<<" size of meshes "<<meshes.size()<<endl;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
*/
break;
}
@ -127,19 +214,23 @@ void RelaxRateAnalysis::draw()
// this runs at save_cb timer rate = DELTA_T_SAVE
void RelaxRateAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
cout << "RelaxRateAnalysis::saving...\n";
//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;
saveimage(file_name);
ofSaveImage(RefractiveIndex::_pixels, file, OF_IMAGE_QUALITY_BEST);
_save_cnt++;
_saved_filenames.push_back(file);
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
}
void RelaxRateAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -21,15 +21,17 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
bool _RUN_DONE;
float _flip, _level;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max;
float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max;
};

View File

@ -89,10 +89,78 @@ void ShadowScapesAnalysis::acquire()
void ShadowScapesAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
string fnamei = _saved_filenames[i];
string fnameii = _saved_filenames[i + 1];
bool l1 = image1.loadImage(_saved_filenames[i]);
bool l2 = image2.loadImage(_saved_filenames[i+1]);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
cout<<"setting mesh"<<endl;
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_BRIGHTNESS), image2, &meshes[index]);
index++;
}
image1.clear();
image2.clear();
}
}
void ShadowScapesAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<ShadowScapesAnalysis> display_results_callback(*this, &ShadowScapesAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=300;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}
// the animation draw - and the output draw
void ShadowScapesAnalysis::draw()
{
@ -191,13 +259,33 @@ void ShadowScapesAnalysis::draw()
{
// display animation of something while the synthesis in on-going...
_state = STATE_DISPLAY_RESULTS;
break;
}
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
cout<<whichMesh<<" size of meshes "<<meshes.size()<<endl;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -211,6 +299,14 @@ void ShadowScapesAnalysis::draw()
void ShadowScapesAnalysis::save_cb(Timer& timer)
{
RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera
if (RefractiveIndex::_vidGrabber.isFrameNew())
{
RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
}
cout << "ShadowScapesAnalysis::saving...\n";
string file_name;
@ -226,7 +322,15 @@ void ShadowScapesAnalysis::save_cb(Timer& timer)
file_name = ofToString(_save_cnt, 2)+"_D_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg";
}
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
saveimage(file_name);
_save_cnt++;
}
void ShadowScapesAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -52,9 +52,11 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
@ -65,6 +67,6 @@ protected:
float _step;
shadow_type _dir;
int _run_cnt, _save_cnt;
float c, _frame_cnt, _frame_cnt_max;
float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max;
};

View File

@ -77,9 +77,69 @@ void ShapeFromShadingAnalysis::acquire()
}
}
void ShapeFromShadingAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
cout<<"setting mesh"<<endl;
int _recorded_brightness_value=getRecordedValueFromFileName(_saved_filenames[i]);
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_BRIGHTNESS,_recorded_brightness_value), image2, &meshes[index]);
index++;
}
}
}
void ShapeFromShadingAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<ShapeFromShadingAnalysis> display_results_callback(*this, &ShapeFromShadingAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=300;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}
// this runs at frame rate = 33 ms for 30 FPS
@ -323,6 +383,26 @@ void ShapeFromShadingAnalysis::draw()
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
cout<<whichMesh<<" size of meshes "<<meshes.size()<<endl;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -341,10 +421,19 @@ void ShapeFromShadingAnalysis::save_cb(Timer& timer)
string file_name = ofToString(_save_cnt,2)+"_"+ quad +"_"+ofToString(_run_cnt,2)+".jpg";
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
saveimage(file_name);
_save_cnt++;
//if(_save_cnt >= NUM_SAVE_PER_RUN)
// _RUN_DONE = true;
}
void ShapeFromShadingAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -21,9 +21,11 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
@ -48,6 +50,6 @@ 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;
float c, _frame_cnt, _frame_cnt_max, _results_cnt, _results_cnt_max;
};

View File

@ -64,7 +64,66 @@ void StrobeAnalysis::acquire()
void StrobeAnalysis::synthesise()
{
// _saved_filenames has all the file names of all the saved images
//incrementer to whichMesh
speed=0.2;
//whichMesh is the index in the vector of meshes
whichMesh=0;
int index=0;
float iterator=1;
bool debug=false;
if(debug){
_saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);
//hack to limit number of meshes.
if(_saved_filenames.size()>100){
iterator= _saved_filenames.size() /100;
}
}
//clear vector so we don't add to it on successive runs
meshes.clear();
for(float i=0;i<_saved_filenames.size()-1;i+=iterator){
ofImage image1;
ofImage image2;
//there is a known issue with using loadImage inside classes in other directories. the fix is to call setUseTExture(false)
image1.setUseTexture(false);
image2.setUseTexture(false);
//some of the textures are not loading correctly so only make mesh if both the images load
if(image1.loadImage(_saved_filenames[i]) && image2.loadImage(_saved_filenames[i+1])){
meshes.push_back(ofMesh());
cout<<"setting mesh"<<endl;
int _recorded_brightness_value=getRecordedValueFromFileName(_saved_filenames[i]);
setMeshFromPixels( calculateListOfZValues(image1,image2, COMPARE_BRIGHTNESS,_recorded_brightness_value), image2, &meshes[index]);
index++;
}
}
}
void StrobeAnalysis::display_results(){
Timer* display_results_timer;
TimerCallback<StrobeAnalysis> display_results_callback(*this, &StrobeAnalysis::display_results_cb);
// display results of the synthesis
display_results_timer = new Timer(0, 20); // timing interval for saving files
display_results_timer->start(display_results_callback);
_RUN_DONE = false;
_results_cnt=0;
_results_cnt_max=300;
while(!_RUN_DONE)
Thread::sleep(3);
display_results_timer->stop();
}
// this runs at frame rate = 33 ms for 30 FPS
@ -139,6 +198,26 @@ void StrobeAnalysis::draw()
case STATE_DISPLAY_RESULTS:
{
// display results of the synthesis
int imageWidth=640;
int imageHeight =480;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateY(_results_cnt*0.3);
//ofRotateX(90);
//ofRotateZ(whichMesh);
ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2),-400;
ofTranslate((ofGetWidth()/2)-(imageWidth/2),0,0 );
meshes[whichMesh].drawVertices();
ofPopMatrix();
whichMesh+=speed;
cout<<whichMesh<<" size of meshes "<<meshes.size()<<endl;
if(whichMesh>meshes.size() -1 || whichMesh<0){
speed*=-1;
whichMesh+=speed;
}
break;
}
@ -153,7 +232,8 @@ void StrobeAnalysis::draw()
void StrobeAnalysis::save_cb(Timer& timer)
{
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(_strobe_on) +"_"+ofToString(_run_cnt,2)+".jpg";
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path+"/"+file_name, OF_IMAGE_QUALITY_BEST);
saveimage(file_name);
_save_cnt++;
cout << "_save_cnt" << _save_cnt << endl;
@ -166,3 +246,12 @@ void StrobeAnalysis::save_cb(Timer& timer)
//}
}
void StrobeAnalysis::display_results_cb(Timer& timer){
_results_cnt++;
if (_results_cnt>_results_cnt_max) {
_RUN_DONE=true;
}
}

View File

@ -21,9 +21,11 @@ public:
void setup(int camWidth, int camHeight);
void acquire();
void synthesise();
void display_results();
void draw();
void save_cb(Poco::Timer& timer);
void display_results_cb(Poco::Timer& timer);
protected:
@ -32,6 +34,8 @@ protected:
int _save_cnt;
int _frame_cnt, _frame_cnt_max, _save_cnt_max ;
float _results_cnt, _results_cnt_max;
int _strobe_interval;
bool _strobe_on;
};