6 Commits

Author SHA1 Message Date
Tom Schofield 8b9c3eaebc added triangular mesh and scaling for z axis. 2012-05-04 16:48:17 +01:00
Tom Schofield a9c8a56850 now displays images after saving them out and also fixed maths booboo with analysis 2012-04-13 11:16:51 +01:00
Tom Schofield 706eb9354d just sorting out my gitignore file 2012-04-12 10:24:18 +01:00
Tom Schofield 21791b9769 added zmapper from inverse square law saves from main app draw() 2012-04-12 10:21:37 +01:00
dviid e29accb9ce fixed file ordering 2012-04-09 13:35:16 +02:00
dviid 7d7ec3606e mode <drawing, analysing> + drawing mode file chooser
make sure you add the config.refindx to your environment
2012-04-06 18:46:38 +02:00
18 changed files with 452 additions and 232 deletions
+6
View File
@@ -1,2 +1,8 @@
src/.DS_Store src/.DS_Store
.DS_Store
Project.xcconfig
bin/
openFrameworks-Info.plist
opencvExample.xcodeproj/
config.refindx
-45
View File
@@ -1,45 +0,0 @@
<!-- 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>
+66 -3
View File
@@ -19,7 +19,7 @@
#define CAMERA_ACQU_WIDTH 640 #define CAMERA_ACQU_WIDTH 640
#define CAMERA_ACQU_HEIGHT 480 #define CAMERA_ACQU_HEIGHT 480
#define LOCATION "MIDDLESBOROUGH" #define LOCATION "MANCHESTER"
#define ISTATE_UNDEF 0xEEEE #define ISTATE_UNDEF 0xEEEE
#define ISTATE_START 0xAAAA #define ISTATE_START 0xAAAA
@@ -27,8 +27,10 @@
#define ISTATE_TRANSITION 0xCCCC #define ISTATE_TRANSITION 0xCCCC
#define ISTATE_END 0xDDDD #define ISTATE_END 0xDDDD
int _state = ISTATE_UNDEF; int _state = ISTATE_UNDEF;
int RefractiveIndex::_mode;
ofPixels RefractiveIndex::_pixels; ofPixels RefractiveIndex::_pixels;
ofVideoGrabber RefractiveIndex::_vidGrabber; ofVideoGrabber RefractiveIndex::_vidGrabber;
int RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, RefractiveIndex::_vid_id; int RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, RefractiveIndex::_vid_id;
@@ -40,6 +42,9 @@ ofxXmlSettings RefractiveIndex::XML;
void RefractiveIndex::setup() void RefractiveIndex::setup()
{ {
camDist=1000;
//camera.setOrientation(ofVec3f(1,-1,1));
bool save_config = false; bool save_config = false;
cout << "Loading configuration..." << endl; cout << "Loading configuration..." << endl;
@@ -50,6 +55,10 @@ void RefractiveIndex::setup()
XML.loadFile("config.refindx"); XML.loadFile("config.refindx");
} }
// <mode>
string m = XML.getValue("config:mode", "analysing");
_mode = (m == "analysing" ? MODE_ANALYSING : (m == "drawing" ? MODE_DRAWING : MODE_ANALYSING));
// <camera> // <camera>
_vid_id = XML.getValue("config:camera:id", CAMERA_ID); _vid_id = XML.getValue("config:camera:id", CAMERA_ID);
cout << "_vid_id: " << _vid_id << endl; cout << "_vid_id: " << _vid_id << endl;
@@ -82,8 +91,10 @@ void RefractiveIndex::setup()
cout << "* cam width = " << _vid_w << endl; cout << "* cam width = " << _vid_w << endl;
cout << "* cam height = " << _vid_h << endl; cout << "* cam height = " << _vid_h << endl;
if(_mode == MODE_ANALYSING) {
_vid_stream_open = false; _vid_stream_open = false;
setup_camera(); setup_camera();
}
cout << "RRRRRREADY!" << endl; cout << "RRRRRREADY!" << endl;
@@ -102,7 +113,6 @@ void RefractiveIndex::setup()
_analysisVector.push_back(new RelaxRateAnalysis()); _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());
@@ -125,6 +135,7 @@ void RefractiveIndex::setup()
_currentAnalysis = NULL; _currentAnalysis = NULL;
_state = ISTATE_UNDEF; _state = ISTATE_UNDEF;
} }
void RefractiveIndex::analysis_cb(string & analysis) void RefractiveIndex::analysis_cb(string & analysis)
@@ -140,6 +151,16 @@ void RefractiveIndex::start_analysis()
_analysisAdapator = new AnalysisAdaptor(_currentAnalysis); _analysisAdapator = new AnalysisAdaptor(_currentAnalysis);
_currentAnalysis->setup(_vid_w, _vid_h); _currentAnalysis->setup(_vid_w, _vid_h);
_analysisAdapator->start(); _analysisAdapator->start();
//allocate fbo for HD
fbo.allocate(1920,1080);
// fbo.allocate( _currentAnalysis->_mesh_size_multiplier *_vid_w,_currentAnalysis->_mesh_size_multiplier * _vid_h);
camera.setPosition(fbo.getWidth()/2, fbo.getHeight()/2,_currentAnalysis->_mesh_size_multiplier *500);
_meshRotation=0;
} }
void RefractiveIndex::stop_analysis() void RefractiveIndex::stop_analysis()
@@ -173,9 +194,13 @@ void RefractiveIndex::state_analysis()
break; break;
case ISTATE_STOP: case ISTATE_STOP:
stop_analysis(); // blocking stop_analysis(); // blocking
if(_mode == MODE_DRAWING)
_state = ISTATE_UNDEF;
else
_state = ISTATE_TRANSITION; _state = ISTATE_TRANSITION;
break; break;
case ISTATE_END: case ISTATE_END:
if(_mode == MODE_ANALYSING)
stop_camera(); stop_camera();
::exit(1); ::exit(1);
break; break;
@@ -199,8 +224,46 @@ void RefractiveIndex::draw()
// black // black
ofBackground(0, 0, 0); ofBackground(0, 0, 0);
if(_currentAnalysis) if(_currentAnalysis){
_currentAnalysis->draw(); _currentAnalysis->draw();
if(_currentAnalysis->meshIsComplete){
fbo.begin();
glShadeModel(GL_SMOOTH);
ofClear(0,0,0);
camera.begin();
ofSetColor(0, 0, 0);
//this is a hack, I don't know how to colour the fbo with black pixels so I'm drawing a massive black rectangle in the background
ofPushMatrix();
ofTranslate(0, 0,-500);
ofRect(-fbo.getWidth(), -fbo.getHeight(), fbo.getWidth()*3, fbo.getHeight()*3);
ofPopMatrix();
ofSetColor(255);
float xDiff= (fbo.getWidth()- (_currentAnalysis->_mesh_size_multiplier *_vid_w))/2;
float yDiff= (fbo.getHeight()- (_currentAnalysis->_mesh_size_multiplier *_vid_h))/2;
ofTranslate(xDiff,yDiff,-_currentAnalysis->zPlaneAverage );
_currentAnalysis->aMesh.draw();
camera.end();
fbo.end();
ofPixels pixels;
fbo.readToPixels(pixels);
ofSaveImage(pixels,_currentAnalysis->meshFileName, OF_IMAGE_QUALITY_BEST);
//saving jpgs doesn't work - pngs only!
}
}
} }
void RefractiveIndex::setup_camera() void RefractiveIndex::setup_camera()
+14 -1
View File
@@ -10,6 +10,11 @@
#include "ofxOpenCv.h" #include "ofxOpenCv.h"
#include "ofxXmlSettings.h" #include "ofxXmlSettings.h"
#include "ofxOpenCv.h"
#define MODE_DRAWING 0xEEFF
#define MODE_ANALYSING 0xFFEE
class RefractiveIndex : public ofBaseApp class RefractiveIndex : public ofBaseApp
{ {
@@ -51,10 +56,15 @@ protected:
AnalysisAdaptor* _analysisAdapator; AnalysisAdaptor* _analysisAdapator;
vector<AbstractAnalysis*> _analysisVector; vector<AbstractAnalysis*> _analysisVector;
float _meshRotation;
float camDist;
ofEasyCam cam;
public: public:
// acquisition // acquisition
static ofPixels _pixels; static ofPixels _pixels;
static ofVideoGrabber _vidGrabber; static ofVideoGrabber _vidGrabber;
static int _mode;
vector<string> videoSourceList; vector<string> videoSourceList;
static int _vid_w, _vid_h, _vid_id; static int _vid_w, _vid_h, _vid_id;
static bool _vid_stream_open; static bool _vid_stream_open;
@@ -63,5 +73,8 @@ public:
// this should be in xml // this should be in xml
static string _location; static string _location;
static ofxXmlSettings XML; // made this static so we can access RUN_NUM in the analyses static ofxXmlSettings XML; // made this static so we can access RUN_NUM in the analyses
ofCamera camera;
ofPixels keepOnScreen;
ofFbo fbo;
ofLight light;
}; };
+74 -5
View File
@@ -3,10 +3,34 @@
#include "AbstractAnalysis.h" #include "AbstractAnalysis.h"
#include "RefractiveIndex.h" #include "RefractiveIndex.h"
#include "ofxFileHelper.h" #include "ofxFileHelper.h"
#include "ofSystemUtils.h"
void AbstractAnalysis::setup(int camWidth, int camHeight) {
meshIsComplete=false;
imageForContourAvailable=false;
_cam_w = camWidth; _cam_h = camHeight;
if(RefractiveIndex::_mode == MODE_DRAWING) {
ofFileDialogResult r = ofSystemLoadDialog("choooose da folda", true);
if(!r.bSuccess) {
ofSystemAlertDialog("OOOOPS.... ERROR...");
return;
}
_whole_file_path_analysis = r.filePath;
_whole_file_path_synthesis = r.filePath + "/darwings";
}
}
// this is the main threaded loop for a given analysis // this is the main threaded loop for a given analysis
void AbstractAnalysis::do_synthesize() { void AbstractAnalysis::do_synthesize() {
switch(RefractiveIndex::_mode)
{
case MODE_ANALYSING:
{
for(int i = 0; i < NUM_RUN; i++) { for(int i = 0; i < NUM_RUN; i++) {
cout << "NUM_RUN: " << i << endl; cout << "NUM_RUN: " << i << endl;
@@ -14,10 +38,6 @@ void AbstractAnalysis::do_synthesize() {
_saved_filenames_analysis.clear(); _saved_filenames_analysis.clear();
_saved_filenames_synthesis.clear(); _saved_filenames_synthesis.clear();
if(_state == STATE_STOP) goto exit;
_state = STATE_ALLOCATE;
allocate();
if(_state == STATE_STOP) goto exit;
_state = STATE_ACQUIRING; _state = STATE_ACQUIRING;
acquire(); acquire();
if(_state == STATE_STOP) goto exit; if(_state == STATE_STOP) goto exit;
@@ -26,13 +46,33 @@ void AbstractAnalysis::do_synthesize() {
if(_state == STATE_STOP) goto exit; if(_state == STATE_STOP) goto exit;
_state = STATE_DISPLAY_RESULTS; _state = STATE_DISPLAY_RESULTS;
displayresults(); displayresults();
_state = STATE_CLEANUP;
cleanup(); cleanup();
} }
}
case MODE_DRAWING:
{
ofxFileHelper fileHelperDrawing;
if(!fileHelperDrawing.doesDirectoryExist(_whole_file_path_synthesis)){
fileHelperDrawing.makeDirectory(_whole_file_path_synthesis);
}
read_dir_create_list(_whole_file_path_analysis);
_state = STATE_SYNTHESISING;
synthesise();
if(_state == STATE_STOP) goto exit;
_state = STATE_DISPLAY_RESULTS;
displayresults();
cleanup();
}
}
exit: exit:
cleanup(); cleanup();
ofNotifyEvent(_synthesize_cb, _name); ofNotifyEvent(_synthesize_cb, _name);
} }
void AbstractAnalysis::create_dir_allocate_images() void AbstractAnalysis::create_dir_allocate_images()
@@ -117,10 +157,38 @@ void AbstractAnalysis::create_dir_allocate_images()
myGrayImage1.setUseTexture(false); myGrayImage1.setUseTexture(false);
myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE); myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE);
//////////////////////////////END ALLOCATE IMAGES ////////////////////////////////////////////////// //////////////////////////////END ALLOCATE IMAGES //////////////////////////////////////////////////
} }
bool cmp_file(string f0, string f1)
{
int v0 = atoi(f0.substr(0, f0.find("_")).c_str());
int v1 = atoi(f1.substr(0, f1.find("_")).c_str());
return v0 < v1;
}
void AbstractAnalysis::read_dir_create_list(string folder_path)
{
File dir(folder_path);
if(dir.exists() && dir.isDirectory()) {
vector<string> list;
dir.list(list);
std::sort(list.begin(), list.end(), cmp_file);
for(int i = 0; i < list.size(); i++) {
string filepath = folder_path + "/" + list[i];
_saved_filenames_analysis.push_back(filepath);
cout << list[i] << endl;
}
}
}
void AbstractAnalysis::saveImageAnalysis(string filename) void AbstractAnalysis::saveImageAnalysis(string filename)
{ {
@@ -186,5 +254,6 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+filename); _saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+filename);
} }
+19 -8
View File
@@ -13,13 +13,10 @@
#define ANALYSIS_PATH "analysis/" #define ANALYSIS_PATH "analysis/"
#define SYNTHESIS_PATH "synthesis/" #define SYNTHESIS_PATH "synthesis/"
#define STATE_ALLOCATE 0x0010
#define STATE_CLEANUP 0x0001
#define STATE_ACQUIRING 0x1111 #define STATE_ACQUIRING 0x1111
#define STATE_SYNTHESISING 0x2222 #define STATE_SYNTHESISING 0x2222
#define STATE_DISPLAY_RESULTS 0x3333 #define STATE_DISPLAY_RESULTS 0x3333
#define STATE_STOP 0xDEADBEEF #define STATE_STOP 0xDEADBEEF
#define STATE_DEF 0x0000
class AbstractAnalysis { class AbstractAnalysis {
@@ -28,7 +25,7 @@ public:
virtual ~AbstractAnalysis(){;} virtual ~AbstractAnalysis(){;}
// generic function to set up the camera // generic function to set up the camera
virtual void setup(int camWidth, int camHeight){_cam_w = camWidth; _cam_h = camHeight;} virtual void setup(int camWidth, int camHeight);
// this is the main threaded loop for a given analysis // this is the main threaded loop for a given analysis
void do_synthesize(); void do_synthesize();
@@ -40,6 +37,8 @@ protected:
virtual void create_dir_allocate_images(); virtual void create_dir_allocate_images();
virtual void read_dir_create_list(string folder_path);
virtual void saveImageAnalysis(string filename); virtual void saveImageAnalysis(string filename);
virtual void saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType); virtual void saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType);
@@ -52,18 +51,30 @@ protected:
// display the results from disk // display the results from disk
virtual void displayresults() = 0; virtual void displayresults() = 0;
// allocate all images // display the results from disk
virtual void allocate() {;}
// deallocate all images
virtual void cleanup() {;} virtual void cleanup() {;}
public: public:
string _name; string _name;
string _draw_directory;
// event // event
ofEvent<string> _synthesize_cb; ofEvent<string> _synthesize_cb;
bool meshIsComplete;
bool imageForContourAvailable;
ofMesh aMesh;
string meshFileName;
//difference between our image size and the size of the fbo
float widthScaleFactor;
float heightScaleFactor;
ofImage contourImage;
ofPixels meshPix;
ofPixels publicColorImage;
float zPlaneAverage;
//added Tom 1/5/12 defines the stretch we make to the mesh to make it fit HD proportions
float _mesh_size_multiplier;
protected: protected:
int _cam_w, _cam_h; int _cam_w, _cam_h;
+2
View File
@@ -15,6 +15,8 @@ using Poco::Thread;
void CamNoiseAnalysis::setup(int camWidth, int camHeight) void CamNoiseAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_camnoise", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_camnoise", NUMBER_RUNS);
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl; cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
+2
View File
@@ -14,6 +14,8 @@ using Poco::Thread;
void ColorMultiAnalysis::setup(int camWidth, int camHeight) void ColorMultiAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colormulti", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colormulti", NUMBER_RUNS);
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl; cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
+2
View File
@@ -15,6 +15,8 @@ using Poco::Thread;
void ColorSingleAnalysis::setup(int camWidth, int camHeight) void ColorSingleAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colorsingle", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colorsingle", NUMBER_RUNS);
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl; cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
+2
View File
@@ -15,6 +15,8 @@ using Poco::Thread;
void DiffNoiseAnalysis::setup(int camWidth, int camHeight) void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl; cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
+211 -34
View File
@@ -15,6 +15,8 @@ using Poco::Thread;
void IResponseAnalysis::setup(int camWidth, int camHeight) void IResponseAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_iresponse", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_iresponse", NUMBER_RUNS);
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl; cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
@@ -23,6 +25,12 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_iresponse", ACQUIRE_TIME); acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_iresponse", ACQUIRE_TIME);
cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl; cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl;
//flag for main sketch
meshIsComplete=false;
_gotFirstImage=false;
_mesh_size_multiplier=4;
//int acq_run_time = 20; // 20 seconds of acquiring per run //int acq_run_time = 20; // 20 seconds of acquiring per run
@@ -123,6 +131,8 @@ void IResponseAnalysis::acquire()
void IResponseAnalysis::synthesise() void IResponseAnalysis::synthesise()
{ {
cout<<"SYNTHESISING IRESPONSE";
//cout << "IResponseAnalysis::saving synthesis...\n"; //cout << "IResponseAnalysis::saving synthesis...\n";
if(_state == STATE_STOP) return; if(_state == STATE_STOP) return;
@@ -145,50 +155,48 @@ void IResponseAnalysis::synthesise()
if(image5.loadImage(_saved_filenames_analysis[i+1])){ if(image5.loadImage(_saved_filenames_analysis[i+1])){
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
if(!_gotFirstImage){
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
_background=image1;
_gotFirstImage=true;
}
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height); //subtract background begin///////////////
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1); ofPixels imagePixels1 = image1.getPixelsRef();
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1); ofPixels imagePixels2 = image5.getPixelsRef();
ofPixels backgroundPixels = _background.getPixelsRef();
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1); for(int i=0;i<imagePixels1.size();i++){
cvGrayDiff1.erode();
cvGrayDiff1.contrastStretch();
//cvGrayDiff1.blur(5);
//cvGrayDiff1.dilate();
//cvGrayDiff1.contrastStretch();
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER //////////////////////////////// unsigned char val=imagePixels1[i];
string file_name; // cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
if(imagePixels1[i]-backgroundPixels[i]>0){
imagePixels1[i]-=backgroundPixels[i];
}
else{
imagePixels1[i]=0;
}
file_name = ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".jpg"; }
//update the images with their new background subtracted selves
image1.setFromPixels(imagePixels1);
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ----> //flag the main app that we aren't read yet
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST); meshIsComplete=false;
//make a mesh - this mesh will be drawn in the main app
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1,image1, aMesh);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ----> //meshPix=make3DZmap(image1, image5, _background);
//ofImage image; //with jpgs this was refusing to save out
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE); meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".png";
_saved_filenames_synthesis.push_back(meshFileName);
//*** 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);
//flag that we are finished
meshIsComplete=true;
_synth_save_cnt++; _synth_save_cnt++;
} }
} }
} }
@@ -405,3 +413,172 @@ void IResponseAnalysis::save_cb(Timer& timer)
saveImageAnalysis(file_name); saveImageAnalysis(file_name);
} }
void IResponseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
int x=0;
int y=0;
//get rid of all previous vectors and colours
mesh.clear();
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
ofColor meshColour=ofColor(255,0,0);
int chooseColour=1 ;
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
float zPlaneAverage=0;
for(int i=0;i<sPixels.size();i++){
zPlaneAverage+=sPixels[i];
}
if (sPixels.size()!=0) {
zPlaneAverage/=sPixels.size();
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
}
else{
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
}
if(chooseColour==1){
for(int i=0;i<sPixels.size();i++){
mesh.addColor( currentSecondImage.getColor(x, y+1) );
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
mesh.addColor( currentSecondImage.getColor(x, y) );
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
mesh.addColor( currentSecondImage.getColor(x+1, y+1) );
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
mesh.addColor( currentSecondImage.getColor(x+1, y+1) );
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
mesh.addColor( currentSecondImage.getColor(x, y) );
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
mesh.addColor( currentSecondImage.getColor(x+1, y) );
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
x++;
if(x>=currentSecondImage.getWidth()-1){
x=0;
y++;
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
if(y>=479){
break;
}
}
}
}
/*else{
for(int i=0;i<somePixels.getWidth()*(somePixels.getHeight()-1);i++){
ofVec3f U;
ofVec3f V;
//tri 1
U =ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- somePixels.getColor(x, y).getBrightness() ).operator- ( ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- somePixels.getColor(x, y).getBrightness() ) );
V =ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- somePixels.getColor(x+1, y+1).getBrightness() ).operator-(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- somePixels.getColor(x, y).getBrightness() ));
ofVec3f normal;
float mult=5.2;
normal = ofVec3f( (U.y*V.z)-(U.z-V.y) , (U.z*V.x)-(U.x*V.z) , (U.x*V.y)-(U.y*V.x) );
mesh.addColor(meshColour);
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- mult*(1+somePixels.getColor(x, y+1).getBrightness() ) ));
mesh.addColor(meshColour);
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- mult*(1+somePixels.getColor(x, y).getBrightness() ) ));
mesh.addColor(meshColour);
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- mult*(1+somePixels.getColor(x+1, y+1).getBrightness()) ));
mesh.addNormal(normal);
//tri 2
U =ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*y,- somePixels.getColor(x, y).getBrightness() ).operator-(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- somePixels.getColor(x+1, y+1).getBrightness() ) );
V =ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- somePixels.getColor(x+1, y).getBrightness() ).operator-(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- somePixels.getColor(x+1, y+1).getBrightness() ) );
normal = ofVec3f( (U.y*V.z)-(U.z-V.y) , (U.z*V.x)-(U.x*V.z) , (U.x*V.y)-(U.y*V.x) );
mesh.addColor(meshColour);
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- mult*(1+somePixels.getColor(x+1, y+1).getBrightness()) ));
// mesh.addColor( ofColor(255,10,10) );
mesh.addColor(meshColour);
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*y,- mult*(1+somePixels.getColor(x, y).getBrightness() ) ));
mesh.addColor(meshColour);
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,-mult*(1+ somePixels.getColor(x+1, y).getBrightness()) ));
mesh.addNormal(normal);
x++;
if(x>=somePixels.getWidth()-1){
x=0;
y++;
if(y>=479){
break;
}
}
}*/
// add colour from current second image of two - this is a hang over from when i was comparing two image
}
vector<float> IResponseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
ofPixels imagePixels1 = image1.getPixelsRef();
ofPixels imagePixels2 = image2.getPixelsRef();
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
vector<float> differences;
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];
for(int i=0;i<imagePixels1.size();i++){
thesePixels[i]=0;
}
int x=0;
int y=0;
int chooseComparison=1;
//the current version compares how bright this pixel is with how bright it would be following inverse square fall off from centre
if(chooseComparison==1){
//for each pixel...
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
for(int i=0;i<imagePixels1.size();i+=3){
ofColor colourImage1 = imagePixels1.getColor(x, y);
//ofColor colourImage2 = imagePixels2.getColor(x, y);
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
float _presumedBrightness=ofMap( sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
//float _presumedBrightness=255;
int thisDiff=abs(colourImage1.getBrightness()-_presumedBrightness);
//cout<<thisDiff<< " thisDiff "<<endl;
float multiplier=2.0;
differences.push_back(multiplier* thisDiff);
thesePixels[i]=thisDiff;
thesePixels[i+1]=thisDiff;
thesePixels[i+2]=thisDiff;
x++;
if(x>=imagePixels1.getWidth()){
x=0;
y++;
}
}
}
difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
return differences;
}
+7
View File
@@ -62,4 +62,11 @@ protected:
//this is the temporary container to allow us to convert and save out greyscale images //this is the temporary container to allow us to convert and save out greyscale images
ofxCvColorImage cvConvertorImage; ofxCvColorImage cvConvertorImage;
//mesh making function
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
//returns ofPixels but these pixels actually hold depth data.
//ofPixels make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
bool _gotFirstImage;
ofImage _background;
}; };
+2
View File
@@ -17,6 +17,8 @@ using Poco::Thread;
void RelaxRateAnalysis::setup(int camWidth, int camHeight) void RelaxRateAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_relaxrate", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_relaxrate", NUMBER_RUNS);
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl; cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
+4 -96
View File
@@ -19,6 +19,8 @@ using Poco::Thread;
void ShadowScapesAnalysis::setup(int camWidth, int camHeight) void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shadowscapes", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shadowscapes", NUMBER_RUNS);
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl; cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
@@ -51,7 +53,6 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
_show_image = false; _show_image = false;
_image_shown = false; _image_shown = false;
/*
image1.clear(); image1.clear();
image2.clear(); image2.clear();
image3.clear(); image3.clear();
@@ -98,7 +99,6 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
*/
} }
@@ -226,116 +226,24 @@ void ShadowScapesAnalysis::displayresults()
if(!image3.loadImage(_saved_filenames_synthesis[i])){ if(!image3.loadImage(_saved_filenames_synthesis[i])){
//couldn't load image //couldn't load image
cout << "didn't load image" << endl; cout << "didn't load image" << endl;
} else {
_show_image = true;
_image_shown = false;
} }
/*
if(image3.loadImage(_saved_filenames_synthesis[i])){ if(image3.loadImage(_saved_filenames_synthesis[i])){
//image3.loadImage(_saved_filenames_synthesis[i]); image3.loadImage(_saved_filenames_synthesis[i]);
//cout << "_show_image = true;" << endl; //cout << "_show_image = true;" << endl;
_show_image = true; _show_image = true;
_image_shown = false; _image_shown = false;
} }
*/
} }
} }
void ShadowScapesAnalysis::allocate()
{
_RUN_DONE = false;
image1.clear();
image3.clear();
image4.clear();
image5.clear();
image1.setUseTexture(false);
image3.setUseTexture(false);
image4.setUseTexture(false);
image5.setUseTexture(false);
image1.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);
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
}
void ShadowScapesAnalysis::cleanup()
{
_RUN_DONE = false;
image1.clear();
image3.clear();
image4.clear();
image5.clear();
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
}
// the animation draw - and the output draw // the animation draw - and the output draw
void ShadowScapesAnalysis::draw() void ShadowScapesAnalysis::draw()
{ {
switch (_state) { switch (_state) {
case STATE_ALLOCATE:
{
image2.clear();
image2.setUseTexture(true);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
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);
_state = STATE_DEF;
_RUN_DONE = true;
break;
}
case STATE_CLEANUP:
{
image2.clear();
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
_state = STATE_DEF;
_RUN_DONE = true;
break;
}
case STATE_ACQUIRING: case STATE_ACQUIRING:
{ {
_line += _step; _line += _step;
-3
View File
@@ -26,9 +26,6 @@ public:
void synthesise(); void synthesise();
void displayresults(); void displayresults();
void allocate();
void cleanup();
void draw(); void draw();
void save_cb(Poco::Timer& timer); void save_cb(Poco::Timer& timer);
+2
View File
@@ -15,6 +15,8 @@ using Poco::Thread;
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight) void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shapefromshading", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shapefromshading", NUMBER_RUNS);
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl; cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;
+2
View File
@@ -15,6 +15,8 @@ using Poco::Thread;
void StrobeAnalysis::setup(int camWidth, int camHeight) void StrobeAnalysis::setup(int camWidth, int camHeight)
{ {
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_strobe", NUMBER_RUNS); NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_strobe", NUMBER_RUNS);
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl; cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5; //NUM_RUN = 5;