Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fefa41516c |
@@ -1,10 +1,10 @@
|
|||||||
WARNING: WORK IN PROGRESS...
|
WARNING: WORK IN PROGRESS...
|
||||||
|
|
||||||
configuring OpenFrameworks under Xcode
|
configuring OpenFrameworks
|
||||||
---------------------------------------
|
-----------------
|
||||||
|
|
||||||
these files are configured according to OpenFrameworks addons - http://ofxaddons.com/howto
|
these files are configured according to OpenFrameworks addons - http://ofxaddons.com/howto
|
||||||
|
|
||||||
(1) drag-drop "ReflectiveIndex" folder into your OpenFrameworks project
|
(1) drag-drop "ReflectiveIndex" folder into your OpenFrameworks project
|
||||||
(2) Install depedencies: {ofxXmlSettings, ofxOpenCV, ofxFileHelper};
|
(2) Install depedencies: {ofxDirList, ofxControlPanel, ofxXmlSettings};
|
||||||
(3) Press Play!
|
(3) Press Play!
|
||||||
|
|||||||
@@ -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>
|
|
||||||
<threshold>51</threshold>
|
|
||||||
<maxblobs>25</maxblobs>
|
|
||||||
</relaxrate>
|
|
||||||
|
|
||||||
</config>
|
|
||||||
+41
-57
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include "ofxXmlSettings.h"
|
#include "ofxXmlSettings.h"
|
||||||
|
|
||||||
#define CAMERA_ID 0
|
#define CAMERA_ID 1
|
||||||
#define CAMERA_ACQU_WIDTH 640
|
#define CAMERA_ACQU_WIDTH 640
|
||||||
#define CAMERA_ACQU_HEIGHT 480
|
#define CAMERA_ACQU_HEIGHT 480
|
||||||
|
|
||||||
@@ -27,10 +27,8 @@
|
|||||||
#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;
|
||||||
@@ -52,10 +50,6 @@ 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;
|
||||||
@@ -88,10 +82,8 @@ 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;
|
||||||
|
|
||||||
@@ -110,7 +102,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,7 +116,6 @@ void RefractiveIndex::setup()
|
|||||||
|
|
||||||
_analysisVector.push_back(new DiffNoiseAnalysis());
|
_analysisVector.push_back(new DiffNoiseAnalysis());
|
||||||
|
|
||||||
|
|
||||||
//_currentAnalysisIndx = 0;
|
//_currentAnalysisIndx = 0;
|
||||||
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
||||||
//_state = ISTATE_START;
|
//_state = ISTATE_START;
|
||||||
@@ -181,14 +171,10 @@ void RefractiveIndex::state_analysis()
|
|||||||
break;
|
break;
|
||||||
case ISTATE_STOP:
|
case ISTATE_STOP:
|
||||||
stop_analysis(); // blocking
|
stop_analysis(); // blocking
|
||||||
if(_mode == MODE_DRAWING)
|
_state = ISTATE_TRANSITION;
|
||||||
_state = ISTATE_UNDEF;
|
|
||||||
else
|
|
||||||
_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;
|
||||||
case ISTATE_UNDEF:
|
case ISTATE_UNDEF:
|
||||||
@@ -366,49 +352,47 @@ void RefractiveIndex::keyPressed (int key)
|
|||||||
TO DO: add a file dialog so we can save images to another hard drive...
|
TO DO: add a file dialog so we can save images to another hard drive...
|
||||||
e.g.: http://dev.openframeworks.cc/pipermail/of-dev-openframeworks.cc/2011-April/003125.html
|
e.g.: http://dev.openframeworks.cc/pipermail/of-dev-openframeworks.cc/2011-April/003125.html
|
||||||
|
|
||||||
>> case 's':
|
>> case 's':
|
||||||
>> doSave ^= true;
|
>> doSave ^= true;
|
||||||
>> doLoad = false;
|
>> doLoad = false;
|
||||||
>> if(doSave) {
|
>> if(doSave) {
|
||||||
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to save to", true);
|
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to save to", true);
|
||||||
>> if(r.bSuccess) {
|
>> if(r.bSuccess) {
|
||||||
>> saveCounter = 0;
|
>> saveCounter = 0;
|
||||||
>> savePath = r.getPath();
|
>> savePath = r.getPath();
|
||||||
>> ofDirectory::createDirectory(savePath + "/color/");
|
>> ofDirectory::createDirectory(savePath + "/color/");
|
||||||
>> ofDirectory::createDirectory(savePath + "/depth/");
|
>> ofDirectory::createDirectory(savePath + "/depth/");
|
||||||
>> printf("SAVE %s %s\n", r.getPath().c_str(), r.getName().c_str());
|
>> printf("SAVE %s %s\n", r.getPath().c_str(), r.getName().c_str());
|
||||||
>> } else {
|
>> } else {
|
||||||
>> doSave = false;
|
>> doSave = false;
|
||||||
>> }
|
>> }
|
||||||
>>
|
>>
|
||||||
>> }
|
>> }
|
||||||
>> break;
|
>> break;
|
||||||
>>
|
>>
|
||||||
>> case 'l':
|
>> case 'l':
|
||||||
>> doLoad ^= true;
|
>> doLoad ^= true;
|
||||||
>> doSave = false;
|
>> doSave = false;
|
||||||
>> if(doLoad) {
|
>> if(doLoad) {
|
||||||
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to load from", true);
|
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to load from", true);
|
||||||
>> if(r.bSuccess) {
|
>> if(r.bSuccess) {
|
||||||
>> loadCounter = 0;
|
>> loadCounter = 0;
|
||||||
>> loadPath = r.getPath();
|
>> loadPath = r.getPath();
|
||||||
>> ofDirectory dir;
|
>> ofDirectory dir;
|
||||||
>> loadMaxFiles = MAX(dir.listDir(loadPath + "/color"), dir.listDir(loadPath + "/depth"));
|
>> loadMaxFiles = MAX(dir.listDir(loadPath + "/color"), dir.listDir(loadPath + "/depth"));
|
||||||
>> printf("LOAD %i %s %s\n", loadMaxFiles, r.getPath().c_str(), r.getName().c_str());
|
>> printf("LOAD %i %s %s\n", loadMaxFiles, r.getPath().c_str(), r.getName().c_str());
|
||||||
>> } else {
|
>> } else {
|
||||||
>> doLoad = false;
|
>> doLoad = false;
|
||||||
>> }
|
>> }
|
||||||
>>
|
>>
|
||||||
>> }
|
>> }
|
||||||
>> break;
|
>> break;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::exit()
|
void RefractiveIndex::exit()
|
||||||
{
|
{
|
||||||
if(_currentAnalysis)
|
|
||||||
_analysisAdapator->stop();
|
|
||||||
stop_camera();
|
stop_camera();
|
||||||
}
|
}
|
||||||
@@ -11,9 +11,6 @@
|
|||||||
#include "ofxOpenCv.h"
|
#include "ofxOpenCv.h"
|
||||||
#include "ofxXmlSettings.h"
|
#include "ofxXmlSettings.h"
|
||||||
|
|
||||||
#define MODE_DRAWING 0xEEFF
|
|
||||||
#define MODE_ANALYSING 0xFFEE
|
|
||||||
|
|
||||||
class RefractiveIndex : public ofBaseApp
|
class RefractiveIndex : public ofBaseApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -58,8 +55,6 @@ 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;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ void AbstractAnalysis::do_synthesize() {
|
|||||||
|
|
||||||
for(int i = 0; i < NUM_RUN; i++) {
|
for(int i = 0; i < NUM_RUN; i++) {
|
||||||
|
|
||||||
cout << "NUM_RUN: " << i << endl;
|
cout << "i NUM_RUN" << i << endl;
|
||||||
|
|
||||||
_saved_filenames_analysis.clear();
|
_saved_filenames_analysis.clear();
|
||||||
_saved_filenames_synthesis.clear();
|
_saved_filenames_synthesis.clear();
|
||||||
@@ -22,15 +22,13 @@ 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();
|
||||||
cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
cleanup();
|
|
||||||
ofNotifyEvent(_synthesize_cb, _name);
|
ofNotifyEvent(_synthesize_cb, _name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractAnalysis::create_dir_allocate_images()
|
void AbstractAnalysis::create_dir()
|
||||||
{
|
{
|
||||||
// HERE IS WHERE WE SETUP THE DIRECTORY FOR ALL THE SAVED IMAGES
|
// HERE IS WHERE WE SETUP THE DIRECTORY FOR ALL THE SAVED IMAGES
|
||||||
|
|
||||||
@@ -94,92 +92,7 @@ void AbstractAnalysis::create_dir_allocate_images()
|
|||||||
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
|
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////ALLOCATE IMAGES //////////////////////////////////////////////////
|
|
||||||
|
|
||||||
myColorImage1.clear();
|
|
||||||
myColorImage1.setUseTexture(false);
|
|
||||||
myColorImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
myColorImage2.clear();
|
|
||||||
myColorImage2.setUseTexture(false);
|
|
||||||
myColorImage2.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
|
|
||||||
myGrayImage1.clear();
|
|
||||||
myGrayImage1.setUseTexture(false);
|
|
||||||
myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE);
|
|
||||||
|
|
||||||
//////////////////////////////END ALLOCATE IMAGES //////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void AbstractAnalysis::saveImageAnalysis(string filename)
|
|
||||||
{
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef TARGET_OSX
|
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+filename, OF_IMAGE_QUALITY_BEST);
|
|
||||||
|
|
||||||
#elif defined(TARGET_WIN32)
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
|
||||||
unsigned char * somePixels;
|
|
||||||
ofPixels appPix = RefractiveIndex::_pixels;
|
|
||||||
somePixels = appPix.getPixels();
|
|
||||||
myColorImage1.setUseTexture(false);
|
|
||||||
myColorImage1.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
|
||||||
myColorImage1.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+filename);
|
|
||||||
myColorImage1.clear();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+filename);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType)
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef TARGET_OSX
|
|
||||||
|
|
||||||
|
|
||||||
ofSaveImage(newPixels->getPixelsRef(), _whole_file_path_synthesis+"/"+filename, OF_IMAGE_QUALITY_BEST);
|
|
||||||
|
|
||||||
#elif defined(TARGET_WIN32)
|
|
||||||
|
|
||||||
if (newType == OF_IMAGE_COLOR){
|
|
||||||
myColorImage2.setUseTexture(false);
|
|
||||||
myColorImage2.setFromPixels(newPixels->getPixels(), newPixels->getWidth(), newPixels->getHeight(), OF_IMAGE_COLOR);
|
|
||||||
myColorImage2.saveImage(_whole_file_path_synthesis+"/"+filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newType == OF_IMAGE_GRAYSCALE){
|
|
||||||
myGrayImage1.setUseTexture(false);
|
|
||||||
|
|
||||||
// THIS IS HOW YOU HAVE TO SAVE OUT THE GREYSCALE IMAGES on WINDOWS FOR SOME REASON --> i.e.: as an OF_IMAGE_COLOR
|
|
||||||
// But they don't save properly - they're spatially translated and generally f'd up
|
|
||||||
myGrayImage1.setFromPixels(newPixels->getPixels(), newPixels->getWidth(), newPixels->getHeight(), OF_IMAGE_COLOR);
|
|
||||||
myGrayImage1.setImageType(OF_IMAGE_COLOR);
|
|
||||||
myGrayImage1.saveImage(_whole_file_path_synthesis+"/"+filename);
|
|
||||||
//myGrayImage1.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+filename);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-13
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
#include "ofEvents.h"
|
#include "ofEvents.h"
|
||||||
#include "ofxOpenCv.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define ANALYSIS_PATH "analysis/"
|
#define ANALYSIS_PATH "analysis/"
|
||||||
@@ -35,10 +34,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void create_dir_allocate_images();
|
virtual void create_dir();
|
||||||
|
|
||||||
virtual void saveImageAnalysis(string filename);
|
|
||||||
virtual void saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType);
|
|
||||||
|
|
||||||
// acquire images - all the children (see - do_synthesize)
|
// acquire images - all the children (see - do_synthesize)
|
||||||
virtual void acquire() = 0;
|
virtual void acquire() = 0;
|
||||||
@@ -49,10 +45,6 @@ protected:
|
|||||||
// display the results from disk
|
// display the results from disk
|
||||||
virtual void displayresults() = 0;
|
virtual void displayresults() = 0;
|
||||||
|
|
||||||
// display the results from disk
|
|
||||||
virtual void cleanup() {;}
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string _name;
|
string _name;
|
||||||
|
|
||||||
@@ -67,10 +59,6 @@ protected:
|
|||||||
|
|
||||||
int _state;
|
int _state;
|
||||||
|
|
||||||
ofImage myColorImage1;
|
|
||||||
ofImage myColorImage2;
|
|
||||||
ofImage myGrayImage1;
|
|
||||||
|
|
||||||
//int _run_cnt;
|
//int _run_cnt;
|
||||||
|
|
||||||
float DELTA_T_SAVE;
|
float DELTA_T_SAVE;
|
||||||
|
|||||||
+47
-56
@@ -15,15 +15,15 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_camnoise", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
|
||||||
|
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_camnoise", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_camnoise", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME CamNoiseAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME CamNoiseAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
|
||||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
@@ -40,17 +40,11 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
int anim_time = 10; // 10 seconds
|
int anim_time = 10; // 10 seconds
|
||||||
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
|
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
|
|
||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
|
||||||
image2.clear();
|
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
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
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
@@ -60,28 +54,9 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -90,8 +65,6 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,7 +77,7 @@ void CamNoiseAnalysis::acquire()
|
|||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
||||||
_run_cnt++;
|
_run_cnt++;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
// for(int i = 0; i < NUM_RUN; i++) {
|
// for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -150,23 +123,15 @@ void CamNoiseAnalysis::synthesise()
|
|||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||||
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
cvGrayImage1 = cvColorImage1;
|
||||||
// cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
//cvGrayImage2 = cvColorImage2;
|
||||||
//added by tom we weren't actually setting cvgrayimage1 anywhere
|
|
||||||
// cvGrayImage1.setFromPixels(cvColorImage1.getPixels(),cvColorImage1.width,cvColorImage1.height);
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
|
||||||
//cvGrayImage1=cvColorImage1;
|
|
||||||
|
|
||||||
|
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
cvGrayImage1.erode();
|
cvGrayImage1.erode();
|
||||||
cvGrayImage1.erode();
|
cvGrayImage1.erode();
|
||||||
cvGrayImage1.erode();
|
cvGrayImage1.erode();
|
||||||
cvGrayImage1.blur();
|
cvGrayImage1.blur();
|
||||||
cvGrayImage1.contrastStretch();
|
cvGrayImage1.contrastStretch();
|
||||||
/* cvColorImage1.erode();
|
|
||||||
cvColorImage1.erode();
|
|
||||||
cvColorImage1.erode();
|
|
||||||
cvColorImage1.blur();
|
|
||||||
cvColorImage1.contrastStretch();*/
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
string file_name;
|
string file_name;
|
||||||
@@ -179,24 +144,18 @@ void CamNoiseAnalysis::synthesise()
|
|||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
|
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
|
||||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
image.setUseTexture(false);
|
||||||
|
|
||||||
//image.setFromPixels(cvGrayImage1.getPixels(), cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
|
image.setFromPixels(cvGrayImage1.getPixels(), cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
|
||||||
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
||||||
|
|
||||||
//_saved_filenames_synthesis.push_back(_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(cvGrayImage1,cvGrayImage1,cvGrayImage1);
|
|
||||||
//cvConvertorImage.setFromGrayscalePlanarImages(cvColorImage1,cvColorImage1,cvColorImage1);
|
|
||||||
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,7 +363,7 @@ void CamNoiseAnalysis::draw()
|
|||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
ofSetColor(255, 255, 255);
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
@@ -428,7 +387,39 @@ void CamNoiseAnalysis::save_cb(Timer& timer)
|
|||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "CamNoiseAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,4 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+49
-39
@@ -14,12 +14,13 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colormulti", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
|
||||||
|
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colormulti", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_colormulti", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ColorMultiAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ColorMultiAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
//int acq_run_time = 35;
|
//int acq_run_time = 35;
|
||||||
@@ -29,7 +30,7 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
|
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
@@ -39,15 +40,12 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
|||||||
int anim_time = 10; // 10 seconds
|
int anim_time = 10; // 10 seconds
|
||||||
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
|
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
|
||||||
|
|
||||||
|
//for an ofxOpenCv.h image i would like to use..."
|
||||||
|
//image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
|
||||||
image2.clear();
|
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
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
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
@@ -57,28 +55,9 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -87,8 +66,6 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorMultiAnalysis::acquire()
|
void ColorMultiAnalysis::acquire()
|
||||||
@@ -100,7 +77,7 @@ void ColorMultiAnalysis::acquire()
|
|||||||
_run_cnt++;
|
_run_cnt++;
|
||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -169,19 +146,17 @@ void ColorMultiAnalysis::synthesise()
|
|||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
|
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
|
||||||
|
|
||||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
image.setUseTexture(false);
|
||||||
|
|
||||||
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
|
image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
|
||||||
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
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> ///
|
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
||||||
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
// }
|
// }
|
||||||
@@ -246,6 +221,8 @@ void ColorMultiAnalysis::draw()
|
|||||||
//cout << "FADING IN..." << endl;
|
//cout << "FADING IN..." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt >= _fade_in_frames && _frame_cnt < _frame_cnt_max-_fade_in_frames){
|
if (_frame_cnt >= _fade_in_frames && _frame_cnt < _frame_cnt_max-_fade_in_frames){
|
||||||
|
|
||||||
aColor.setHsb(c, 255, 255);
|
aColor.setHsb(c, 255, 255);
|
||||||
@@ -406,9 +383,42 @@ void ColorMultiAnalysis::draw()
|
|||||||
// this runs at save_cb timer rate = DELTA_T_SAVE
|
// this runs at save_cb timer rate = DELTA_T_SAVE
|
||||||
void ColorMultiAnalysis::save_cb(Timer& timer)
|
void ColorMultiAnalysis::save_cb(Timer& timer)
|
||||||
{
|
{
|
||||||
|
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "ColorMultiAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,4 @@ protected:
|
|||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+67
-202
@@ -15,12 +15,13 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colorsingle", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
|
||||||
|
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colorsingle", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_colorsingle", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ColorSingleAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ColorSingleAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
||||||
@@ -30,7 +31,7 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
|
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -49,12 +50,6 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
|
||||||
image2.clear();
|
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
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
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
@@ -64,28 +59,9 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -93,9 +69,6 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,7 +82,7 @@ void ColorSingleAnalysis::acquire()
|
|||||||
_run_cnt++;
|
_run_cnt++;
|
||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -124,6 +97,7 @@ void ColorSingleAnalysis::acquire()
|
|||||||
|
|
||||||
save_timer->stop();
|
save_timer->stop();
|
||||||
|
|
||||||
|
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,103 +110,11 @@ void ColorSingleAnalysis::synthesise()
|
|||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
||||||
|
|
||||||
//cout << "ColorSingleAnalysis::synthesis FOR LOOP...\n";
|
//cout << "ColorSingleAnalysis::synthesis FOR LOOP...\n";
|
||||||
|
|
||||||
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
image1.loadImage("Mar_02_19_00_47_2/194_9.72_1.jpg");
|
|
||||||
image1.resize(image1.width/20, image1.height/20);
|
|
||||||
|
|
||||||
int width = image1.width;
|
|
||||||
int height = image1.height;
|
|
||||||
|
|
||||||
// get the pixels from the image
|
|
||||||
imagePixels = image1.getPixels();
|
|
||||||
|
|
||||||
// ------------------- create the vector field ------------------------------------
|
|
||||||
|
|
||||||
vectorCount = width * height;
|
|
||||||
|
|
||||||
// create a 2d vector field
|
|
||||||
vectorField = new ofVec2f[vectorCount];
|
|
||||||
|
|
||||||
// set all values in vector field to 0.0
|
|
||||||
for(int i=0; i<vectorCount; i++){
|
|
||||||
|
|
||||||
vectorField[i].x = 0.0;
|
|
||||||
vectorField[i].y = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------- calculate the vectors ------------------------------------
|
|
||||||
|
|
||||||
// loop through all of the pixels
|
|
||||||
for(int x=1; x< width-1; x++){
|
|
||||||
for(int y=1; y< height-1; y++){
|
|
||||||
|
|
||||||
char areaPixels[9];
|
|
||||||
|
|
||||||
// loop through the area pixels
|
|
||||||
for(int i=-1; i<=1; i++){
|
|
||||||
for(int j=-1; j<=1; j++){
|
|
||||||
|
|
||||||
// determine where to read from in the area (not optimized)
|
|
||||||
int readPos = ((y + j) * width + (x + i)) * 3;
|
|
||||||
|
|
||||||
unsigned char R = imagePixels[readPos];
|
|
||||||
unsigned char G = imagePixels[readPos+1];
|
|
||||||
unsigned char B = imagePixels[readPos+2];
|
|
||||||
|
|
||||||
unsigned char BR = (0.299 * R) + (.587 * G) + (.114 * B);
|
|
||||||
|
|
||||||
int writePos = (j+1) * 3 + (i + 1);
|
|
||||||
|
|
||||||
areaPixels[writePos] = BR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float dX = (areaPixels[0] + areaPixels[3] + areaPixels[6])/3 - (areaPixels[2] + areaPixels[5] + areaPixels[8])/3;
|
|
||||||
float dY = (areaPixels[0] + areaPixels[1] + areaPixels[2])/3 - (areaPixels[6] + areaPixels[7] + areaPixels[8])/3;
|
|
||||||
|
|
||||||
int vectorPos = y * width + x;
|
|
||||||
|
|
||||||
//printf("dx %f\n", dX);
|
|
||||||
|
|
||||||
vectorField[vectorPos].x = dX;
|
|
||||||
vectorField[vectorPos].y = dY;
|
|
||||||
|
|
||||||
//vectorField[vectorPos].x = -dY;
|
|
||||||
//vectorField[vectorPos].y = dX;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------- normalize the vectors ------------------------------------
|
|
||||||
|
|
||||||
// variables for the maximum magnitude (absolute) in x and y
|
|
||||||
float maxMagX = 1.0;
|
|
||||||
float maxMagY = 1.0;
|
|
||||||
|
|
||||||
// loop through the vector field to find the maximum x and y values
|
|
||||||
for(int i=0; i< vectorCount; i++){
|
|
||||||
|
|
||||||
if(fabs(vectorField[i].x) > maxMagX) maxMagX = fabs(vectorField[i].x);
|
|
||||||
if(fabs(vectorField[i].y) > maxMagY) maxMagY = fabs(vectorField[i].y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop through the vector field to normalize the values
|
|
||||||
for(int i=0; i< vectorCount; i++){
|
|
||||||
|
|
||||||
vectorField[i].x /= maxMagX;
|
|
||||||
vectorField[i].y /= maxMagY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// COMMENTING OUT THE FILLER SYNTH ALGORITHM
|
|
||||||
/*
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
@@ -247,6 +129,16 @@ void ColorSingleAnalysis::synthesise()
|
|||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||||
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
|
//cvGrayImage1 = cvColorImage1;
|
||||||
|
//cvGrayImage2 = cvColorImage2;
|
||||||
|
|
||||||
|
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
|
//cvGrayDiff1.erode();
|
||||||
|
//cvGrayDiff1.contrastStretch();
|
||||||
|
//cvGrayDiff1.blur(5);
|
||||||
|
//cvGrayDiff1.dilate();
|
||||||
|
//cvGrayDiff1.contrastStretch();
|
||||||
|
|
||||||
cvColorImage1.blur(5);
|
cvColorImage1.blur(5);
|
||||||
cvColorImage1.erode();
|
cvColorImage1.erode();
|
||||||
cvColorImage1.erode();
|
cvColorImage1.erode();
|
||||||
@@ -268,27 +160,20 @@ void ColorSingleAnalysis::synthesise()
|
|||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
|
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
|
||||||
|
|
||||||
// This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS?
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
image.setUseTexture(false);
|
||||||
|
|
||||||
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
|
image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
|
||||||
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
||||||
|
|
||||||
//_saved_filenames_synthesis.push_back(_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> ///
|
|
||||||
|
|
||||||
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
@@ -297,23 +182,8 @@ void ColorSingleAnalysis::synthesise()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
void ColorSingleAnalysis::displayresults()
|
void ColorSingleAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
_show_image = true;
|
|
||||||
_image_shown = false;
|
|
||||||
|
|
||||||
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
|
||||||
|
|
||||||
while(!_image_shown){
|
|
||||||
Thread::sleep(2);
|
|
||||||
//cout << "!_image_shown" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
@@ -337,7 +207,6 @@ void ColorSingleAnalysis::displayresults()
|
|||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,6 +217,8 @@ void ColorSingleAnalysis::draw()
|
|||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt < _frame_cnt_max)
|
if (_frame_cnt < _frame_cnt_max)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -493,49 +364,9 @@ void ColorSingleAnalysis::draw()
|
|||||||
case STATE_DISPLAY_RESULTS:
|
case STATE_DISPLAY_RESULTS:
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "case STATE_DISPLAY_RESULTS = true" << endl;
|
|
||||||
|
|
||||||
int width = image1.width;
|
|
||||||
int height = image1.height;
|
|
||||||
float spacing = 10;
|
|
||||||
|
|
||||||
if (_frame_cnt > 2000)
|
|
||||||
{
|
|
||||||
_image_shown = true;
|
|
||||||
_frame_cnt=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_frame_cnt++;
|
|
||||||
|
|
||||||
if (_show_image)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
cout << "_show_image = true" << endl;
|
|
||||||
|
|
||||||
for(int x=0; x<width; x++){
|
|
||||||
|
|
||||||
float xPos = (float) x * spacing + 5;
|
|
||||||
|
|
||||||
for(int y=0; y<height; y++){
|
|
||||||
float yPos = (float)y * spacing + 5;
|
|
||||||
glPushMatrix();
|
|
||||||
ofLine(xPos, yPos, xPos+(vectorField[y*width+x].x*spacing), yPos+(vectorField[y*width+x].y*spacing));
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//this is where we save the full-frame software output to file... after the vectors, etc. are rendered...
|
|
||||||
//saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_RUN_DONE = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
/*
|
|
||||||
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -550,9 +381,9 @@ void ColorSingleAnalysis::draw()
|
|||||||
|
|
||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
ofSetColor(255, 255, 255);
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
}
|
}
|
||||||
@@ -560,11 +391,12 @@ void ColorSingleAnalysis::draw()
|
|||||||
// display results of the synthesis
|
// display results of the synthesis
|
||||||
_RUN_DONE = true;
|
_RUN_DONE = true;
|
||||||
break;
|
break;
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -574,7 +406,40 @@ void ColorSingleAnalysis::save_cb(Timer& timer)
|
|||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "ColorSingleAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name =ofToString(_save_cnt,2)+"_"+fileNameTag+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name =ofToString(_save_cnt,2)+"_"+fileNameTag+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,11 +62,4 @@ protected:
|
|||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
unsigned char * imagePixels;
|
|
||||||
int vectorCount;
|
|
||||||
ofVec2f * vectorField;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+45
-40
@@ -15,12 +15,13 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
|
||||||
|
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_diffnoise", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:diffnoise_shadow", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME DiffNoiseAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME DiffNoiseAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||||
@@ -30,7 +31,7 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
|
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -43,11 +44,8 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
//for an ofxOpenCv.h image i would like to use..."
|
||||||
image2.clear();
|
//image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h);
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
@@ -58,28 +56,9 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -87,9 +66,6 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +77,7 @@ void DiffNoiseAnalysis::acquire()
|
|||||||
_run_cnt++;
|
_run_cnt++;
|
||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -168,19 +144,16 @@ void DiffNoiseAnalysis::synthesise()
|
|||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvColorImage1.width, cvGrayImage1.height, OF_IMAGE_COLOR);
|
//image.allocate(cvColorImage1.width, cvGrayImage1.height, OF_IMAGE_COLOR);
|
||||||
|
|
||||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
image.setUseTexture(false);
|
||||||
|
|
||||||
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
|
image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
|
||||||
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
||||||
|
|
||||||
//_saved_filenames_synthesis.push_back(_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> ///
|
|
||||||
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
// }
|
// }
|
||||||
@@ -430,7 +403,39 @@ void DiffNoiseAnalysis::save_cb(Timer& timer)
|
|||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "DiffNoiseAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,4 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+46
-47
@@ -15,15 +15,15 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void IResponseAnalysis::setup(int camWidth, int camHeight)
|
void IResponseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_iresponse", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
|
||||||
|
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_iresponse", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_iresponse", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
|
||||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
@@ -31,7 +31,7 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
_synth_save_cnt = 0;
|
_synth_save_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -43,12 +43,6 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
|
||||||
image2.clear();
|
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
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
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
@@ -58,28 +52,9 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -88,7 +63,6 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +76,7 @@ void IResponseAnalysis::acquire()
|
|||||||
_run_cnt++;
|
_run_cnt++;
|
||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -149,8 +123,8 @@ void IResponseAnalysis::synthesise()
|
|||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
cvGrayImage1 = cvColorImage1;
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
cvGrayImage2 = cvColorImage2;
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
cvGrayDiff1.erode();
|
cvGrayDiff1.erode();
|
||||||
@@ -170,25 +144,19 @@ void IResponseAnalysis::synthesise()
|
|||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
|
||||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
image.setUseTexture(false);
|
||||||
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
|
||||||
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||||
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
||||||
|
|
||||||
|
|
||||||
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
|
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
||||||
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
|
|
||||||
|
|
||||||
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
|
|
||||||
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,7 +346,7 @@ void IResponseAnalysis::draw()
|
|||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
ofSetColor(255, 255, 255);
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
@@ -401,7 +369,38 @@ void IResponseAnalysis::save_cb(Timer& timer)
|
|||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "IResponseAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,4 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+113
-82
@@ -12,26 +12,18 @@ using Poco::Thread;
|
|||||||
|
|
||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
#define THRESHOLD 80
|
|
||||||
#define MAXBLOBS 15
|
|
||||||
|
|
||||||
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_relaxrate", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
|
||||||
|
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_relaxrate", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_relaxrate", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME RelaxRateAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME RelaxRateAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
_threshold = RefractiveIndex::XML.getValue("config:relaxrate:threshold", THRESHOLD);
|
|
||||||
cout << "THRESHOLD RelaxRateAnalysis " << _threshold << endl;
|
|
||||||
|
|
||||||
_maxblobs = RefractiveIndex::XML.getValue("config:relaxrate:maxblobs", MAXBLOBS);
|
|
||||||
cout << "MAXBLOBS RelaxRateAnalysis " << _maxblobs << endl;
|
|
||||||
|
|
||||||
|
|
||||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
@@ -39,7 +31,7 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
|
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_level = 0;
|
_level = 0;
|
||||||
@@ -54,19 +46,26 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.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
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
// images used for re-loading and saving out the synthesized files ///
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
image3.setUseTexture(false);
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
image4.setUseTexture(false);
|
||||||
cvColorImage1.clear();
|
image5.setUseTexture(false);
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
||||||
|
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ void RelaxRateAnalysis::acquire()
|
|||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
|
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -102,28 +101,60 @@ void RelaxRateAnalysis::synthesise()
|
|||||||
//cout << "IResponseAnalysis::saving synthesis...\n";
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
cvContourFinderVect.clear();
|
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
||||||
|
|
||||||
|
//cout << "IResponseAnalysis::synthesis FOR LOOP...\n";
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
|
//couldn't load image
|
||||||
|
cout << "didn't load image" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
|
//cout << "LOADED image1!!!" << endl;
|
||||||
|
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 //////////////////////////
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayDiff1, 1);
|
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
cvGrayDiff1.threshold(_threshold);
|
cvGrayImage1 = cvColorImage1;
|
||||||
|
cvGrayImage2 = cvColorImage2;
|
||||||
|
|
||||||
rfiCvContourFinder* cf = new rfiCvContourFinder();
|
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
|
cvGrayDiff1.erode();
|
||||||
|
cvGrayDiff1.contrastStretch();
|
||||||
|
cvGrayDiff1.blur(5);
|
||||||
|
|
||||||
cf->findContours(cvGrayDiff1, 20, (image1.width * image1.height) / 4, _maxblobs, true);
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
|
string file_name;
|
||||||
|
|
||||||
cvContourFinderVect.push_back(cf);
|
file_name = ofToString(_synth_save_cnt, 2)+"_RelaxRateAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
ofImage image;
|
||||||
|
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
|
||||||
|
//*** 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);
|
||||||
|
_synth_save_cnt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,39 +167,30 @@ void RelaxRateAnalysis::synthesise()
|
|||||||
void RelaxRateAnalysis::displayresults()
|
void RelaxRateAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
|
|
||||||
//cvContourFinderVectDisplay.clear();
|
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
||||||
clearcfindervectdisplay();
|
|
||||||
|
|
||||||
for(int i=1;i<cvContourFinderVect.size();i++){
|
|
||||||
|
|
||||||
if(_state == STATE_STOP){
|
|
||||||
clearcfindervectdisplay();
|
|
||||||
clearcfindervect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
||||||
|
|
||||||
while(!_image_shown){
|
while(!_image_shown){
|
||||||
Thread::sleep(2);
|
Thread::sleep(2);
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
cvContourFinderVectDisplay.push_back(cvContourFinderVect[i]);
|
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
||||||
_show_image = true;
|
//couldn't load image
|
||||||
_image_shown = false;
|
// cout << "didn't load image" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
||||||
|
image3.loadImage(_saved_filenames_synthesis[i]);
|
||||||
|
//cout << "_show_image = true;" << endl;
|
||||||
|
_show_image = true;
|
||||||
|
_image_shown = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearcfindervectdisplay();
|
|
||||||
clearcfindervect();
|
|
||||||
|
|
||||||
|
|
||||||
//cvContourFinderVectDisplay.clear();
|
|
||||||
//cvContourFinderVect.clear();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +202,9 @@ void RelaxRateAnalysis::draw()
|
|||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
|
/// *** TODO *** ///
|
||||||
|
// still need to deal with latency frames here - i.e.: there are frames
|
||||||
|
/// *** TODO *** ///
|
||||||
|
|
||||||
if (_frame_cnt < _frame_cnt_max)
|
if (_frame_cnt < _frame_cnt_max)
|
||||||
{
|
{
|
||||||
@@ -211,7 +235,6 @@ void RelaxRateAnalysis::draw()
|
|||||||
|
|
||||||
case STATE_SYNTHESISING:
|
case STATE_SYNTHESISING:
|
||||||
{
|
{
|
||||||
|
|
||||||
// display animation of something while the synthesis in on-going...
|
// display animation of something while the synthesis in on-going...
|
||||||
|
|
||||||
//cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n";
|
//cout << "RelaxRateAnalysis = STATE_SYNTHESISING...\n";
|
||||||
@@ -264,7 +287,7 @@ void RelaxRateAnalysis::draw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//cout << "_anim_cnt = " << _anim_cnt << endl;
|
cout << "_anim_cnt = " << _anim_cnt << endl;
|
||||||
|
|
||||||
if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) {
|
if (_anim_cnt > (_anim_cnt_max-_fade_in_frames) && _anim_cnt <= _anim_cnt_max) {
|
||||||
|
|
||||||
@@ -312,10 +335,15 @@ void RelaxRateAnalysis::draw()
|
|||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
{
|
||||||
for(int i=0;i<cvContourFinderVectDisplay.size();i++){
|
//cout << "_show_image...\n" << endl;
|
||||||
cvContourFinderVectDisplay[i]->draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
|
||||||
|
ofSetColor(255, 255, 255);
|
||||||
|
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
|
ofDisableAlphaBlending();
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
// display results of the synthesis
|
||||||
@@ -335,34 +363,37 @@ void RelaxRateAnalysis::save_cb(Timer& timer)
|
|||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
//cout << "RelaxRateAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
+20
-15
@@ -5,12 +5,8 @@
|
|||||||
|
|
||||||
#include "Poco/Timer.h"
|
#include "Poco/Timer.h"
|
||||||
|
|
||||||
#include "rfiCvContourFinder.h"
|
|
||||||
|
|
||||||
#include "ofxOpenCv.h"
|
#include "ofxOpenCv.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RelaxRateAnalysis : public AbstractAnalysis
|
class RelaxRateAnalysis : public AbstractAnalysis
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -23,7 +19,6 @@ public:
|
|||||||
void acquire();
|
void acquire();
|
||||||
void synthesise();
|
void synthesise();
|
||||||
void displayresults();
|
void displayresults();
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
@@ -31,24 +26,34 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void clearcfindervect();
|
|
||||||
void clearcfindervectdisplay();
|
|
||||||
|
|
||||||
bool _RUN_DONE;
|
bool _RUN_DONE;
|
||||||
float _flip, _level;
|
float _flip, _level;
|
||||||
int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt;
|
int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt;
|
||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
int _threshold;
|
|
||||||
int _maxblobs;
|
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
ofImage image1;
|
||||||
|
ofImage image2;
|
||||||
|
ofImage image3;
|
||||||
|
ofImage image4;
|
||||||
|
ofImage image5;
|
||||||
|
ofImage image6;
|
||||||
|
|
||||||
ofImage image1;
|
|
||||||
ofxCvColorImage cvColorImage1;
|
ofxCvColorImage cvColorImage1;
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
ofxCvColorImage cvColorImage2;
|
||||||
|
ofxCvColorImage cvColorImage3;
|
||||||
|
ofxCvColorImage cvColorImage4;
|
||||||
|
ofxCvColorImage cvColorImage5;
|
||||||
|
ofxCvColorImage cvColorImage6;
|
||||||
|
|
||||||
vector<rfiCvContourFinder*> cvContourFinderVect;
|
ofxCvGrayscaleImage cvGrayDiff1;
|
||||||
vector<rfiCvContourFinder*> cvContourFinderVectDisplay;
|
ofxCvGrayscaleImage cvGrayDiff2;
|
||||||
|
|
||||||
|
ofxCvGrayscaleImage cvGrayImage1;
|
||||||
|
ofxCvGrayscaleImage cvGrayImage2;
|
||||||
|
ofxCvGrayscaleImage cvGrayImage3;
|
||||||
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shadowscapes", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shadowscapes", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_shadowscapes", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ShadowScapesAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ShadowScapesAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
int screenSpan;
|
int screenSpan;
|
||||||
@@ -39,6 +39,8 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
DELTA_T_SAVE = 3*(10*acq_run_time/2); // for 20 seconds, we want this to be around 100 files
|
DELTA_T_SAVE = 3*(10*acq_run_time/2); // for 20 seconds, we want this to be around 100 files
|
||||||
// or 5 times per second = every 200 ms
|
// or 5 times per second = every 200 ms
|
||||||
|
//DELTA_T_SAVE = 1;
|
||||||
|
//create_dir(); // this makes both synth and analysis folder structures
|
||||||
|
|
||||||
_scanLineWidth = 100.0;
|
_scanLineWidth = 100.0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
@@ -51,12 +53,6 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
|
||||||
image2.clear();
|
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
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
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
@@ -66,28 +62,9 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -95,9 +72,6 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowScapesAnalysis::acquire()
|
void ShadowScapesAnalysis::acquire()
|
||||||
@@ -111,22 +85,26 @@ void ShadowScapesAnalysis::acquire()
|
|||||||
_line = 0;
|
_line = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
|
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
|
//cout << "RUN NUM = " << i;
|
||||||
|
|
||||||
save_timer.start(save_callback);
|
save_timer.start(save_callback);
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(3);
|
Thread::sleep(3);
|
||||||
|
|
||||||
save_timer.stop();
|
save_timer.stop();
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowScapesAnalysis::synthesise()
|
void ShadowScapesAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
//cout << "ShadowScapesAnalysis::saving synthesis...\n";
|
//cout << "ShadowScapesAnalysis::saving synthesis...\n";
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1; i++){
|
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
||||||
|
|
||||||
// cout << "ShadowScapesAnalysis::synthesis FOR LOOP...\n";
|
// cout << "ShadowScapesAnalysis::synthesis FOR LOOP...\n";
|
||||||
|
|
||||||
@@ -148,11 +126,8 @@ void ShadowScapesAnalysis::synthesise()
|
|||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
cvGrayImage1 = cvColorImage1;
|
||||||
//cvGrayImage2 = cvColorImage2;
|
cvGrayImage2 = cvColorImage2;
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
cvGrayDiff1.erode();
|
cvGrayDiff1.erode();
|
||||||
@@ -176,28 +151,24 @@ void ShadowScapesAnalysis::synthesise()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
|
||||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
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);
|
image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
||||||
|
|
||||||
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
|
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
||||||
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
|
|
||||||
|
|
||||||
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,6 +205,41 @@ void ShadowScapesAnalysis::displayresults()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// THE OLD SHIT ///
|
||||||
|
/*
|
||||||
|
for(float i=1;i<_saved_filenames_synthesis.size()-1;i++){
|
||||||
|
|
||||||
|
// cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
||||||
|
|
||||||
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
|
while(!_image_shown){
|
||||||
|
Thread::sleep(2);
|
||||||
|
//cout << "!_image_shown" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_synthesis[i])){
|
||||||
|
//couldn't load image
|
||||||
|
cout << "didn't load image" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
|
|
||||||
|
image1.loadImage(_saved_filenames_analysis[i]);
|
||||||
|
cout << "loaded filenames[i] - " << _saved_filenames_analysis[i] << endl;
|
||||||
|
|
||||||
|
image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//cout << "_show_image = true;" << endl;
|
||||||
|
_show_image = true;
|
||||||
|
_image_shown = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -413,6 +419,7 @@ void ShadowScapesAnalysis::draw()
|
|||||||
{
|
{
|
||||||
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -428,8 +435,7 @@ void ShadowScapesAnalysis::draw()
|
|||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
ofSetColor(255, 255, 255);
|
||||||
|
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
@@ -439,9 +445,6 @@ void ShadowScapesAnalysis::draw()
|
|||||||
|
|
||||||
// display results of the synthesis
|
// display results of the synthesis
|
||||||
_RUN_DONE = true;
|
_RUN_DONE = true;
|
||||||
|
|
||||||
// clear allocated memory...?
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,6 +460,17 @@ void ShadowScapesAnalysis::save_cb(Timer& timer)
|
|||||||
|
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "ShadowScapesAnalysis::saving analysis...\n";
|
||||||
|
|
||||||
string file_name;
|
string file_name;
|
||||||
|
|
||||||
if(_dir == H) {
|
if(_dir == H) {
|
||||||
@@ -471,6 +485,26 @@ void ShadowScapesAnalysis::save_cb(Timer& timer)
|
|||||||
file_name = ofToString(_save_cnt, 2)+"_D_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
file_name = ofToString(_save_cnt, 2)+"_D_"+ofToString(_line, 2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,4 @@ protected:
|
|||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -15,15 +15,16 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shapefromshading", NUMBER_RUNS);
|
|
||||||
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
|
||||||
|
// NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shapefromshading", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_shapefromshading", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ShapeFromShadingAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ShapeFromShadingAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
|
||||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
@@ -31,7 +32,7 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
_frame_cnt_max = acq_run_time*ofGetFrameRate(); // e.g.: 30 frames per second * 20 seconds = 600 frames
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
_synth_save_cnt = 0;
|
_synth_save_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -40,15 +41,10 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
|||||||
int anim_time = 5; // 10 seconds
|
int anim_time = 5; // 10 seconds
|
||||||
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
|
_anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames
|
||||||
|
|
||||||
|
|
||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
|
||||||
image2.clear();
|
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
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
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
@@ -58,28 +54,9 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
// cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -88,8 +65,6 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +78,7 @@ void ShapeFromShadingAnalysis::acquire()
|
|||||||
_run_cnt++;
|
_run_cnt++;
|
||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0, _synth_save_cnt = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
_animation_cnt1 = 0;
|
_animation_cnt1 = 0;
|
||||||
_animation_cnt2 = 0;
|
_animation_cnt2 = 0;
|
||||||
@@ -169,8 +144,8 @@ void ShapeFromShadingAnalysis::synthesise()
|
|||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
cvGrayImage1 = cvColorImage1;
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
cvGrayImage2 = cvColorImage2;
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
cvGrayDiff1.erode();
|
cvGrayDiff1.erode();
|
||||||
@@ -188,23 +163,18 @@ void ShapeFromShadingAnalysis::synthesise()
|
|||||||
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
|
||||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
image.setUseTexture(false);
|
||||||
|
|
||||||
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||||
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
||||||
|
|
||||||
//_saved_filenames_synthesis.push_back(_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);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -567,7 +537,7 @@ void ShapeFromShadingAnalysis::draw()
|
|||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
ofSetColor(255, 255, 255);
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
@@ -592,7 +562,39 @@ void ShapeFromShadingAnalysis::save_cb(Timer& timer)
|
|||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "ShapeFromShadingAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ quad +"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ quad +"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,8 +78,4 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+46
-48
@@ -15,12 +15,13 @@ using Poco::Thread;
|
|||||||
|
|
||||||
void StrobeAnalysis::setup(int camWidth, int camHeight)
|
void StrobeAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_strobe", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis:NUM_RUN", NUMBER_RUNS);
|
||||||
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
|
||||||
|
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_strobe", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis:acquiretime_strobe", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME StrobeAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME StrobeAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
||||||
@@ -34,7 +35,7 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
// The British Health and Safety Executive recommend that a net flash rate for a bank of strobe lights does not exceed 5 flashes per second, at which only 5% of photosensitive epileptics are at risk. It also recommends that no strobing effect continue for more than 30 seconds, due to the potential for discomfort and disorientation.
|
// The British Health and Safety Executive recommend that a net flash rate for a bank of strobe lights does not exceed 5 flashes per second, at which only 5% of photosensitive epileptics are at risk. It also recommends that no strobing effect continue for more than 30 seconds, due to the potential for discomfort and disorientation.
|
||||||
|
|
||||||
//create_dir_allocate_images();
|
//create_dir();
|
||||||
_synth_save_cnt = 0;
|
_synth_save_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
|
|
||||||
@@ -44,12 +45,6 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
|
||||||
image2.clear();
|
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// 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
|
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
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
@@ -59,28 +54,9 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.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_w " << RefractiveIndex::_vid_w << endl;
|
||||||
// cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << 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();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -89,8 +65,6 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +77,7 @@ void StrobeAnalysis::acquire()
|
|||||||
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _strobe_cnt = 0, _synth_save_cnt = 0;
|
_frame_cnt = 0; _save_cnt = 0; _anim_cnt = 0; _strobe_cnt = 0, _synth_save_cnt = 0;
|
||||||
_run_cnt++;
|
_run_cnt++;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
create_dir_allocate_images();
|
create_dir();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -151,8 +125,8 @@ void StrobeAnalysis::synthesise()
|
|||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
cvGrayImage1 = cvColorImage1;
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
cvGrayImage2 = cvColorImage2;
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
cvGrayDiff1.dilate();
|
cvGrayDiff1.dilate();
|
||||||
@@ -170,26 +144,18 @@ void StrobeAnalysis::synthesise()
|
|||||||
|
|
||||||
|
|
||||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
//ofImage image;
|
ofImage image;
|
||||||
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
|
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
|
||||||
|
|
||||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
//image.setUseTexture(false);
|
image.setUseTexture(false);
|
||||||
|
|
||||||
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height,OF_IMAGE_GRAYSCALE);
|
image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height,OF_IMAGE_GRAYSCALE);
|
||||||
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
image.saveImage(_whole_file_path_synthesis+"/"+file_name);
|
||||||
|
|
||||||
//_saved_filenames_synthesis.push_back(_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);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,7 +362,7 @@ void StrobeAnalysis::draw()
|
|||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
ofSetColor(255, 255, 255);
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
@@ -421,7 +387,39 @@ void StrobeAnalysis::save_cb(Timer& timer)
|
|||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout << "StrobeAnalysis::saving...\n";
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(_strobe_on) +"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(_strobe_on) +"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
|
||||||
|
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
|
||||||
|
//ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
|
|
||||||
|
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||||
|
unsigned char * somePixels;
|
||||||
|
ofPixels appPix = RefractiveIndex::_pixels;
|
||||||
|
somePixels = new unsigned char [appPix.getWidth()*appPix.getHeight()*3];
|
||||||
|
somePixels = appPix.getPixels();
|
||||||
|
|
||||||
|
ofImage myImage;
|
||||||
|
//myImage.allocate(appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||||
|
myImage.setUseTexture(false);
|
||||||
|
|
||||||
|
myImage.setFromPixels(somePixels,appPix.getWidth(),appPix.getHeight(), OF_IMAGE_COLOR);
|
||||||
|
myImage.saveImage(ofToDataPath("")+ _whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
|
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,4 @@ protected:
|
|||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,211 +0,0 @@
|
|||||||
|
|
||||||
#include "rfiCvContourFinder.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
static bool sort_carea_compare( const CvSeq* a, const CvSeq* b) {
|
|
||||||
// use opencv to calc size, then sort based on size
|
|
||||||
float areaa = fabs(cvContourArea(a, CV_WHOLE_SEQ));
|
|
||||||
float areab = fabs(cvContourArea(b, CV_WHOLE_SEQ));
|
|
||||||
|
|
||||||
//return 0;
|
|
||||||
return (areaa > areab);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
rfiCvContourFinder::rfiCvContourFinder() {
|
|
||||||
_width = 0;
|
|
||||||
_height = 0;
|
|
||||||
myMoments = (CvMoments*)malloc( sizeof(CvMoments) );
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
rfiCvContourFinder::~rfiCvContourFinder() {
|
|
||||||
free( myMoments );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
void rfiCvContourFinder::reset() {
|
|
||||||
cvSeqBlobs.clear();
|
|
||||||
blobs.clear();
|
|
||||||
nBlobs = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
int rfiCvContourFinder::findContours( ofxCvGrayscaleImage& input,
|
|
||||||
int minArea,
|
|
||||||
int maxArea,
|
|
||||||
int nConsidered,
|
|
||||||
bool bFindHoles,
|
|
||||||
bool bUseApproximation) {
|
|
||||||
|
|
||||||
// get width/height disregarding ROI
|
|
||||||
IplImage* ipltemp = input.getCvImage();
|
|
||||||
_width = ipltemp->width;
|
|
||||||
_height = ipltemp->height;
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
// opencv will clober the image it detects contours on, so we want to
|
|
||||||
// copy it into a copy before we detect contours. That copy is allocated
|
|
||||||
// if necessary (necessary = (a) not allocated or (b) wrong size)
|
|
||||||
// so be careful if you pass in different sized images to "findContours"
|
|
||||||
// there is a performance penalty, but we think there is not a memory leak
|
|
||||||
// to worry about better to create mutiple contour finders for different
|
|
||||||
// sizes, ie, if you are finding contours in a 640x480 image but also a
|
|
||||||
// 320x240 image better to make two rfiCvContourFinder objects then to use
|
|
||||||
// one, because you will get penalized less.
|
|
||||||
|
|
||||||
if( inputCopy.getWidth() == 0 ) {
|
|
||||||
inputCopy.setUseTexture(false);
|
|
||||||
inputCopy.allocate( _width, _height );
|
|
||||||
} else if( inputCopy.getWidth() != _width || inputCopy.getHeight() != _height ) {
|
|
||||||
// reallocate to new size
|
|
||||||
inputCopy.clear();
|
|
||||||
inputCopy.setUseTexture(false);
|
|
||||||
inputCopy.allocate( _width, _height );
|
|
||||||
}
|
|
||||||
|
|
||||||
inputCopy.setROI( input.getROI() );
|
|
||||||
inputCopy = input;
|
|
||||||
|
|
||||||
CvSeq* contour_list = NULL;
|
|
||||||
contour_storage = cvCreateMemStorage( 1000 );
|
|
||||||
storage = cvCreateMemStorage( 1000 );
|
|
||||||
|
|
||||||
CvContourRetrievalMode retrieve_mode
|
|
||||||
= (bFindHoles) ? CV_RETR_LIST : CV_RETR_EXTERNAL;
|
|
||||||
cvFindContours( inputCopy.getCvImage(), contour_storage, &contour_list,
|
|
||||||
sizeof(CvContour), retrieve_mode, bUseApproximation ? CV_CHAIN_APPROX_SIMPLE : CV_CHAIN_APPROX_NONE );
|
|
||||||
CvSeq* contour_ptr = contour_list;
|
|
||||||
|
|
||||||
// put the contours from the linked list, into an array for sorting
|
|
||||||
while( (contour_ptr != NULL) ) {
|
|
||||||
float area = fabs( cvContourArea(contour_ptr, CV_WHOLE_SEQ) );
|
|
||||||
if( (area > minArea) && (area < maxArea) ) {
|
|
||||||
cvSeqBlobs.push_back(contour_ptr);
|
|
||||||
}
|
|
||||||
contour_ptr = contour_ptr->h_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// sort the pointers based on size
|
|
||||||
if( cvSeqBlobs.size() > 1 ) {
|
|
||||||
sort( cvSeqBlobs.begin(), cvSeqBlobs.end(), sort_carea_compare );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// now, we have cvSeqBlobs.size() contours, sorted by size in the array
|
|
||||||
// cvSeqBlobs let's get the data out and into our structures that we like
|
|
||||||
for( int i = 0; i < MIN(nConsidered, (int)cvSeqBlobs.size()); i++ ) {
|
|
||||||
blobs.push_back( ofxCvBlob() );
|
|
||||||
float area = cvContourArea( cvSeqBlobs[i], CV_WHOLE_SEQ );
|
|
||||||
CvRect rect = cvBoundingRect( cvSeqBlobs[i], 0 );
|
|
||||||
cvMoments( cvSeqBlobs[i], myMoments );
|
|
||||||
|
|
||||||
blobs[i].area = fabs(area);
|
|
||||||
blobs[i].hole = area < 0 ? true : false;
|
|
||||||
blobs[i].length = cvArcLength(cvSeqBlobs[i]);
|
|
||||||
blobs[i].boundingRect.x = rect.x;
|
|
||||||
blobs[i].boundingRect.y = rect.y;
|
|
||||||
blobs[i].boundingRect.width = rect.width;
|
|
||||||
blobs[i].boundingRect.height = rect.height;
|
|
||||||
blobs[i].centroid.x = (myMoments->m10 / myMoments->m00);
|
|
||||||
blobs[i].centroid.y = (myMoments->m01 / myMoments->m00);
|
|
||||||
|
|
||||||
// get the points for the blob:
|
|
||||||
CvPoint pt;
|
|
||||||
CvSeqReader reader;
|
|
||||||
cvStartReadSeq( cvSeqBlobs[i], &reader, 0 );
|
|
||||||
|
|
||||||
for( int j=0; j < cvSeqBlobs[i]->total; j++ ) {
|
|
||||||
CV_READ_SEQ_ELEM( pt, reader );
|
|
||||||
blobs[i].pts.push_back( ofPoint((float)pt.x, (float)pt.y) );
|
|
||||||
}
|
|
||||||
blobs[i].nPts = blobs[i].pts.size();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
nBlobs = blobs.size();
|
|
||||||
|
|
||||||
// Free the storage memory.
|
|
||||||
// Warning: do this inside this function otherwise a strange memory leak
|
|
||||||
if( contour_storage != NULL ) { cvReleaseMemStorage(&contour_storage); }
|
|
||||||
if( storage != NULL ) { cvReleaseMemStorage(&storage); }
|
|
||||||
|
|
||||||
return nBlobs;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
void rfiCvContourFinder::draw( float x, float y, float w, float h ) {
|
|
||||||
|
|
||||||
float scalex = 0.0f;
|
|
||||||
float scaley = 0.0f;
|
|
||||||
if( _width != 0 ) { scalex = w/_width; } else { scalex = 1.0f; }
|
|
||||||
if( _height != 0 ) { scaley = h/_height; } else { scaley = 1.0f; }
|
|
||||||
|
|
||||||
if(bAnchorIsPct){
|
|
||||||
x -= anchor.x * w;
|
|
||||||
y -= anchor.y * h;
|
|
||||||
}else{
|
|
||||||
x -= anchor.x;
|
|
||||||
y -= anchor.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
ofPushStyle();
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef( x, y, 0.0 );
|
|
||||||
glScalef( scalex, scaley, 0.0 );
|
|
||||||
ofSetHexColor(0xFFFFFF);
|
|
||||||
|
|
||||||
for( int i=0; i<(int)blobs.size(); i++ ) {
|
|
||||||
ofNoFill();
|
|
||||||
ofBeginShape();
|
|
||||||
for( int j=0; j<blobs[i].nPts; j++ ) {
|
|
||||||
ofVertex( blobs[i].pts[j].x, blobs[i].pts[j].y );
|
|
||||||
}
|
|
||||||
ofEndShape();
|
|
||||||
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
ofPopStyle();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------
|
|
||||||
void rfiCvContourFinder::draw(const ofPoint & point){
|
|
||||||
draw(point.x, point.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------
|
|
||||||
void rfiCvContourFinder::draw(const ofRectangle & rect){
|
|
||||||
draw(rect.x, rect.y, rect.width, rect.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
void rfiCvContourFinder::setAnchorPercent( float xPct, float yPct ){
|
|
||||||
anchor.x = xPct;
|
|
||||||
anchor.y = yPct;
|
|
||||||
bAnchorIsPct = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
void rfiCvContourFinder::setAnchorPoint( int x, int y ){
|
|
||||||
anchor.x = x;
|
|
||||||
anchor.y = y;
|
|
||||||
bAnchorIsPct = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
void rfiCvContourFinder::resetAnchor(){
|
|
||||||
anchor.set(0,0);
|
|
||||||
bAnchorIsPct = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* rfiCvContourFinder.h
|
|
||||||
*
|
|
||||||
* Finds white blobs in binary images and identifies
|
|
||||||
* centroid, bounding box, area, length and polygonal contour
|
|
||||||
* The result is placed in a vector of ofxCvBlob objects.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RFI_CV_CONTOUR_FINDER
|
|
||||||
#define RFI_CV_CONTOUR_FINDER
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "ofxCvConstants.h"
|
|
||||||
#include "ofxCvBlob.h"
|
|
||||||
#include "ofxCvGrayscaleImage.h"
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
class rfiCvContourFinder : public ofBaseDraws {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
vector<ofxCvBlob> blobs;
|
|
||||||
int nBlobs; // DEPRECATED: use blobs.size() instead
|
|
||||||
|
|
||||||
|
|
||||||
rfiCvContourFinder();
|
|
||||||
virtual ~rfiCvContourFinder();
|
|
||||||
|
|
||||||
virtual float getWidth() { return _width; }; //set after first findContours call
|
|
||||||
virtual float getHeight() { return _height; }; //set after first findContours call
|
|
||||||
|
|
||||||
virtual int findContours( ofxCvGrayscaleImage& input,
|
|
||||||
int minArea, int maxArea,
|
|
||||||
int nConsidered, bool bFindHoles,
|
|
||||||
bool bUseApproximation = true);
|
|
||||||
// approximation = don't do points for all points
|
|
||||||
// of the contour, if the contour runs
|
|
||||||
// along a straight line, for example...
|
|
||||||
|
|
||||||
virtual void draw() { draw(0,0, _width, _height); };
|
|
||||||
virtual void draw( float x, float y ) { draw(x,y, _width, _height); };
|
|
||||||
virtual void draw( float x, float y, float w, float h );
|
|
||||||
virtual void draw(const ofPoint & point);
|
|
||||||
virtual void draw(const ofRectangle & rect);
|
|
||||||
virtual void setAnchorPercent(float xPct, float yPct);
|
|
||||||
virtual void setAnchorPoint(int x, int y);
|
|
||||||
virtual void resetAnchor();
|
|
||||||
//virtual ofxCvBlob getBlob(int num);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
int _width;
|
|
||||||
int _height;
|
|
||||||
ofxCvGrayscaleImage inputCopy;
|
|
||||||
CvMemStorage* contour_storage;
|
|
||||||
CvMemStorage* storage;
|
|
||||||
CvMoments* myMoments;
|
|
||||||
vector<CvSeq*> cvSeqBlobs; //these will become blobs
|
|
||||||
|
|
||||||
ofPoint anchor;
|
|
||||||
bool bAnchorIsPct;
|
|
||||||
|
|
||||||
virtual void reset();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user