Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 97e24c31f2 | |||
| f66ce7e2e8 | |||
| 7d7ec3606e | |||
| daec77d2be | |||
| 6d0f6422bf | |||
| 1728a128e4 | |||
| e43b78cc5a |
@@ -1,6 +1,7 @@
|
||||
<!-- THIS FILE NEEDS TO GO IN THE APPLICATION /data/ folder -->
|
||||
|
||||
<config>
|
||||
<mode>drawing</mode>
|
||||
<camera>
|
||||
<id>1</id>
|
||||
<width>640</width>
|
||||
|
||||
@@ -27,8 +27,10 @@
|
||||
#define ISTATE_TRANSITION 0xCCCC
|
||||
#define ISTATE_END 0xDDDD
|
||||
|
||||
|
||||
int _state = ISTATE_UNDEF;
|
||||
|
||||
int RefractiveIndex::_mode;
|
||||
ofPixels RefractiveIndex::_pixels;
|
||||
ofVideoGrabber RefractiveIndex::_vidGrabber;
|
||||
int RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, RefractiveIndex::_vid_id;
|
||||
@@ -50,6 +52,10 @@ void RefractiveIndex::setup()
|
||||
XML.loadFile("config.refindx");
|
||||
}
|
||||
|
||||
// <mode>
|
||||
string m = XML.getValue("config:mode", "analysing");
|
||||
_mode = (m == "analysing" ? MODE_ANALYSING : (m == "drawing" ? MODE_DRAWING : MODE_ANALYSING));
|
||||
|
||||
// <camera>
|
||||
_vid_id = XML.getValue("config:camera:id", CAMERA_ID);
|
||||
cout << "_vid_id: " << _vid_id << endl;
|
||||
@@ -82,8 +88,10 @@ void RefractiveIndex::setup()
|
||||
cout << "* cam width = " << _vid_w << endl;
|
||||
cout << "* cam height = " << _vid_h << endl;
|
||||
|
||||
if(_mode == MODE_ANALYSING) {
|
||||
_vid_stream_open = false;
|
||||
setup_camera();
|
||||
}
|
||||
|
||||
cout << "RRRRRREADY!" << endl;
|
||||
|
||||
@@ -173,9 +181,13 @@ void RefractiveIndex::state_analysis()
|
||||
break;
|
||||
case ISTATE_STOP:
|
||||
stop_analysis(); // blocking
|
||||
if(_mode == MODE_DRAWING)
|
||||
_state = ISTATE_UNDEF;
|
||||
else
|
||||
_state = ISTATE_TRANSITION;
|
||||
break;
|
||||
case ISTATE_END:
|
||||
if(_mode == MODE_ANALYSING)
|
||||
stop_camera();
|
||||
::exit(1);
|
||||
break;
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include "ofxOpenCv.h"
|
||||
#include "ofxXmlSettings.h"
|
||||
|
||||
#define MODE_DRAWING 0xEEFF
|
||||
#define MODE_ANALYSING 0xFFEE
|
||||
|
||||
class RefractiveIndex : public ofBaseApp
|
||||
{
|
||||
public:
|
||||
@@ -55,6 +58,8 @@ public:
|
||||
// acquisition
|
||||
static ofPixels _pixels;
|
||||
static ofVideoGrabber _vidGrabber;
|
||||
static int _mode;
|
||||
|
||||
vector<string> videoSourceList;
|
||||
static int _vid_w, _vid_h, _vid_id;
|
||||
static bool _vid_stream_open;
|
||||
|
||||
@@ -3,10 +3,32 @@
|
||||
#include "AbstractAnalysis.h"
|
||||
#include "RefractiveIndex.h"
|
||||
#include "ofxFileHelper.h"
|
||||
#include "ofSystemUtils.h"
|
||||
|
||||
void AbstractAnalysis::setup(int camWidth, int camHeight) {
|
||||
|
||||
_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
|
||||
void AbstractAnalysis::do_synthesize() {
|
||||
|
||||
switch(RefractiveIndex::_mode)
|
||||
{
|
||||
case MODE_ANALYSING:
|
||||
{
|
||||
for(int i = 0; i < NUM_RUN; i++) {
|
||||
|
||||
cout << "NUM_RUN: " << i << endl;
|
||||
@@ -22,10 +44,31 @@ void AbstractAnalysis::do_synthesize() {
|
||||
if(_state == STATE_STOP) goto exit;
|
||||
_state = STATE_DISPLAY_RESULTS;
|
||||
displayresults();
|
||||
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:
|
||||
cleanup();
|
||||
ofNotifyEvent(_synthesize_cb, _name);
|
||||
|
||||
}
|
||||
|
||||
void AbstractAnalysis::create_dir_allocate_images()
|
||||
@@ -114,6 +157,57 @@ void AbstractAnalysis::create_dir_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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AbstractAnalysis::saveImageAnalysis(string filename)
|
||||
{
|
||||
|
||||
@@ -179,5 +273,6 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
|
||||
|
||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+filename);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
virtual ~AbstractAnalysis(){;}
|
||||
|
||||
// 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
|
||||
void do_synthesize();
|
||||
@@ -37,6 +37,8 @@ protected:
|
||||
|
||||
virtual void create_dir_allocate_images();
|
||||
|
||||
virtual void read_dir_create_list(string folder_path);
|
||||
|
||||
virtual void saveImageAnalysis(string filename);
|
||||
virtual void saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType);
|
||||
|
||||
@@ -49,8 +51,13 @@ protected:
|
||||
// display the results from disk
|
||||
virtual void displayresults() = 0;
|
||||
|
||||
// display the results from disk
|
||||
virtual void cleanup() {;}
|
||||
|
||||
|
||||
public:
|
||||
string _name;
|
||||
string _draw_directory;
|
||||
|
||||
// event
|
||||
ofEvent<string> _synthesize_cb;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -14,6 +14,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -65,5 +65,8 @@ protected:
|
||||
//this is the temporary container to allow us to convert and save out greyscale images
|
||||
ofxCvColorImage cvConvertorImage;
|
||||
|
||||
unsigned char * imagePixels;
|
||||
int vectorCount;
|
||||
ofVec2f * vectorField;
|
||||
|
||||
};
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
@@ -184,7 +186,11 @@ void IResponseAnalysis::synthesise()
|
||||
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
|
||||
|
||||
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
|
||||
|
||||
_synth_save_cnt++;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+45
-33
@@ -17,6 +17,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
@@ -55,49 +57,18 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
||||
_image_shown = false;
|
||||
|
||||
image1.clear();
|
||||
image2.clear();
|
||||
image3.clear();
|
||||
image4.clear();
|
||||
image5.clear();
|
||||
|
||||
// images use for drawing the synthesized files to the screen ///
|
||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||
|
||||
// images used for re-loading and saving out the synthesized files ///
|
||||
image3.setUseTexture(false);
|
||||
image4.setUseTexture(false);
|
||||
image5.setUseTexture(false);
|
||||
|
||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||
|
||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
||||
|
||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
||||
cvColorImage1.clear();
|
||||
cvGrayImage1.clear();
|
||||
cvGrayDiff1.clear();
|
||||
|
||||
cvColorImage2.clear();
|
||||
cvGrayImage2.clear();
|
||||
cvGrayDiff2.clear();
|
||||
|
||||
|
||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
|
||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +106,7 @@ void RelaxRateAnalysis::synthesise()
|
||||
|
||||
cvContourFinderVect.clear();
|
||||
|
||||
|
||||
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||
|
||||
if(_state == STATE_STOP) return;
|
||||
@@ -166,11 +138,16 @@ void RelaxRateAnalysis::synthesise()
|
||||
void RelaxRateAnalysis::displayresults()
|
||||
{
|
||||
|
||||
cvContourFinderVectDisplay.clear();
|
||||
//cvContourFinderVectDisplay.clear();
|
||||
clearcfindervectdisplay();
|
||||
|
||||
for(int i=1;i<cvContourFinderVect.size();i++){
|
||||
|
||||
if(_state == STATE_STOP) return;
|
||||
if(_state == STATE_STOP){
|
||||
clearcfindervectdisplay();
|
||||
clearcfindervect();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
||||
@@ -187,6 +164,14 @@ void RelaxRateAnalysis::displayresults()
|
||||
|
||||
}
|
||||
|
||||
clearcfindervectdisplay();
|
||||
clearcfindervect();
|
||||
|
||||
|
||||
//cvContourFinderVectDisplay.clear();
|
||||
//cvContourFinderVect.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +183,7 @@ void RelaxRateAnalysis::draw()
|
||||
case STATE_ACQUIRING:
|
||||
{
|
||||
|
||||
|
||||
if (_frame_cnt < _frame_cnt_max)
|
||||
{
|
||||
|
||||
@@ -227,6 +213,7 @@ void RelaxRateAnalysis::draw()
|
||||
|
||||
case STATE_SYNTHESISING:
|
||||
{
|
||||
|
||||
// display animation of something while the synthesis in on-going...
|
||||
|
||||
//cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n";
|
||||
@@ -356,3 +343,28 @@ void RelaxRateAnalysis::save_cb(Timer& timer)
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RelaxRateAnalysis::cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void RelaxRateAnalysis::clearcfindervect()
|
||||
{
|
||||
for(int i = 0; i < cvContourFinderVect.size(); i++) {
|
||||
rfiCvContourFinder* f = cvContourFinderVect[i];
|
||||
|
||||
// maybe it's erase here? http://forum.openframeworks.cc/index.php/topic,3016.0.html
|
||||
// cvContourFinderVect.erase(i);
|
||||
|
||||
delete f;
|
||||
}
|
||||
cvContourFinderVect.clear();
|
||||
|
||||
}
|
||||
|
||||
void RelaxRateAnalysis::clearcfindervectdisplay()
|
||||
{
|
||||
cvContourFinderVectDisplay.clear();
|
||||
}
|
||||
|
||||
|
||||
+5
-18
@@ -23,6 +23,7 @@ public:
|
||||
void acquire();
|
||||
void synthesise();
|
||||
void displayresults();
|
||||
void cleanup();
|
||||
|
||||
void draw();
|
||||
|
||||
@@ -30,6 +31,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
void clearcfindervect();
|
||||
void clearcfindervectdisplay();
|
||||
|
||||
bool _RUN_DONE;
|
||||
float _flip, _level;
|
||||
int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt;
|
||||
@@ -39,27 +43,10 @@ protected:
|
||||
int _maxblobs;
|
||||
|
||||
bool _show_image, _image_shown;
|
||||
|
||||
ofImage image1;
|
||||
ofImage image2;
|
||||
ofImage image3;
|
||||
ofImage image4;
|
||||
ofImage image5;
|
||||
ofImage image6;
|
||||
|
||||
ofxCvColorImage cvColorImage1;
|
||||
ofxCvColorImage cvColorImage2;
|
||||
ofxCvColorImage cvColorImage3;
|
||||
ofxCvColorImage cvColorImage4;
|
||||
ofxCvColorImage cvColorImage5;
|
||||
ofxCvColorImage cvColorImage6;
|
||||
|
||||
ofxCvGrayscaleImage cvGrayDiff1;
|
||||
ofxCvGrayscaleImage cvGrayDiff2;
|
||||
|
||||
ofxCvGrayscaleImage cvGrayImage1;
|
||||
ofxCvGrayscaleImage cvGrayImage2;
|
||||
ofxCvGrayscaleImage cvGrayImage3;
|
||||
ofxCvGrayscaleImage cvGrayImage4;
|
||||
|
||||
vector<rfiCvContourFinder*> cvContourFinderVect;
|
||||
vector<rfiCvContourFinder*> cvContourFinderVectDisplay;
|
||||
|
||||
@@ -19,6 +19,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
@@ -439,6 +441,9 @@ void ShadowScapesAnalysis::draw()
|
||||
|
||||
// display results of the synthesis
|
||||
_RUN_DONE = true;
|
||||
|
||||
// clear allocated memory...?
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
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);
|
||||
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
Reference in New Issue
Block a user