2012-02-22 02:09:19 +01:00
|
|
|
/* */
|
2012-01-24 15:13:07 +01:00
|
|
|
|
|
|
|
|
#include "AbstractAnalysis.h"
|
2012-02-11 18:54:46 +01:00
|
|
|
#include "RefractiveIndex.h"
|
2012-02-18 20:37:22 +01:00
|
|
|
#include "ofxFileHelper.h"
|
2012-02-11 18:54:46 +01:00
|
|
|
|
2012-02-15 08:43:43 +01:00
|
|
|
// this is the main threaded loop for a given analysis
|
2012-02-11 18:54:46 +01:00
|
|
|
void AbstractAnalysis::do_synthesize() {
|
2012-02-22 15:36:22 +01:00
|
|
|
|
|
|
|
|
for(int i = 0; i < NUM_RUN; i++) {
|
|
|
|
|
|
2012-02-26 15:28:27 +01:00
|
|
|
cout << "NUM_RUN: " << i << endl;
|
2012-02-22 15:36:22 +01:00
|
|
|
|
2012-02-23 01:22:14 +00:00
|
|
|
_saved_filenames_analysis.clear();
|
2012-02-26 19:12:34 +01:00
|
|
|
_saved_filenames_synthesis.clear();
|
|
|
|
|
|
2012-02-22 15:36:22 +01:00
|
|
|
_state = STATE_ACQUIRING;
|
|
|
|
|
acquire();
|
|
|
|
|
if(_state == STATE_STOP) goto exit;
|
|
|
|
|
_state = STATE_SYNTHESISING;
|
|
|
|
|
synthesise();
|
|
|
|
|
if(_state == STATE_STOP) goto exit;
|
|
|
|
|
_state = STATE_DISPLAY_RESULTS;
|
|
|
|
|
displayresults();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 02:09:19 +01:00
|
|
|
exit:
|
2012-02-11 18:54:46 +01:00
|
|
|
ofNotifyEvent(_synthesize_cb, _name);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:12:34 +01:00
|
|
|
void AbstractAnalysis::create_dir_allocate_images()
|
2012-02-11 18:54:46 +01:00
|
|
|
{
|
|
|
|
|
// HERE IS WHERE WE SETUP THE DIRECTORY FOR ALL THE SAVED IMAGES
|
|
|
|
|
|
|
|
|
|
//FOR WINDOWS i HAVE HAD TO REPLACE SPACES WITH UNDERSCORES AND REDUCE THE LENGTH OF THE FOLDER NAME
|
|
|
|
|
time_t rawtime;
|
|
|
|
|
struct tm * timeinfo;
|
|
|
|
|
|
|
|
|
|
time ( &rawtime );
|
|
|
|
|
timeinfo = localtime ( &rawtime );
|
|
|
|
|
string time = asctime(timeinfo);
|
|
|
|
|
string replaceTime = "";
|
|
|
|
|
|
|
|
|
|
//DON'T INCLUDE THE DAY IN WORDS EG 'TUE' OR THE YEAR EG 2012 THIS MAKES THE DIRECTORY NAME TOO LONG AND CAUSES DIR CREATION TO FAIL
|
|
|
|
|
for(int i=4;i<time.size()-4;i++){
|
|
|
|
|
if(time.at(i)==' '||time.at(i)==':'){
|
|
|
|
|
replaceTime+="_";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
replaceTime+=time.at(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-18 20:37:22 +01:00
|
|
|
|
2012-02-22 02:09:19 +01:00
|
|
|
ofxFileHelper fileHelperAnalysis;
|
|
|
|
|
ofxFileHelper fileHelperSynthesis;
|
2012-02-11 18:54:46 +01:00
|
|
|
|
2012-02-22 02:09:19 +01:00
|
|
|
_whole_file_path_analysis = ANALYSIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime ;
|
|
|
|
|
|
|
|
|
|
//cout << "_whole_file_path_analysis = " << _whole_file_path_analysis << endl;
|
|
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(_whole_file_path_analysis)){
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
|
2012-02-22 02:09:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_whole_file_path_synthesis = SYNTHESIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime;
|
|
|
|
|
|
|
|
|
|
if(!fileHelperSynthesis.doesDirectoryExist(_whole_file_path_synthesis)){
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
|
|
|
|
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime))
|
2012-02-22 02:09:19 +01:00
|
|
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
2012-02-23 01:22:14 +00:00
|
|
|
|
2012-02-11 18:54:46 +01:00
|
|
|
}
|
2012-02-26 19:12:34 +01:00
|
|
|
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
|
|
|
|
|
|
2012-02-11 18:54:46 +01:00
|
|
|
|
2012-02-26 19:12:34 +01:00
|
|
|
//////////////////////////////ALLOCATE IMAGES //////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
ofImage myColorImage1;
|
2012-02-27 02:41:25 +01:00
|
|
|
myColorImage1.clear();
|
2012-02-26 19:12:34 +01:00
|
|
|
myColorImage1.setUseTexture(false);
|
|
|
|
|
myColorImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
|
|
|
|
2012-02-27 02:41:25 +01:00
|
|
|
//ofxCvImage myColorCvImage2;
|
2012-02-27 03:06:40 +01:00
|
|
|
myColorImage2.clear();
|
|
|
|
|
myColorImage2.setUseTexture(false);
|
|
|
|
|
myColorImage2.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
2012-02-27 02:41:25 +01:00
|
|
|
|
|
|
|
|
//ofxCvImage myGrayCvImage1;
|
2012-02-27 03:06:40 +01:00
|
|
|
myGrayImage1.clear();
|
|
|
|
|
myGrayImage1.setUseTexture(false);
|
|
|
|
|
myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE);
|
2012-02-26 19:12:34 +01:00
|
|
|
|
|
|
|
|
//////////////////////////////END ALLOCATE IMAGES //////////////////////////////////////////////////
|
|
|
|
|
|
2012-02-11 18:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:12:34 +01:00
|
|
|
void AbstractAnalysis::saveImageAnalysis(string filename)
|
2012-02-26 15:28:27 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera
|
|
|
|
|
|
|
|
|
|
if (RefractiveIndex::_vidGrabber.isFrameNew())
|
|
|
|
|
{
|
|
|
|
|
RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-27 03:11:26 +01:00
|
|
|
#ifdef TARGET_OSX
|
2012-02-26 15:28:27 +01:00
|
|
|
|
2012-02-27 03:11:26 +01:00
|
|
|
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+filename, OF_IMAGE_QUALITY_BEST);
|
2012-02-26 15:28:27 +01:00
|
|
|
|
2012-02-27 03:11:26 +01:00
|
|
|
#elif defined(TARGET_WIN32)
|
2012-02-26 15:28:27 +01:00
|
|
|
|
|
|
|
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
|
|
|
|
unsigned char * somePixels;
|
|
|
|
|
ofPixels appPix = RefractiveIndex::_pixels;
|
|
|
|
|
somePixels = appPix.getPixels();
|
2012-02-27 03:06:40 +01:00
|
|
|
myColorImage1.setUseTexture(false);
|
2012-02-26 19:12:34 +01:00
|
|
|
myColorImage1.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
|
|
|
|
myColorImage1.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+filename);
|
2012-02-27 02:41:25 +01:00
|
|
|
myColorImage1.clear();
|
2012-02-26 15:28:27 +01:00
|
|
|
|
2012-02-27 03:11:26 +01:00
|
|
|
#endif
|
2012-02-26 15:28:27 +01:00
|
|
|
|
|
|
|
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+filename);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:12:34 +01:00
|
|
|
|
|
|
|
|
void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType)
|
|
|
|
|
{
|
|
|
|
|
|
2012-02-27 18:47:18 +01:00
|
|
|
//#ifdef TARGET_OSX
|
2012-02-26 19:12:34 +01:00
|
|
|
|
2012-02-27 18:47:18 +01:00
|
|
|
// ofSaveImage(newPixels->getPixelsRef(), _whole_file_path_synthesis+"/"+filename, OF_IMAGE_QUALITY_BEST);
|
2012-02-26 19:12:34 +01:00
|
|
|
|
2012-02-27 18:47:18 +01:00
|
|
|
//#elif defined(TARGET_WIN32)
|
2012-02-26 19:12:34 +01:00
|
|
|
|
|
|
|
|
if (newType == OF_IMAGE_COLOR){
|
2012-02-27 03:06:40 +01:00
|
|
|
myColorImage2.setUseTexture(false);
|
|
|
|
|
myColorImage2.setFromPixels(newPixels->getPixels(), newPixels->getWidth(), newPixels->getHeight(), OF_IMAGE_COLOR);
|
|
|
|
|
myColorImage2.saveImage(_whole_file_path_synthesis+"/"+filename);
|
|
|
|
|
myColorImage2.clear();
|
2012-02-26 19:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newType == OF_IMAGE_GRAYSCALE){
|
2012-02-27 03:06:40 +01:00
|
|
|
myGrayImage1.setUseTexture(false);
|
2012-02-27 18:47:18 +01:00
|
|
|
|
|
|
|
|
// THIS IS HOW YOU HAVE TO SAVE OUT THE GREYSCALE IMAGES on WINDOWS FOR SOME REASON --> i.e.: as an OF_IMAGE_COLOR
|
|
|
|
|
myGrayImage1.setFromPixels(newPixels->getPixels(), newPixels->getWidth(), newPixels->getHeight(), OF_IMAGE_COLOR);
|
|
|
|
|
|
|
|
|
|
// THIS DOESN' SEEM TO SAVE OUT IMAGES ON WINDOWS
|
|
|
|
|
//myGrayImage1.setFromPixels(newPixels->getPixels(), newPixels->getWidth(), newPixels->getHeight(), OF_IMAGE_GRAYSCALE);
|
2012-02-27 03:06:40 +01:00
|
|
|
myGrayImage1.saveImage(_whole_file_path_synthesis+"/"+filename);
|
|
|
|
|
myGrayImage1.clear();
|
2012-02-26 19:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-27 18:47:18 +01:00
|
|
|
//#endif
|
2012-02-27 02:41:25 +01:00
|
|
|
|
2012-02-27 02:46:18 +01:00
|
|
|
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+filename);
|
2012-02-26 19:12:34 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|