Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 97e24c31f2 | |||
| f66ce7e2e8 | |||
| 7d7ec3606e |
+2
-1
@@ -1,6 +1,7 @@
|
||||
<!-- THIS FILE NEEDS TO GO IN THE APPLICATION /data/ folder -->
|
||||
|
||||
<config>
|
||||
<mode>drawing</mode>
|
||||
<camera>
|
||||
<id>1</id>
|
||||
<width>640</width>
|
||||
@@ -38,7 +39,7 @@
|
||||
</analysis_time>
|
||||
|
||||
<relaxrate>
|
||||
<threshold>51</threshold>
|
||||
<treshold>51</treshold>
|
||||
<maxblobs>25</maxblobs>
|
||||
</relaxrate>
|
||||
|
||||
|
||||
@@ -3,10 +3,32 @@
|
||||
#include "AbstractAnalysis.h"
|
||||
#include "RefractiveIndex.h"
|
||||
#include "ofxFileHelper.h"
|
||||
#include "ofSystemUtils.h"
|
||||
|
||||
void AbstractAnalysis::setup(int camWidth, int camHeight) {
|
||||
|
||||
_cam_w = camWidth; _cam_h = camHeight;
|
||||
|
||||
if(RefractiveIndex::_mode == MODE_DRAWING) {
|
||||
ofFileDialogResult r = ofSystemLoadDialog("choooose da folda", true);
|
||||
if(!r.bSuccess) {
|
||||
ofSystemAlertDialog("OOOOPS.... ERROR...");
|
||||
return;
|
||||
}
|
||||
|
||||
_whole_file_path_analysis = r.filePath;
|
||||
_whole_file_path_synthesis = r.filePath + "/darwings";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// this is the main threaded loop for a given analysis
|
||||
void AbstractAnalysis::do_synthesize() {
|
||||
|
||||
switch(RefractiveIndex::_mode)
|
||||
{
|
||||
case MODE_ANALYSING:
|
||||
{
|
||||
for(int i = 0; i < NUM_RUN; i++) {
|
||||
|
||||
cout << "NUM_RUN: " << i << endl;
|
||||
@@ -24,10 +46,29 @@ void AbstractAnalysis::do_synthesize() {
|
||||
displayresults();
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
case MODE_DRAWING:
|
||||
{
|
||||
ofxFileHelper fileHelperDrawing;
|
||||
if(!fileHelperDrawing.doesDirectoryExist(_whole_file_path_synthesis)){
|
||||
fileHelperDrawing.makeDirectory(_whole_file_path_synthesis);
|
||||
}
|
||||
|
||||
read_dir_create_list(_whole_file_path_analysis);
|
||||
_state = STATE_SYNTHESISING;
|
||||
synthesise();
|
||||
if(_state == STATE_STOP) goto exit;
|
||||
_state = STATE_DISPLAY_RESULTS;
|
||||
displayresults();
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
cleanup();
|
||||
ofNotifyEvent(_synthesize_cb, _name);
|
||||
|
||||
}
|
||||
|
||||
void AbstractAnalysis::create_dir_allocate_images()
|
||||
@@ -116,6 +157,57 @@ void AbstractAnalysis::create_dir_allocate_images()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool cmp_file(string f0, string f1)
|
||||
|
||||
{
|
||||
|
||||
int v0 = atoi(f0.substr(0, f0.find("_")).c_str());
|
||||
|
||||
int v1 = atoi(f1.substr(0, f1.find("_")).c_str());
|
||||
|
||||
return v0 < v1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AbstractAnalysis::read_dir_create_list(string folder_path)
|
||||
|
||||
{
|
||||
|
||||
File dir(folder_path);
|
||||
|
||||
|
||||
|
||||
if(dir.exists() && dir.isDirectory()) {
|
||||
|
||||
vector<string> list;
|
||||
|
||||
dir.list(list);
|
||||
|
||||
|
||||
|
||||
std::sort(list.begin(), list.end(), cmp_file);
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
|
||||
string filepath = folder_path + "/" + list[i];
|
||||
|
||||
_saved_filenames_analysis.push_back(filepath);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AbstractAnalysis::saveImageAnalysis(string filename)
|
||||
{
|
||||
|
||||
@@ -181,5 +273,6 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
|
||||
|
||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+filename);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
virtual ~AbstractAnalysis(){;}
|
||||
|
||||
// generic function to set up the camera
|
||||
virtual void setup(int camWidth, int camHeight){_cam_w = camWidth; _cam_h = camHeight;}
|
||||
virtual void setup(int camWidth, int camHeight);
|
||||
|
||||
// this is the main threaded loop for a given analysis
|
||||
void do_synthesize();
|
||||
@@ -37,6 +37,8 @@ protected:
|
||||
|
||||
virtual void create_dir_allocate_images();
|
||||
|
||||
virtual void read_dir_create_list(string folder_path);
|
||||
|
||||
virtual void saveImageAnalysis(string filename);
|
||||
virtual void saveImageSynthesis(string filename, ofxCvImage* newPixels, ofImageType newType);
|
||||
|
||||
@@ -55,6 +57,7 @@ protected:
|
||||
|
||||
public:
|
||||
string _name;
|
||||
string _draw_directory;
|
||||
|
||||
// event
|
||||
ofEvent<string> _synthesize_cb;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_camnoise", NUMBER_RUNS);
|
||||
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -14,6 +14,8 @@ using Poco::Thread;
|
||||
|
||||
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colormulti", NUMBER_RUNS);
|
||||
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
@@ -246,6 +248,8 @@ void ColorMultiAnalysis::draw()
|
||||
//cout << "FADING IN..." << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (_frame_cnt >= _fade_in_frames && _frame_cnt < _frame_cnt_max-_fade_in_frames){
|
||||
|
||||
aColor.setHsb(c, 255, 255);
|
||||
|
||||
+10
-155
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colorsingle", NUMBER_RUNS);
|
||||
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
@@ -124,6 +126,7 @@ void ColorSingleAnalysis::acquire()
|
||||
|
||||
save_timer->stop();
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -136,103 +139,11 @@ void ColorSingleAnalysis::synthesise()
|
||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
||||
|
||||
//cout << "ColorSingleAnalysis::synthesis FOR LOOP...\n";
|
||||
|
||||
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
||||
|
||||
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])){
|
||||
//couldn't load image
|
||||
cout << "didn't load image" << endl;
|
||||
@@ -271,7 +182,7 @@ void ColorSingleAnalysis::synthesise()
|
||||
//ofImage image;
|
||||
//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.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
|
||||
@@ -285,10 +196,7 @@ void ColorSingleAnalysis::synthesise()
|
||||
_synth_save_cnt++;
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||
@@ -297,23 +205,8 @@ void ColorSingleAnalysis::synthesise()
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
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++){
|
||||
|
||||
if(_state == STATE_STOP) return;
|
||||
@@ -337,7 +230,6 @@ void ColorSingleAnalysis::displayresults()
|
||||
_image_shown = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -348,6 +240,8 @@ void ColorSingleAnalysis::draw()
|
||||
switch (_state) {
|
||||
case STATE_ACQUIRING:
|
||||
{
|
||||
|
||||
|
||||
if (_frame_cnt < _frame_cnt_max)
|
||||
{
|
||||
|
||||
@@ -493,49 +387,9 @@ void ColorSingleAnalysis::draw()
|
||||
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;
|
||||
|
||||
|
||||
if (_frame_cnt > 2)
|
||||
{
|
||||
_image_shown = true;
|
||||
@@ -560,9 +414,10 @@ void ColorSingleAnalysis::draw()
|
||||
// display results of the synthesis
|
||||
_RUN_DONE = true;
|
||||
break;
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
|
||||
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
void IResponseAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_iresponse", NUMBER_RUNS);
|
||||
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -12,11 +12,13 @@ using Poco::Thread;
|
||||
|
||||
#define NUMBER_RUNS 1
|
||||
#define ACQUIRE_TIME 20
|
||||
#define THRESHOLD 80
|
||||
#define TRESHOLD 80
|
||||
#define MAXBLOBS 15
|
||||
|
||||
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_relaxrate", NUMBER_RUNS);
|
||||
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
@@ -25,8 +27,8 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_relaxrate", ACQUIRE_TIME);
|
||||
cout << "ACQUIRE_TIME RelaxRateAnalysis " << acq_run_time << endl;
|
||||
|
||||
_threshold = RefractiveIndex::XML.getValue("config:relaxrate:threshold", THRESHOLD);
|
||||
cout << "THRESHOLD RelaxRateAnalysis " << _threshold << endl;
|
||||
_treshold = RefractiveIndex::XML.getValue("config:relaxrate:treshold", TRESHOLD);
|
||||
cout << "TRESHOLD RelaxRateAnalysis " << _treshold << endl;
|
||||
|
||||
_maxblobs = RefractiveIndex::XML.getValue("config:relaxrate:maxblobs", MAXBLOBS);
|
||||
cout << "MAXBLOBS RelaxRateAnalysis " << _maxblobs << endl;
|
||||
@@ -116,7 +118,7 @@ void RelaxRateAnalysis::synthesise()
|
||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayDiff1, 1);
|
||||
|
||||
cvGrayDiff1.threshold(_threshold);
|
||||
cvGrayDiff1.threshold(_treshold);
|
||||
|
||||
rfiCvContourFinder* cf = new rfiCvContourFinder();
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ protected:
|
||||
int _run_cnt, _save_cnt, _synth_save_cnt, _anim_cnt;
|
||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||
|
||||
int _threshold;
|
||||
int _treshold;
|
||||
int _maxblobs;
|
||||
|
||||
bool _show_image, _image_shown;
|
||||
|
||||
@@ -19,6 +19,8 @@ using Poco::Thread;
|
||||
|
||||
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shadowscapes", NUMBER_RUNS);
|
||||
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shapefromshading", NUMBER_RUNS);
|
||||
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
@@ -15,6 +15,8 @@ using Poco::Thread;
|
||||
|
||||
void StrobeAnalysis::setup(int camWidth, int camHeight)
|
||||
{
|
||||
AbstractAnalysis::setup(camWidth, camHeight);
|
||||
|
||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_strobe", NUMBER_RUNS);
|
||||
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
|
||||
//NUM_RUN = 5;
|
||||
|
||||
Reference in New Issue
Block a user