Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e7136fad0 | |||
| 58fdce259f | |||
| 9a6c1c6a55 | |||
| 35aa74f743 | |||
| 0dc006af44 | |||
| 357573f81a | |||
| 8872b60133 | |||
| da5da62160 | |||
| ec8d6f1296 | |||
| 34f3cf6ffd | |||
| 1e5bb28b43 | |||
| e0e170b522 | |||
| 8b9c3eaebc | |||
| a9c8a56850 | |||
| 706eb9354d | |||
| 21791b9769 | |||
| e29accb9ce | |||
| 7d7ec3606e | |||
| daec77d2be | |||
| 6d0f6422bf | |||
| 1728a128e4 | |||
| e43b78cc5a | |||
| 884e55abd4 | |||
| 46d02b4166 | |||
| a0483636ac | |||
| b39f191936 | |||
| 7d4f7ec18c | |||
| d31fd93932 | |||
| ebe29d2c8a | |||
| 86769bfc5f | |||
| 1f23d167c2 | |||
| 0d62dbd135 | |||
| c653d96c77 | |||
| 5693046ad9 | |||
| 81f37f8274 | |||
| ff7d3b6476 | |||
| 7b8dcd0940 | |||
| 476ab8cfd9 | |||
| f10aeefaef | |||
| cd49615cfc | |||
| 3b9bdde619 | |||
| 25a423f4ea | |||
| 7da4b4b47a | |||
| 7cd4da7341 | |||
| 5d48d6ef6a | |||
| 7a7614d02d | |||
| 38ec4da627 | |||
| 8fe367b47b | |||
| c8de799215 | |||
| 60e51a84f2 | |||
| 44c900e060 | |||
| 51c0098d27 | |||
| 5564329916 | |||
| 245d67cf8f |
@@ -1,2 +1,8 @@
|
|||||||
|
|
||||||
src/.DS_Store
|
src/.DS_Store
|
||||||
|
.DS_Store
|
||||||
|
Project.xcconfig
|
||||||
|
bin/
|
||||||
|
openFrameworks-Info.plist
|
||||||
|
opencvExample.xcodeproj/
|
||||||
|
config.refindx
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
WARNING: WORK IN PROGRESS...
|
WARNING: WORK IN PROGRESS...
|
||||||
|
|
||||||
configuring OpenFrameworks
|
configuring OpenFrameworks under Xcode
|
||||||
-----------------
|
---------------------------------------
|
||||||
|
|
||||||
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: {ofxDirList, ofxControlPanel, ofxXmlSettings};
|
(2) Install depedencies: {ofxXmlSettings, ofxOpenCV, ofxFileHelper};
|
||||||
(3) Press Play!
|
(3) Press Play!
|
||||||
|
|||||||
+138
-34
@@ -15,11 +15,11 @@
|
|||||||
|
|
||||||
#include "ofxXmlSettings.h"
|
#include "ofxXmlSettings.h"
|
||||||
|
|
||||||
#define CAMERA_ID 1
|
#define CAMERA_ID 0
|
||||||
#define CAMERA_ACQU_WIDTH 640
|
#define CAMERA_ACQU_WIDTH 640
|
||||||
#define CAMERA_ACQU_HEIGHT 480
|
#define CAMERA_ACQU_HEIGHT 480
|
||||||
|
|
||||||
#define LOCATION "MIDDLESBOROUGH"
|
#define LOCATION "MANCHESTER"
|
||||||
|
|
||||||
#define ISTATE_UNDEF 0xEEEE
|
#define ISTATE_UNDEF 0xEEEE
|
||||||
#define ISTATE_START 0xAAAA
|
#define ISTATE_START 0xAAAA
|
||||||
@@ -27,8 +27,10 @@
|
|||||||
#define ISTATE_TRANSITION 0xCCCC
|
#define ISTATE_TRANSITION 0xCCCC
|
||||||
#define ISTATE_END 0xDDDD
|
#define ISTATE_END 0xDDDD
|
||||||
|
|
||||||
|
|
||||||
int _state = ISTATE_UNDEF;
|
int _state = ISTATE_UNDEF;
|
||||||
|
|
||||||
|
int RefractiveIndex::_mode;
|
||||||
ofPixels RefractiveIndex::_pixels;
|
ofPixels RefractiveIndex::_pixels;
|
||||||
ofVideoGrabber RefractiveIndex::_vidGrabber;
|
ofVideoGrabber RefractiveIndex::_vidGrabber;
|
||||||
int RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, RefractiveIndex::_vid_id;
|
int RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, RefractiveIndex::_vid_id;
|
||||||
@@ -36,10 +38,14 @@ bool RefractiveIndex::_vid_stream_open;
|
|||||||
bool RefractiveIndex::_vid_toggle_on;
|
bool RefractiveIndex::_vid_toggle_on;
|
||||||
string RefractiveIndex::_location;
|
string RefractiveIndex::_location;
|
||||||
|
|
||||||
ofxXmlSettings XML;
|
ofxXmlSettings RefractiveIndex::XML;
|
||||||
|
|
||||||
void RefractiveIndex::setup()
|
void RefractiveIndex::setup()
|
||||||
{
|
{
|
||||||
|
camDist=1000;
|
||||||
|
|
||||||
|
ofBackground(0, 0, 0);
|
||||||
|
ofSetBackgroundAuto(false);
|
||||||
bool save_config = false;
|
bool save_config = false;
|
||||||
|
|
||||||
cout << "Loading configuration..." << endl;
|
cout << "Loading configuration..." << endl;
|
||||||
@@ -50,8 +56,14 @@ 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;
|
||||||
|
|
||||||
_vid_w = XML.getValue("config:camera:width", CAMERA_ACQU_WIDTH);
|
_vid_w = XML.getValue("config:camera:width", CAMERA_ACQU_WIDTH);
|
||||||
_vid_h = XML.getValue("config:camera:height", CAMERA_ACQU_HEIGHT);
|
_vid_h = XML.getValue("config:camera:height", CAMERA_ACQU_HEIGHT);
|
||||||
|
|
||||||
@@ -80,8 +92,10 @@ void RefractiveIndex::setup()
|
|||||||
cout << "* cam width = " << _vid_w << endl;
|
cout << "* cam width = " << _vid_w << endl;
|
||||||
cout << "* cam height = " << _vid_h << endl;
|
cout << "* cam height = " << _vid_h << endl;
|
||||||
|
|
||||||
_vid_stream_open = false;
|
if(_mode == MODE_ANALYSING) {
|
||||||
setup_camera();
|
_vid_stream_open = false;
|
||||||
|
setup_camera();
|
||||||
|
}
|
||||||
|
|
||||||
cout << "RRRRRREADY!" << endl;
|
cout << "RRRRRREADY!" << endl;
|
||||||
|
|
||||||
@@ -91,43 +105,41 @@ void RefractiveIndex::setup()
|
|||||||
//void ofPixels::allocate(int w, int h, ofImageType type)
|
//void ofPixels::allocate(int w, int h, ofImageType type)
|
||||||
_pixels.allocate(_vid_w, _vid_h, OF_IMAGE_COLOR);
|
_pixels.allocate(_vid_w, _vid_h, OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
|
||||||
//TODO: whichever one of these is first - it always runs twice ?
|
//TODO: whichever one of these is first - it always runs twice ?
|
||||||
|
|
||||||
_analysisVector.push_back(new ShadowScapesAnalysis(V));
|
_analysisVector.push_back(new ShadowScapesAnalysis(V)); //1
|
||||||
_analysisVector.push_back(new ShadowScapesAnalysis(H));
|
_analysisVector.push_back(new ShadowScapesAnalysis(H)); //2
|
||||||
_analysisVector.push_back(new ShadowScapesAnalysis(D));
|
_analysisVector.push_back(new ShadowScapesAnalysis(D)); //3
|
||||||
|
|
||||||
_analysisVector.push_back(new RelaxRateAnalysis());
|
_analysisVector.push_back(new RelaxRateAnalysis()); //4
|
||||||
|
|
||||||
_analysisVector.push_back(new IResponseAnalysis());
|
_analysisVector.push_back(new IResponseAnalysis()); //5
|
||||||
|
|
||||||
_analysisVector.push_back(new ShapeFromShadingAnalysis());
|
_analysisVector.push_back(new ShapeFromShadingAnalysis()); //6
|
||||||
|
|
||||||
_analysisVector.push_back(new StrobeAnalysis());
|
_analysisVector.push_back(new StrobeAnalysis()); //7
|
||||||
|
|
||||||
_analysisVector.push_back(new CamNoiseAnalysis());
|
_analysisVector.push_back(new CamNoiseAnalysis()); //8
|
||||||
|
|
||||||
_analysisVector.push_back(new ColorSingleAnalysis());
|
_analysisVector.push_back(new ColorSingleAnalysis()); //9
|
||||||
|
|
||||||
_analysisVector.push_back(new ColorMultiAnalysis());
|
_analysisVector.push_back(new ColorMultiAnalysis()); //0
|
||||||
|
|
||||||
_analysisVector.push_back(new DiffNoiseAnalysis());
|
_analysisVector.push_back(new DiffNoiseAnalysis()); //Q
|
||||||
|
|
||||||
//_currentAnalysisIndx = 0;
|
//_currentAnalysisIndx = 0;
|
||||||
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
||||||
|
|
||||||
//_state = ISTATE_START;
|
//_state = ISTATE_START;
|
||||||
|
|
||||||
_currentAnalysis = NULL;
|
_currentAnalysis = NULL;
|
||||||
_state = ISTATE_UNDEF;
|
_state = ISTATE_UNDEF;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::analysis_cb(string & analysis)
|
void RefractiveIndex::analysis_cb(string & analysis)
|
||||||
{
|
{
|
||||||
assert(analysis == _currentAnalysis->_name);
|
assert(analysis == _currentAnalysis->_name);
|
||||||
|
|
||||||
_state = ISTATE_STOP;
|
_state = ISTATE_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +149,17 @@ void RefractiveIndex::start_analysis()
|
|||||||
_analysisAdapator = new AnalysisAdaptor(_currentAnalysis);
|
_analysisAdapator = new AnalysisAdaptor(_currentAnalysis);
|
||||||
_currentAnalysis->setup(_vid_w, _vid_h);
|
_currentAnalysis->setup(_vid_w, _vid_h);
|
||||||
_analysisAdapator->start();
|
_analysisAdapator->start();
|
||||||
|
|
||||||
|
//allocate fbo for HD
|
||||||
|
fbo.allocate(1920,1080);
|
||||||
|
|
||||||
|
// fbo.allocate( _currentAnalysis->_mesh_size_multiplier *_vid_w,_currentAnalysis->_mesh_size_multiplier * _vid_h);
|
||||||
|
//camera.setPosition((fbo.getWidth()/2), fbo.getHeight()/2,_currentAnalysis->_mesh_size_multiplier *500);
|
||||||
|
camera.setPosition(0, (fbo.getHeight()/2)+150, _currentAnalysis->_mesh_size_multiplier*500);
|
||||||
|
camera.setFov(65.0);
|
||||||
|
camera.setOrientation(ofVec3f(-2,0,0));
|
||||||
|
_meshRotation=0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::stop_analysis()
|
void RefractiveIndex::stop_analysis()
|
||||||
@@ -170,10 +193,14 @@ void RefractiveIndex::state_analysis()
|
|||||||
break;
|
break;
|
||||||
case ISTATE_STOP:
|
case ISTATE_STOP:
|
||||||
stop_analysis(); // blocking
|
stop_analysis(); // blocking
|
||||||
_state = ISTATE_TRANSITION;
|
if(_mode == MODE_DRAWING)
|
||||||
|
_state = ISTATE_UNDEF;
|
||||||
|
else
|
||||||
|
_state = ISTATE_TRANSITION;
|
||||||
break;
|
break;
|
||||||
case ISTATE_END:
|
case ISTATE_END:
|
||||||
stop_camera();
|
if(_mode == MODE_ANALYSING)
|
||||||
|
stop_camera();
|
||||||
::exit(1);
|
::exit(1);
|
||||||
break;
|
break;
|
||||||
case ISTATE_UNDEF:
|
case ISTATE_UNDEF:
|
||||||
@@ -190,33 +217,67 @@ void RefractiveIndex::update()
|
|||||||
|
|
||||||
void RefractiveIndex::draw()
|
void RefractiveIndex::draw()
|
||||||
{
|
{
|
||||||
// refractive mauve
|
// refractive mauve - this doesn't work... looks weird in various places.
|
||||||
//ofBackground(113, 110, 136);
|
//ofBackground(113, 110, 136);
|
||||||
|
|
||||||
// black
|
// black
|
||||||
ofBackground(0, 0, 0);
|
ofBackground(0, 0, 0);
|
||||||
|
|
||||||
//TODO: Needs to return to a black screen - not to exit...
|
if(_currentAnalysis){
|
||||||
|
|
||||||
// i.e.: operational sequence
|
|
||||||
// 1) starts in a black screen
|
|
||||||
// 2) we 'start' with keypress "s" the entire set of analyses
|
|
||||||
// 3) at any point we need to be able to restart / stop-return-to-black / trigger each analysis individually
|
|
||||||
// 4) should end in black screen as well
|
|
||||||
// 5) final kill button
|
|
||||||
|
|
||||||
//ofRect(0,0,ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
if(_currentAnalysis)
|
|
||||||
_currentAnalysis->draw();
|
_currentAnalysis->draw();
|
||||||
|
|
||||||
|
if(_currentAnalysis->meshIsComplete){
|
||||||
|
|
||||||
|
fbo.begin();
|
||||||
|
ofClear(0,0,0);
|
||||||
|
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
|
|
||||||
|
camera.begin();
|
||||||
|
|
||||||
|
//this is a hack, I don't know how to colour the fbo with black pixels so I'm drawing a massive black rectangle in the background
|
||||||
|
/*
|
||||||
|
ofPushMatrix();
|
||||||
|
ofTranslate(0, 0,-500);
|
||||||
|
ofSetColor(0, 0, 0);
|
||||||
|
ofRect(-fbo.getWidth(), -fbo.getHeight(), fbo.getWidth()*3, fbo.getHeight()*3);
|
||||||
|
ofPopMatrix();
|
||||||
|
ofSetColor(255);
|
||||||
|
*/
|
||||||
|
//float xDiff= (fbo.getWidth()- 1.55*(_currentAnalysis->_mesh_size_multiplier * _vid_w))/2;
|
||||||
|
float xDiff= (fbo.getWidth()- 1.33333*(_currentAnalysis->_mesh_size_multiplier * _vid_w))/2;
|
||||||
|
float yDiff= (fbo.getHeight()-(_currentAnalysis->_mesh_size_multiplier * _vid_h))/2;
|
||||||
|
|
||||||
|
ofTranslate(xDiff,yDiff,-_currentAnalysis->zPlaneAverage );
|
||||||
|
//ofScale(1.33333,1.0,1.0);
|
||||||
|
//_currentAnalysis->aMesh.drawVertices(); // TODO: tom - why do you have the vertices drawing here?
|
||||||
|
_currentAnalysis->aMesh.drawFaces();
|
||||||
|
_currentAnalysis->aMesh.draw();
|
||||||
|
|
||||||
|
camera.end();
|
||||||
|
fbo.end();
|
||||||
|
|
||||||
|
ofPixels pixels;
|
||||||
|
fbo.readToPixels(pixels);
|
||||||
|
|
||||||
|
ofSaveImage(pixels,_currentAnalysis->meshFileName, OF_IMAGE_QUALITY_BEST);
|
||||||
|
//saving jpgs doesn't work - pngs only!
|
||||||
|
// PNG is fine - better for Final Cut anyway!
|
||||||
|
|
||||||
|
ofDisableBlendMode() ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::setup_camera()
|
void RefractiveIndex::setup_camera()
|
||||||
{
|
{
|
||||||
stop_camera();
|
stop_camera();
|
||||||
|
|
||||||
|
// THIS IS LOADED IN FROM THE XML FILE SETTINGS
|
||||||
_vidGrabber.setDeviceID(_vid_id);
|
_vidGrabber.setDeviceID(_vid_id);
|
||||||
_vidGrabber.listDevices();
|
_vidGrabber.listDevices();
|
||||||
|
|
||||||
if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) {
|
if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) {
|
||||||
ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber";
|
ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber";
|
||||||
@@ -357,10 +418,53 @@ void RefractiveIndex::keyPressed (int key)
|
|||||||
_state = ISTATE_TRANSITION;
|
_state = ISTATE_TRANSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
|
||||||
|
>> case 's':
|
||||||
|
>> doSave ^= true;
|
||||||
|
>> doLoad = false;
|
||||||
|
>> if(doSave) {
|
||||||
|
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to save to", true);
|
||||||
|
>> if(r.bSuccess) {
|
||||||
|
>> saveCounter = 0;
|
||||||
|
>> savePath = r.getPath();
|
||||||
|
>> ofDirectory::createDirectory(savePath + "/color/");
|
||||||
|
>> ofDirectory::createDirectory(savePath + "/depth/");
|
||||||
|
>> printf("SAVE %s %s\n", r.getPath().c_str(), r.getName().c_str());
|
||||||
|
>> } else {
|
||||||
|
>> doSave = false;
|
||||||
|
>> }
|
||||||
|
>>
|
||||||
|
>> }
|
||||||
|
>> break;
|
||||||
|
>>
|
||||||
|
>> case 'l':
|
||||||
|
>> doLoad ^= true;
|
||||||
|
>> doSave = false;
|
||||||
|
>> if(doLoad) {
|
||||||
|
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to load from", true);
|
||||||
|
>> if(r.bSuccess) {
|
||||||
|
>> loadCounter = 0;
|
||||||
|
>> loadPath = r.getPath();
|
||||||
|
>> ofDirectory dir;
|
||||||
|
>> 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());
|
||||||
|
>> } else {
|
||||||
|
>> doLoad = false;
|
||||||
|
>> }
|
||||||
|
>>
|
||||||
|
>> }
|
||||||
|
>> break;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::exit()
|
void RefractiveIndex::exit()
|
||||||
{
|
{
|
||||||
|
if(_currentAnalysis)
|
||||||
|
_analysisAdapator->stop();
|
||||||
stop_camera();
|
stop_camera();
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,12 @@
|
|||||||
#include "AnalysisAdaptor.h"
|
#include "AnalysisAdaptor.h"
|
||||||
|
|
||||||
#include "ofxOpenCv.h"
|
#include "ofxOpenCv.h"
|
||||||
|
#include "ofxXmlSettings.h"
|
||||||
|
#include "ofxOpenCv.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MODE_DRAWING 0xEEFF
|
||||||
|
#define MODE_ANALYSING 0xFFEE
|
||||||
|
|
||||||
class RefractiveIndex : public ofBaseApp
|
class RefractiveIndex : public ofBaseApp
|
||||||
{
|
{
|
||||||
@@ -50,10 +56,15 @@ protected:
|
|||||||
AnalysisAdaptor* _analysisAdapator;
|
AnalysisAdaptor* _analysisAdapator;
|
||||||
vector<AbstractAnalysis*> _analysisVector;
|
vector<AbstractAnalysis*> _analysisVector;
|
||||||
|
|
||||||
|
float _meshRotation;
|
||||||
|
float camDist;
|
||||||
|
ofEasyCam cam;
|
||||||
public:
|
public:
|
||||||
// acquisition
|
// acquisition
|
||||||
static ofPixels _pixels;
|
static ofPixels _pixels;
|
||||||
static ofVideoGrabber _vidGrabber;
|
static ofVideoGrabber _vidGrabber;
|
||||||
|
static int _mode;
|
||||||
|
|
||||||
vector<string> videoSourceList;
|
vector<string> videoSourceList;
|
||||||
static int _vid_w, _vid_h, _vid_id;
|
static int _vid_w, _vid_h, _vid_id;
|
||||||
static bool _vid_stream_open;
|
static bool _vid_stream_open;
|
||||||
@@ -61,5 +72,9 @@ public:
|
|||||||
|
|
||||||
// this should be in xml
|
// this should be in xml
|
||||||
static string _location;
|
static string _location;
|
||||||
|
static ofxXmlSettings XML; // made this static so we can access RUN_NUM in the analyses
|
||||||
|
ofCamera camera;
|
||||||
|
ofPixels keepOnScreen;
|
||||||
|
ofFbo fbo;
|
||||||
|
|
||||||
};
|
};
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
#include "ofAppGlutWindow.h"
|
#include "ofAppGlutWindow.h"
|
||||||
#include "RefractiveIndex.h"
|
#include "RefractiveIndex.h"
|
||||||
|
|
||||||
#define SCREEN_WIDTH 800
|
#define SCREEN_WIDTH 1280
|
||||||
#define SCREEN_HEIGHT 600
|
#define SCREEN_HEIGHT 800
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
|||||||
+198
-18
@@ -3,30 +3,79 @@
|
|||||||
#include "AbstractAnalysis.h"
|
#include "AbstractAnalysis.h"
|
||||||
#include "RefractiveIndex.h"
|
#include "RefractiveIndex.h"
|
||||||
#include "ofxFileHelper.h"
|
#include "ofxFileHelper.h"
|
||||||
|
#include "ofSystemUtils.h"
|
||||||
|
|
||||||
|
void AbstractAnalysis::setup(int camWidth, int camHeight) {
|
||||||
|
|
||||||
|
meshIsComplete=false;
|
||||||
|
imageForContourAvailable=false;
|
||||||
|
|
||||||
|
_cam_w = camWidth; _cam_h = camHeight;
|
||||||
|
if(RefractiveIndex::_mode == MODE_DRAWING) {
|
||||||
|
ofFileDialogResult r = ofSystemLoadDialog("choooose da folda", true);
|
||||||
|
if(!r.bSuccess) {
|
||||||
|
ofSystemAlertDialog("OOOOPS.... ERROR...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_whole_file_path_analysis = r.filePath;
|
||||||
|
_whole_file_path_synthesis = r.filePath + "/darwings";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// this is the main threaded loop for a given analysis
|
// this is the main threaded loop for a given analysis
|
||||||
void AbstractAnalysis::do_synthesize() {
|
void AbstractAnalysis::do_synthesize() {
|
||||||
|
|
||||||
for(int i = 0; i < NUM_RUN; i++) {
|
switch(RefractiveIndex::_mode)
|
||||||
|
{
|
||||||
|
case MODE_ANALYSING:
|
||||||
|
{
|
||||||
|
for(int i = 0; i < NUM_RUN; i++) {
|
||||||
|
|
||||||
cout << "i NUM_RUN" << i << endl;
|
cout << "NUM_RUN: " << i << endl;
|
||||||
|
|
||||||
_saved_filenames_analysis.clear();
|
_saved_filenames_analysis.clear();
|
||||||
_state = STATE_ACQUIRING;
|
_saved_filenames_synthesis.clear();
|
||||||
acquire();
|
|
||||||
if(_state == STATE_STOP) goto exit;
|
_state = STATE_ACQUIRING;
|
||||||
_state = STATE_SYNTHESISING;
|
acquire();
|
||||||
synthesise();
|
if(_state == STATE_STOP) goto exit;
|
||||||
if(_state == STATE_STOP) goto exit;
|
_state = STATE_SYNTHESISING;
|
||||||
_state = STATE_DISPLAY_RESULTS;
|
synthesise();
|
||||||
displayresults();
|
if(_state == STATE_STOP) goto exit;
|
||||||
|
_state = STATE_DISPLAY_RESULTS;
|
||||||
|
displayresults();
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case MODE_DRAWING:
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
ofxFileHelper fileHelperDrawing;
|
||||||
|
if(!fileHelperDrawing.doesDirectoryExist(_whole_file_path_synthesis)){
|
||||||
|
fileHelperDrawing.makeDirectory(_whole_file_path_synthesis);
|
||||||
|
}
|
||||||
|
|
||||||
|
read_dir_create_list(_whole_file_path_analysis);
|
||||||
|
_state = STATE_SYNTHESISING;
|
||||||
|
synthesise();
|
||||||
|
if(_state == STATE_STOP) goto exit;
|
||||||
|
_state = STATE_DISPLAY_RESULTS;
|
||||||
|
displayresults();
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
cleanup();
|
||||||
ofNotifyEvent(_synthesize_cb, _name);
|
ofNotifyEvent(_synthesize_cb, _name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractAnalysis::create_dir()
|
void AbstractAnalysis::create_dir_allocate_images()
|
||||||
{
|
{
|
||||||
// HERE IS WHERE WE SETUP THE DIRECTORY FOR ALL THE SAVED IMAGES
|
// HERE IS WHERE WE SETUP THE DIRECTORY FOR ALL THE SAVED IMAGES
|
||||||
|
|
||||||
@@ -57,21 +106,152 @@ void AbstractAnalysis::create_dir()
|
|||||||
//cout << "_whole_file_path_analysis = " << _whole_file_path_analysis << endl;
|
//cout << "_whole_file_path_analysis = " << _whole_file_path_analysis << endl;
|
||||||
|
|
||||||
if(!fileHelperAnalysis.doesDirectoryExist(_whole_file_path_analysis)){
|
if(!fileHelperAnalysis.doesDirectoryExist(_whole_file_path_analysis)){
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH))
|
||||||
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH);
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH);
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location))
|
||||||
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location);
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location);
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name))
|
||||||
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name);
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name);
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime))
|
||||||
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
fileHelperAnalysis.makeDirectory(ANALYSIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_whole_file_path_synthesis = SYNTHESIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime;
|
_whole_file_path_synthesis = SYNTHESIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime;
|
||||||
|
|
||||||
if(!fileHelperSynthesis.doesDirectoryExist(_whole_file_path_synthesis)){
|
if(!fileHelperSynthesis.doesDirectoryExist(_whole_file_path_synthesis)){
|
||||||
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH);
|
|
||||||
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location);
|
|
||||||
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name);
|
|
||||||
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH))
|
||||||
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH);
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location))
|
||||||
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location);
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name))
|
||||||
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name);
|
||||||
|
|
||||||
|
if(!fileHelperAnalysis.doesDirectoryExist(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 //////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmp_file(string f0, string f1)
|
||||||
|
{
|
||||||
|
int v0 = atoi(f0.substr(0, f0.find("_")).c_str());
|
||||||
|
int v1 = atoi(f1.substr(0, f1.find("_")).c_str());
|
||||||
|
return v0 < v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractAnalysis::read_dir_create_list(string folder_path)
|
||||||
|
{
|
||||||
|
File dir(folder_path);
|
||||||
|
|
||||||
|
if(dir.exists() && dir.isDirectory()) {
|
||||||
|
vector<string> list;
|
||||||
|
dir.list(list);
|
||||||
|
|
||||||
|
std::sort(list.begin(), list.end(), cmp_file);
|
||||||
|
|
||||||
|
for(int i = 0; i < list.size(); i++) {
|
||||||
|
string filepath = folder_path + "/" + list[i];
|
||||||
|
_saved_filenames_analysis.push_back(filepath);
|
||||||
|
|
||||||
|
cout << list[i] << endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractAnalysis::saveImageAnalysis(string filename)
|
||||||
|
{
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+34
-2
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#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/"
|
||||||
@@ -24,7 +25,7 @@ public:
|
|||||||
virtual ~AbstractAnalysis(){;}
|
virtual ~AbstractAnalysis(){;}
|
||||||
|
|
||||||
// generic function to set up the camera
|
// generic function to set up the camera
|
||||||
virtual void setup(int camWidth, int camHeight){_cam_w = camWidth; _cam_h = camHeight;}
|
virtual void setup(int camWidth, int camHeight);
|
||||||
|
|
||||||
// this is the main threaded loop for a given analysis
|
// this is the main threaded loop for a given analysis
|
||||||
void do_synthesize();
|
void do_synthesize();
|
||||||
@@ -34,7 +35,12 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void create_dir();
|
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);
|
||||||
|
|
||||||
// acquire images - all the children (see - do_synthesize)
|
// acquire images - all the children (see - do_synthesize)
|
||||||
virtual void acquire() = 0;
|
virtual void acquire() = 0;
|
||||||
@@ -45,11 +51,33 @@ 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;
|
||||||
|
string _draw_directory;
|
||||||
|
|
||||||
// event
|
// event
|
||||||
ofEvent<string> _synthesize_cb;
|
ofEvent<string> _synthesize_cb;
|
||||||
|
bool meshIsComplete;
|
||||||
|
bool imageForContourAvailable;
|
||||||
|
ofMesh aMesh;
|
||||||
|
ofLight light;
|
||||||
|
ofLight lightStatic;
|
||||||
|
|
||||||
|
string meshFileName;
|
||||||
|
//difference between our image size and the size of the fbo
|
||||||
|
float widthScaleFactor;
|
||||||
|
float heightScaleFactor;
|
||||||
|
ofImage contourImage;
|
||||||
|
ofPixels meshPix;
|
||||||
|
ofPixels publicColorImage;
|
||||||
|
float zPlaneAverage;
|
||||||
|
|
||||||
|
//added Tom 1/5/12 defines the stretch we make to the mesh to make it fit HD proportions
|
||||||
|
float _mesh_size_multiplier;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int _cam_w, _cam_h;
|
int _cam_w, _cam_h;
|
||||||
@@ -59,6 +87,10 @@ 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;
|
||||||
|
|||||||
+742
-46
@@ -10,13 +10,79 @@ using Poco::Timer;
|
|||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
NUM_RUN = 5;
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_camnoise", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time = 20; // 20 seconds of acquiring per run
|
|
||||||
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
_mesh_size_multiplier = 8;
|
||||||
|
vertexSubsampling = 1;
|
||||||
|
chooseColour = 6;
|
||||||
|
multiplier = 4.0;
|
||||||
|
|
||||||
|
ofSetLineWidth(5.0f);
|
||||||
|
glPointSize(5.0f);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
//blendMode = OF_BLENDMODE_ADD;
|
||||||
|
//blendMode = OF_BLENDMODE_MULTIPLY;
|
||||||
|
//blendMode = OF_BLENDMODE_SUBTRACT;
|
||||||
|
//blendMode = OF_BLENDMODE_ALPHA;
|
||||||
|
blendMode = OF_BLENDMODE_SCREEN;
|
||||||
|
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
||||||
|
// meshMode = OF_PRIMITIVE_LINES;
|
||||||
|
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
||||||
|
meshMode = OF_PRIMITIVE_POINTS;
|
||||||
|
|
||||||
|
///setup light
|
||||||
|
ofEnableLighting();
|
||||||
|
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||||
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||||
|
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHT0);
|
||||||
|
|
||||||
|
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHT1);
|
||||||
|
glPointSize(9.0f);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_camnoise", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME CamNoiseAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
|
||||||
|
//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
|
||||||
// or 5 times per second = every 200 ms
|
// or 5 times per second = every 200 ms
|
||||||
@@ -32,11 +98,17 @@ 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();
|
//create_dir_allocate_images();
|
||||||
|
|
||||||
_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
|
||||||
@@ -46,9 +118,27 @@ 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();
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -56,7 +146,6 @@ void CamNoiseAnalysis::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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +158,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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
// for(int i = 0; i < NUM_RUN; i++) {
|
// for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -93,10 +182,25 @@ void CamNoiseAnalysis::synthesise()
|
|||||||
//cout << "CamNoiseAnalysis::saving synthesis...\n";
|
//cout << "CamNoiseAnalysis::saving synthesis...\n";
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
_returnAveragePixelValues();
|
||||||
|
vector<vector<float> > averagePixelBrightnessesForEachLevel = averagePixelValuesForAllLevels;
|
||||||
|
float lightLevel=0;
|
||||||
|
float pLightLevel=0;
|
||||||
|
cout<<_listOfLightLevels.size()<<" "<<averagePixelBrightnessesForEachLevel.size()<<" these should be the same";
|
||||||
|
|
||||||
|
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
||||||
|
vector<string> fileNameParts= ofSplitString(_saved_filenames_analysis[i], "_");
|
||||||
|
|
||||||
|
lightLevel = ofToFloat(fileNameParts[fileNameParts.size()-2]);
|
||||||
//cout << "CamNoiseAnalysis::synthesis FOR LOOP...\n";
|
//cout << "CamNoiseAnalysis::synthesis FOR LOOP...\n";
|
||||||
|
|
||||||
|
//find which list of average pixel values is for THIS light level
|
||||||
|
int _averagePixelVectorIndex;
|
||||||
|
for (int j=0; j<_listOfLightLevels.size(); j+=3) {
|
||||||
|
if(lightLevel==_listOfLightLevels[j]){
|
||||||
|
_averagePixelVectorIndex=j;
|
||||||
|
}
|
||||||
|
}
|
||||||
//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;
|
||||||
@@ -107,43 +211,118 @@ void CamNoiseAnalysis::synthesise()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//cout << "LOADED image1!!!" << endl;
|
// cout << "LOADED image1!!!" << endl;
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
|
||||||
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;
|
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||||
//cvGrayImage2 = cvColorImage2;
|
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
//cvGrayDiff1.erode();
|
//cvGrayDiff1.erode();
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
//cvGrayDiff1.blur(5);
|
|
||||||
//cvGrayDiff1.dilate();
|
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
|
|
||||||
cvGrayImage1.threshold(255.0*i/_saved_filenames_analysis.size()); //random threshold for the moment
|
cvGrayImage1.dilate();
|
||||||
cvGrayImage1.blur(10);
|
cvGrayImage1.blur(5);
|
||||||
cvGrayImage1.contrastStretch();
|
cvGrayImage1.contrastStretch();
|
||||||
cvGrayImage1.blur(10);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
string file_name;
|
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||||
|
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_CamNoiseAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||||
|
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//cvFloatImage1 = cvColorImage1;
|
||||||
|
//cvGrayImage1 = cvColorImage1;
|
||||||
|
|
||||||
ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
|
||||||
//ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
//}
|
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
|
||||||
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
|
|
||||||
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
|
|
||||||
|
// convert the CV image
|
||||||
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
|
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
||||||
|
*/
|
||||||
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//subtract background begin///////////////
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
|
//DIFFERENCING SUBSEQUENT IMAGES
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||||
|
imagePixels1[i]-=imagePixels2[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//DIFFERENCING THE BACKGROUND
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, averagePixelBrightnessesForEachLevel[_averagePixelVectorIndex], _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
|
//string file_name;
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_CamNoiseAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
|
//flag that we are finished
|
||||||
|
meshIsComplete=true;
|
||||||
|
_synth_save_cnt++;
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// _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
|
||||||
@@ -349,7 +528,7 @@ void CamNoiseAnalysis::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();
|
||||||
@@ -373,20 +552,537 @@ 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";
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(file_name);
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void CamNoiseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
//to do
|
||||||
|
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
mesh.setMode(meshMode);
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255);
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==2){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==3){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==4){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
int randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==5){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
int randomJitter2 = 0;
|
||||||
|
int randomJitter = 0;
|
||||||
|
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
ofColor currentSecondImageBW;
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(chooseColour==6){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x++;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> CamNoiseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, vector<float> averageDepths, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
int inc=0;
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
|
||||||
|
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
||||||
|
|
||||||
|
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
||||||
|
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
if(i<100){
|
||||||
|
|
||||||
|
// cout<<" average: "<<averageDepths[inc]<<" actual: "<<imageColor1.getBrightness()<<" ";
|
||||||
|
}
|
||||||
|
// int thisDiff=imageColor1.getBrightness();
|
||||||
|
|
||||||
|
int thisDiff=-(imageColor1.getBrightness() - averageDepths[inc] );
|
||||||
|
//int thisDiff=abs(imageColor1.getLightness());
|
||||||
|
//int thisDiff=-abs(imageColor1.r);
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
differences.push_back(multiplier * thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
inc++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CamNoiseAnalysis:: _returnAveragePixelValues(){
|
||||||
|
|
||||||
|
|
||||||
|
//second number in 15_204.00_2.jpg is the light level
|
||||||
|
|
||||||
|
float lightLevel=0;
|
||||||
|
float pLightLevel=0;
|
||||||
|
float numberOfImagesActuallyLoaded=0;
|
||||||
|
vector<float> averagePixelValuesForOneLevel;
|
||||||
|
|
||||||
|
for (int j=0; j<RefractiveIndex::_vid_w*RefractiveIndex::_vid_h; j++) {
|
||||||
|
averagePixelValuesForOneLevel.push_back(0.0);
|
||||||
|
}
|
||||||
|
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
||||||
|
|
||||||
|
|
||||||
|
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])){
|
||||||
|
|
||||||
|
//split file name by under score
|
||||||
|
vector<string> fileNameParts= ofSplitString(_saved_filenames_analysis[i], "_");
|
||||||
|
|
||||||
|
lightLevel = ofToFloat(fileNameParts[fileNameParts.size()-2]);
|
||||||
|
// cout<<" lightLevel "<<lightLevel;
|
||||||
|
|
||||||
|
ofPixels image1Pixels=image1.getPixelsRef();
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
int inc=0;
|
||||||
|
for (int j=0; j<image1Pixels.size(); j+=3) {
|
||||||
|
ofColor color=image1Pixels.getColor(x, y);
|
||||||
|
averagePixelValuesForOneLevel[inc]+= color.getBrightness();
|
||||||
|
x++;
|
||||||
|
inc++;
|
||||||
|
if(x>=image1Pixels.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// _listOfLightLevels}
|
||||||
|
numberOfImagesActuallyLoaded++;
|
||||||
|
|
||||||
|
//if this is a new light level advance
|
||||||
|
if (lightLevel!=pLightLevel) {
|
||||||
|
|
||||||
|
///check that this light level is not already in our list
|
||||||
|
|
||||||
|
|
||||||
|
_listOfLightLevels.push_back(lightLevel);
|
||||||
|
|
||||||
|
for (int j=0; j<averagePixelValuesForOneLevel.size(); j++) {
|
||||||
|
averagePixelValuesForOneLevel[j]/=numberOfImagesActuallyLoaded;
|
||||||
|
//cout<<" "<<averagePixelValuesForOneLevel[j]<<" ";
|
||||||
|
}
|
||||||
|
averagePixelValuesForAllLevels.push_back(averagePixelValuesForOneLevel);
|
||||||
|
for (int j=0; j<averagePixelValuesForOneLevel.size(); j++) {
|
||||||
|
averagePixelValuesForOneLevel[j]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pLightLevel=lightLevel;
|
||||||
|
numberOfImagesActuallyLoaded=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int j=0;j<_listOfLightLevels.size();j++){
|
||||||
|
//cout<<_listOfLightLevels[j]<<" lightlevel ";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,4 +60,30 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, vector<float> averageDepths, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
//returns a vector of floats for each distinct light level
|
||||||
|
void _returnAveragePixelValues();
|
||||||
|
//this vector of vectors will be returned
|
||||||
|
vector<vector<float> > averagePixelValuesForAllLevels;
|
||||||
|
|
||||||
|
vector<float> _listOfLightLevels;
|
||||||
|
|
||||||
|
int vertexSubsampling;
|
||||||
|
|
||||||
|
int chooseColour;
|
||||||
|
ofPrimitiveMode meshMode;
|
||||||
|
ofBlendMode blendMode;
|
||||||
|
float multiplier;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+283
-41
@@ -9,20 +9,37 @@ using Poco::Timer;
|
|||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
NUM_RUN = 5;
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colormulti", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time = 35;
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
|
||||||
|
_mesh_size_multiplier=8;
|
||||||
|
vertexSubsampling = 1;
|
||||||
|
chooseColour=1;
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colormulti", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME ColorMultiAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
//int acq_run_time = 35;
|
||||||
|
|
||||||
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
// or 10 times per second = every 100 ms
|
// or 10 times per second = every 100 ms
|
||||||
|
|
||||||
_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();
|
//create_dir_allocate_images();
|
||||||
|
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
@@ -32,12 +49,15 @@ 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
|
||||||
@@ -47,9 +67,28 @@ 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);
|
||||||
@@ -58,6 +97,8 @@ 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()
|
||||||
@@ -69,7 +110,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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -108,6 +149,7 @@ void ColorMultiAnalysis::synthesise()
|
|||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//cout << "LOADED image1!!!" << endl;
|
//cout << "LOADED image1!!!" << endl;
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
||||||
@@ -117,43 +159,91 @@ void ColorMultiAnalysis::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.blur(1);
|
||||||
|
//cvColorImage1.erode();
|
||||||
|
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
|
||||||
|
//cvFloatImage1 = cvColorImage1;
|
||||||
//cvGrayImage1 = cvColorImage1;
|
//cvGrayImage1 = cvColorImage1;
|
||||||
//cvGrayImage2 = cvColorImage2;
|
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 15, 15);
|
||||||
//cvGrayDiff1.erode();
|
cvXorS( cvColorImage1.getCvImage(), cvScalarAll(2), cvColorImage1.getCvImage(), 0 );
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
//cvGrayDiff1.blur(5);
|
|
||||||
//cvGrayDiff1.dilate();
|
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
|
|
||||||
cvColorImage1.contrastStretch();
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
cvColorImage1.blur(5);
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
cvColorImage1.erode();
|
|
||||||
cvColorImage1.erode();
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
cvColorImage1.dilate();
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
cvColorImage1.blur(5);
|
|
||||||
cvColorImage1.dilate();
|
// convert the CV image
|
||||||
cvColorImage1.dilate();
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
cvColorImage1.dilate();
|
|
||||||
cvColorImage1.dilate();
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//subtract background begin///////////////
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
string file_name;
|
//string file_name;
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
ofSaveImage(cvColorImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
//flag that we are finished
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
meshIsComplete=true;
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
||||||
|
/*
|
||||||
|
_RUN_DONE = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
meshIsComplete=false;
|
||||||
|
_synth_save_cnt=0;
|
||||||
|
|
||||||
// _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
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(3);
|
Thread::sleep(3);
|
||||||
}
|
}
|
||||||
@@ -189,6 +279,27 @@ void ColorMultiAnalysis::displayresults()
|
|||||||
void ColorMultiAnalysis::draw()
|
void ColorMultiAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ofEnableSmoothing();
|
||||||
|
|
||||||
|
ofEnableLighting();
|
||||||
|
ofEnableSeparateSpecularLight();
|
||||||
|
light.enable();
|
||||||
|
|
||||||
|
light.setPosition(200,200,-150);
|
||||||
|
lightStatic.enable();
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
ofSetLineWidth(2.0f);
|
||||||
|
//glPointSize(4.0f);
|
||||||
|
|
||||||
|
ofEnableBlendMode ( OF_BLENDMODE_ADD );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_MULTIPLY );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_SUBTRACT );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_ALPHA );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_SCREEN );
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -351,7 +462,6 @@ void ColorMultiAnalysis::draw()
|
|||||||
|
|
||||||
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.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
@@ -374,25 +484,157 @@ 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++;
|
||||||
|
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
saveImageAnalysis(file_name);
|
||||||
|
}
|
||||||
|
|
||||||
RefractiveIndex::_vidGrabber.grabFrame(); // get a new frame from the camera
|
|
||||||
|
|
||||||
if (RefractiveIndex::_vidGrabber.isFrameNew())
|
void ColorMultiAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
{
|
int x=0;
|
||||||
RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
|
int y=0;
|
||||||
} else {
|
|
||||||
return;
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
|
||||||
|
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_LINES);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_LINE_STRIP);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_LINE_LOOP);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_POINTS);
|
||||||
|
|
||||||
|
/*
|
||||||
|
OF_PRIMITIVE_TRIANGLES,
|
||||||
|
OF_PRIMITIVE_TRIANGLE_STRIP,
|
||||||
|
OF_PRIMITIVE_TRIANGLE_FAN,
|
||||||
|
OF_PRIMITIVE_LINES,
|
||||||
|
OF_PRIMITIVE_LINE_STRIP,
|
||||||
|
OF_PRIMITIVE_LINE_LOOP,
|
||||||
|
OF_PRIMITIVE_POINTS
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//cout << "ColorMultiAnalysis::saving...\n";
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
if(chooseColour==1){
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> ColorMultiAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
//float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
//float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
||||||
|
//float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
int thisDiff=-abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getLightness());
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
float multiplier=15.0*((thisDiff)/255.0);
|
||||||
|
|
||||||
|
differences.push_back(multiplier* thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,4 +55,21 @@ protected:
|
|||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
|
//this is the temporary container to allow us to convert and save out greyscale images
|
||||||
|
ofxCvColorImage cvConvertorImage;
|
||||||
|
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
int vertexSubsampling;
|
||||||
|
int chooseColour;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+447
-50
@@ -1,29 +1,48 @@
|
|||||||
#include "ColorSingleAnalysis.h"
|
#include "ColorSingleAnalysis.h"
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
|
|
||||||
#include "Poco/Timer.h"
|
#include "Poco/Timer.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "RefractiveIndex.h"
|
#include "RefractiveIndex.h"
|
||||||
|
|
||||||
using Poco::Timer;
|
using Poco::Timer;
|
||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
NUM_RUN = 5;
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_colorsingle", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time = 25; // 20 seconds of acquiring per run
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
_mesh_size_multiplier=8;
|
||||||
|
vertexSubsampling = 1;
|
||||||
|
chooseColour=1;
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colorsingle", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME ColorSingleAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
|
||||||
|
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
// or 10 times per second = every 100 ms
|
// or 10 times per second = every 100 ms
|
||||||
|
|
||||||
_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();
|
//create_dir_allocate_images();
|
||||||
|
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -38,10 +57,17 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
|||||||
b = 0;
|
b = 0;
|
||||||
|
|
||||||
fileNameTag = "";
|
fileNameTag = "";
|
||||||
|
fileNameColor = "";
|
||||||
|
|
||||||
_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
|
||||||
@@ -51,9 +77,28 @@ 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);
|
||||||
@@ -61,12 +106,13 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorSingleAnalysis::acquire()
|
void ColorSingleAnalysis::acquire()
|
||||||
{
|
{
|
||||||
|
|
||||||
Timer* save_timer;
|
Timer* save_timer;
|
||||||
|
|
||||||
TimerCallback<ColorSingleAnalysis> save_callback(*this, &ColorSingleAnalysis::save_cb);
|
TimerCallback<ColorSingleAnalysis> save_callback(*this, &ColorSingleAnalysis::save_cb);
|
||||||
@@ -74,7 +120,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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -89,8 +135,6 @@ void ColorSingleAnalysis::acquire()
|
|||||||
|
|
||||||
save_timer->stop();
|
save_timer->stop();
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorSingleAnalysis::synthesise()
|
void ColorSingleAnalysis::synthesise()
|
||||||
@@ -113,51 +157,126 @@ void ColorSingleAnalysis::synthesise()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//cout << "LOADED image1!!!" << endl;
|
//cout << "LOADED image1!!!" << endl;
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
cout << "_saved_filenames_analysis[i].find(RED): " << _saved_filenames_analysis[i].find("RED") << endl;
|
||||||
|
|
||||||
|
if(_saved_filenames_analysis[i].find("RED")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameColor = "RED";
|
||||||
|
cout<<"FOUND RED"<<endl;
|
||||||
|
} else if (_saved_filenames_analysis[i].find("GREEN")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameColor = "GREEN";
|
||||||
|
cout<<"FOUND GREEN"<<endl;
|
||||||
|
} else if(_saved_filenames_analysis[i].find("BLUE")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameColor = "BLUE";
|
||||||
|
cout<<"FOUND BLUE"<<endl;
|
||||||
|
} else if(_saved_filenames_analysis[i].find("FADING")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameColor = "FADING";
|
||||||
|
cout<<"FOUND FADING"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
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.blur(1);
|
||||||
|
|
||||||
|
//cvSmooth( cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), CV_GAUSSIAN, 9, 9 );
|
||||||
|
|
||||||
|
cvColorImage1.erode();
|
||||||
|
|
||||||
|
cvSmooth( cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), CV_GAUSSIAN, 3, 3 );
|
||||||
|
|
||||||
|
//cvColorImage1.erode();
|
||||||
|
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
|
||||||
|
//cvFloatImage1 = cvColorImage1;
|
||||||
//cvGrayImage1 = cvColorImage1;
|
//cvGrayImage1 = cvColorImage1;
|
||||||
//cvGrayImage2 = cvColorImage2;
|
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(255), cvColorImage1.getCvImage(), 0 );
|
||||||
//cvGrayDiff1.erode();
|
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
//cvGrayDiff1.blur(5);
|
|
||||||
//cvGrayDiff1.dilate();
|
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
|
|
||||||
cvColorImage1.contrastStretch();
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
cvColorImage1.blur(5);
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
cvColorImage1.erode();
|
|
||||||
cvColorImage1.erode();
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
cvColorImage1.dilate();
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
cvColorImage1.blur(5);
|
|
||||||
cvColorImage1.erode();
|
// convert the CV image
|
||||||
cvColorImage1.erode();
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
cvColorImage1.erode();
|
|
||||||
cvColorImage1.erode();
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//subtract background begin///////////////
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
string file_name;
|
//string file_name;
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
ofSaveImage(cvColorImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
//flag that we are finished
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
meshIsComplete=true;
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
||||||
|
/*
|
||||||
|
_RUN_DONE = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
meshIsComplete=false;
|
||||||
|
_synth_save_cnt=0;
|
||||||
|
|
||||||
// _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
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(3);
|
Thread::sleep(3);
|
||||||
|
|
||||||
@@ -194,12 +313,31 @@ void ColorSingleAnalysis::displayresults()
|
|||||||
|
|
||||||
void ColorSingleAnalysis::draw()
|
void ColorSingleAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
ofEnableSmoothing();
|
||||||
|
|
||||||
|
ofEnableLighting();
|
||||||
|
ofEnableSeparateSpecularLight();
|
||||||
|
light.enable();
|
||||||
|
|
||||||
|
light.setPosition(200,200,-150);
|
||||||
|
lightStatic.enable();
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
ofSetLineWidth(1.0f);
|
||||||
|
glPointSize(1.0f);
|
||||||
|
|
||||||
|
ofEnableBlendMode ( OF_BLENDMODE_ADD );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_MULTIPLY );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_SUBTRACT );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_ALPHA );
|
||||||
|
//ofEnableBlendMode ( OF_BLENDMODE_SCREEN );
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt < _frame_cnt_max)
|
if (_frame_cnt < _frame_cnt_max)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -364,7 +502,6 @@ void ColorSingleAnalysis::draw()
|
|||||||
|
|
||||||
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.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
@@ -388,22 +525,282 @@ 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";
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(file_name);
|
||||||
|
}
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
|
||||||
|
|
||||||
|
|
||||||
|
void ColorSingleAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_TRIANGLES);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_LINES);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_LINE_STRIP);
|
||||||
|
//mesh.setMode(OF_PRIMITIVE_LINE_LOOP);
|
||||||
|
mesh.setMode(OF_PRIMITIVE_POINTS);
|
||||||
|
|
||||||
|
/*
|
||||||
|
OF_PRIMITIVE_TRIANGLES,
|
||||||
|
OF_PRIMITIVE_TRIANGLE_STRIP,
|
||||||
|
OF_PRIMITIVE_TRIANGLE_FAN,
|
||||||
|
OF_PRIMITIVE_LINES,
|
||||||
|
OF_PRIMITIVE_LINE_STRIP,
|
||||||
|
OF_PRIMITIVE_LINE_LOOP,
|
||||||
|
OF_PRIMITIVE_POINTS
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255, 255);
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==2){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==3){
|
||||||
|
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
if(fileNameColor=="RED")
|
||||||
|
{
|
||||||
|
currentSecondImageColor.r=255;
|
||||||
|
currentSecondImageColor.g=0;
|
||||||
|
currentSecondImageColor.b=0;
|
||||||
|
currentSecondImageColor.a=255;
|
||||||
|
|
||||||
|
} else if(fileNameColor=="GREEN")
|
||||||
|
{
|
||||||
|
currentSecondImageColor.r=0;
|
||||||
|
currentSecondImageColor.g=255;
|
||||||
|
currentSecondImageColor.b=0;
|
||||||
|
currentSecondImageColor.a=255;
|
||||||
|
|
||||||
|
} else if(fileNameColor=="BLUE")
|
||||||
|
{
|
||||||
|
currentSecondImageColor.r=0;
|
||||||
|
currentSecondImageColor.g=0;
|
||||||
|
currentSecondImageColor.b=255;
|
||||||
|
currentSecondImageColor.a=255;
|
||||||
|
|
||||||
|
} else if(fileNameColor=="FADING")
|
||||||
|
{
|
||||||
|
currentSecondImageColor.r= 255;
|
||||||
|
currentSecondImageColor.g= 255;
|
||||||
|
currentSecondImageColor.b= 255;
|
||||||
|
currentSecondImageColor.a= 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
//x++;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//y++;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> ColorSingleAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
int thisDiff;
|
||||||
|
|
||||||
|
if(fileNameColor=="RED")
|
||||||
|
{
|
||||||
|
//thisDiff=abs(imageColor1.r);
|
||||||
|
|
||||||
|
thisDiff=abs(255-imageColor1.r);
|
||||||
|
} else if(fileNameColor=="GREEN")
|
||||||
|
{
|
||||||
|
//thisDiff=abs(imageColor1.g);
|
||||||
|
|
||||||
|
thisDiff=abs(255-imageColor1.g);
|
||||||
|
|
||||||
|
} else if(fileNameColor=="BLUE")
|
||||||
|
{
|
||||||
|
//thisDiff=abs(imageColor1.b);
|
||||||
|
|
||||||
|
thisDiff=abs(255-imageColor1.b);
|
||||||
|
|
||||||
|
} else if(fileNameColor=="FADING") {
|
||||||
|
|
||||||
|
//thisDiff=imageColor1.getBrightness();
|
||||||
|
thisDiff=255-imageColor1.getBrightness();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
float multiplier=8.0;
|
||||||
|
|
||||||
|
differences.push_back(multiplier* thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
~ author: dviid
|
~ author: dviid
|
||||||
~ contact: dviid@labs.ciid.dk
|
~ contact: dviid@labs.ciid.dk
|
||||||
*/
|
*/
|
||||||
@@ -32,6 +32,7 @@ protected:
|
|||||||
|
|
||||||
bool _RUN_DONE;
|
bool _RUN_DONE;
|
||||||
string fileNameTag;
|
string fileNameTag;
|
||||||
|
string fileNameColor;
|
||||||
float r,g,b;
|
float r,g,b;
|
||||||
|
|
||||||
int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt;
|
int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt;
|
||||||
@@ -60,6 +61,24 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage3;
|
ofxCvGrayscaleImage cvGrayImage3;
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
|
ofxCvFloatImage cvFloatImage1;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
|
//this is the temporary container to allow us to convert and save out greyscale images
|
||||||
|
ofxCvColorImage cvConvertorImage;
|
||||||
|
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
int vertexSubsampling;
|
||||||
|
int chooseColour;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+598
-43
@@ -10,20 +10,52 @@ using Poco::Timer;
|
|||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
NUM_RUN = 5;
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
|
||||||
|
|
||||||
int acq_run_time = 20; // 20 seconds of acquiring per run
|
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
_mesh_size_multiplier = 10;
|
||||||
|
vertexSubsampling = 1;
|
||||||
|
chooseColour = 5;
|
||||||
|
multiplier = 4.0;
|
||||||
|
|
||||||
|
blendMode = OF_BLENDMODE_ADD;
|
||||||
|
//blendMode = OF_BLENDMODE_MULTIPLY;
|
||||||
|
//blendMode = OF_BLENDMODE_SUBTRACT;
|
||||||
|
//blendMode = OF_BLENDMODE_ALPHA;
|
||||||
|
//blendMode = OF_BLENDMODE_SCREEN;
|
||||||
|
|
||||||
|
meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
||||||
|
//meshMode = OF_PRIMITIVE_LINES;
|
||||||
|
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_POINTS;
|
||||||
|
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_diffnoise", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME DiffNoiseAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
// or 10 times per second = every 100 ms
|
// or 10 times per second = every 100 ms
|
||||||
|
|
||||||
_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();
|
//create_dir_allocate_images();
|
||||||
|
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -36,8 +68,11 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
//for an ofxOpenCv.h image i would like to use..."
|
image1.clear();
|
||||||
//image3.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h);
|
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
|
||||||
@@ -48,9 +83,28 @@ 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);
|
||||||
@@ -59,7 +113,7 @@ void DiffNoiseAnalysis::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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,7 +125,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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -119,40 +173,133 @@ void DiffNoiseAnalysis::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.erode();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
|
||||||
|
//cvColorImage1.blur(5);
|
||||||
|
//cvColorImage2.blur(5);
|
||||||
|
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||||
|
//cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||||
|
|
||||||
|
//cvGrayImage1.convertToRange(0.0, 255.0);
|
||||||
|
//cvGrayImage2.convertToRange(0.0, 255.0);
|
||||||
|
|
||||||
|
//cvGrayImage1.adaptiveThreshold( 200, 0);
|
||||||
|
//cvGrayImage2.adaptiveThreshold( 200, 0);
|
||||||
|
|
||||||
|
//cvGrayImage1.contrastStretch();
|
||||||
|
//cvGrayImage2.contrastStretch();
|
||||||
|
|
||||||
|
//cvGrayImage1.brightnessContrast(1.0,0.5);
|
||||||
|
//cvGrayImage2.brightnessContrast(1.0,0.5);
|
||||||
|
|
||||||
|
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||||
|
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||||
|
|
||||||
|
cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||||
|
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||||
|
|
||||||
|
//cvFloatImage1 = cvColorImage1;
|
||||||
//cvGrayImage1 = cvColorImage1;
|
//cvGrayImage1 = cvColorImage1;
|
||||||
//cvGrayImage2 = cvColorImage2;
|
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
||||||
//cvGrayDiff1.erode();
|
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
||||||
//cvGrayDiff1.contrastStretch();
|
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
//cvGrayDiff1.blur(5);
|
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
//cvGrayDiff1.dilate();
|
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
|
|
||||||
cvColorImage1.contrastStretch();
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
cvColorImage1.invert();
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
cvColorImage1.blur(5);
|
|
||||||
cvColorImage1.erode();
|
|
||||||
cvColorImage1.blur(5);
|
|
||||||
cvColorImage1.erode();
|
|
||||||
cvColorImage1.contrastStretch();
|
|
||||||
|
|
||||||
//////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
string file_name;
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_DiffNoiseAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
// convert the CV image
|
||||||
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
|
//image5.setFromPixels(cvColorImage2.getPixelsRef());
|
||||||
|
|
||||||
ofSaveImage(cvColorImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//subtract background begin///////////////
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
|
//DIFFERENCING SUBSEQUENT IMAGES
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||||
|
imagePixels1[i]-=imagePixels2[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
//DIFFERENCING THE BACKGROUND
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
|
//string file_name;
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_DiffNoiseAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
|
//flag that we are finished
|
||||||
|
meshIsComplete=true;
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
// }
|
//}
|
||||||
|
} else {
|
||||||
|
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
||||||
|
/*
|
||||||
|
_RUN_DONE = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
meshIsComplete=false;
|
||||||
|
_synth_save_cnt=0;
|
||||||
|
|
||||||
// _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
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(3);
|
Thread::sleep(3);
|
||||||
|
|
||||||
@@ -192,6 +339,26 @@ void DiffNoiseAnalysis::displayresults()
|
|||||||
// this runs at frame rate = 33 ms for 30 FPS
|
// this runs at frame rate = 33 ms for 30 FPS
|
||||||
void DiffNoiseAnalysis::draw()
|
void DiffNoiseAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
ofEnableSmoothing();
|
||||||
|
|
||||||
|
ofEnableLighting();
|
||||||
|
ofEnableSeparateSpecularLight();
|
||||||
|
light.setPointLight();
|
||||||
|
|
||||||
|
light.enable();
|
||||||
|
lightStatic.enable();
|
||||||
|
|
||||||
|
light.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
||||||
|
|
||||||
|
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,-1);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
ofSetLineWidth(1.0f);
|
||||||
|
glPointSize(5.0f);
|
||||||
|
|
||||||
|
ofEnableBlendMode(blendMode);
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -238,7 +405,6 @@ void DiffNoiseAnalysis::draw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt <= _frame_cnt_max) {
|
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt <= _frame_cnt_max) {
|
||||||
|
|
||||||
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
|
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
|
||||||
@@ -395,23 +561,412 @@ 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";
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(file_name);
|
||||||
|
}
|
||||||
|
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
|
||||||
|
|
||||||
_save_cnt++;
|
void DiffNoiseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
mesh.setMode(meshMode);
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255);
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==2){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==3){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==4){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
int randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==5){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
int randomJitter2 = 0;
|
||||||
|
int randomJitter = 0;
|
||||||
|
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
ofColor currentSecondImageBW;
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> DiffNoiseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
||||||
|
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
int thisDiff=-abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getLightness());
|
||||||
|
//int thisDiff=-abs(imageColor1.r);
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
differences.push_back(multiplier * thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,4 +59,24 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
int vertexSubsampling;
|
||||||
|
int chooseColour;
|
||||||
|
ofPrimitiveMode meshMode;
|
||||||
|
ofBlendMode blendMode;
|
||||||
|
float multiplier;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+218
-43
@@ -10,19 +10,41 @@ using Poco::Timer;
|
|||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
void IResponseAnalysis::setup(int camWidth, int camHeight)
|
void IResponseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
NUM_RUN = 5;
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_iresponse", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
int acq_run_time = 20; // 20 seconds of acquiring per run
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
|
||||||
|
_mesh_size_multiplier=4;
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_iresponse", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
|
||||||
|
_mesh_size_multiplier=8;
|
||||||
|
|
||||||
|
//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
|
||||||
// or 10 times per second = every 100 ms
|
// or 10 times per second = every 100 ms
|
||||||
|
|
||||||
_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();
|
//create_dir_allocate_images();
|
||||||
_synth_save_cnt = 0;
|
_synth_save_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -34,6 +56,12 @@ 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
|
||||||
@@ -43,9 +71,26 @@ 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();
|
||||||
|
|
||||||
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);
|
||||||
@@ -53,21 +98,17 @@ void IResponseAnalysis::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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IResponseAnalysis::acquire()
|
void IResponseAnalysis::acquire()
|
||||||
{
|
{
|
||||||
|
|
||||||
Timer* save_timer;
|
Timer* save_timer;
|
||||||
TimerCallback<IResponseAnalysis> save_callback(*this, &IResponseAnalysis::save_cb);
|
TimerCallback<IResponseAnalysis> save_callback(*this, &IResponseAnalysis::save_cb);
|
||||||
|
|
||||||
_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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -88,6 +129,7 @@ void IResponseAnalysis::acquire()
|
|||||||
|
|
||||||
void IResponseAnalysis::synthesise()
|
void IResponseAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
|
cout<<"SYNTHESISING IRESPONSE";
|
||||||
|
|
||||||
//cout << "IResponseAnalysis::saving synthesis...\n";
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
@@ -107,43 +149,66 @@ void IResponseAnalysis::synthesise()
|
|||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//cout << "LOADED image1!!!" << endl;
|
//cout << "LOADED image1!!!" << endl;
|
||||||
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
//subtract background begin///////////////
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
cvGrayImage1 = cvColorImage1;
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
cvGrayImage2 = cvColorImage2;
|
//ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
//background subtraction//
|
||||||
cvGrayDiff1.erode();
|
/*
|
||||||
cvGrayDiff1.contrastStretch();
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
//cvGrayDiff1.blur(5);
|
//unsigned char val=imagePixels1[i];
|
||||||
//cvGrayDiff1.dilate();
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
//cvGrayDiff1.contrastStretch();
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
//flag the main app that we aren't read yet
|
||||||
string file_name;
|
meshIsComplete=false;
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
//meshPix=make3DZmap(image1, image5, _background);
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//flag that we are finished
|
||||||
|
meshIsComplete=true;
|
||||||
ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
||||||
|
/*
|
||||||
|
_RUN_DONE = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
meshIsComplete=false;
|
||||||
|
_synth_save_cnt=0;
|
||||||
|
|
||||||
// _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
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(3);
|
Thread::sleep(3);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -324,7 +389,7 @@ void IResponseAnalysis::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();
|
||||||
@@ -347,19 +412,129 @@ 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";
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(file_name);
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IResponseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,0,0);
|
||||||
|
|
||||||
|
int chooseColour=1 ;
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x++;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<float> IResponseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//the current version compares how bright this pixel is with how bright it would be following inverse square fall off from centre
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
||||||
|
|
||||||
|
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
||||||
|
|
||||||
|
//float _presumedBrightness=255;
|
||||||
|
|
||||||
|
int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
float multiplier=4.0;
|
||||||
|
|
||||||
|
differences.push_back(multiplier * thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,4 +58,12 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
//returns ofPixels but these pixels actually hold depth data.
|
||||||
|
//ofPixels make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
};
|
};
|
||||||
|
|||||||
+655
-50
@@ -10,19 +10,60 @@ using Poco::Timer;
|
|||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
#define TRESHOLD 80
|
||||||
|
#define MAXBLOBS 15
|
||||||
|
|
||||||
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = 5;
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
int acq_run_time = 20; // 20 seconds of acquiring per run
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_relaxrate", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
_mesh_size_multiplier = 8;
|
||||||
|
vertexSubsampling_x = 1; //must be at least '1'
|
||||||
|
vertexSubsampling_y = 5; //must be at least '1'
|
||||||
|
chooseColour = 2;
|
||||||
|
multiplier = 4.0;
|
||||||
|
|
||||||
|
//blendMode = OF_BLENDMODE_ADD;
|
||||||
|
//blendMode = OF_BLENDMODE_MULTIPLY;
|
||||||
|
blendMode = OF_BLENDMODE_SUBTRACT;
|
||||||
|
//blendMode = OF_BLENDMODE_ALPHA;
|
||||||
|
//blendMode = OF_BLENDMODE_SCREEN;
|
||||||
|
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
||||||
|
//meshMode = OF_PRIMITIVE_LINES;
|
||||||
|
meshMode = OF_PRIMITIVE_LINE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_POINTS;
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_relaxrate", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME RelaxRateAnalysis " << acq_run_time << 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;
|
||||||
|
|
||||||
|
|
||||||
|
//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
|
||||||
// or 10 times per second = every 100 ms
|
// or 10 times per second = every 100 ms
|
||||||
|
|
||||||
_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();
|
//create_dir_allocate_images();
|
||||||
|
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_level = 0;
|
_level = 0;
|
||||||
@@ -37,6 +78,12 @@ void RelaxRateAnalysis::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
|
||||||
@@ -46,8 +93,23 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
|||||||
image4.setUseTexture(false);
|
image4.setUseTexture(false);
|
||||||
image5.setUseTexture(false);
|
image5.setUseTexture(false);
|
||||||
|
|
||||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
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);
|
||||||
|
|
||||||
|
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
||||||
|
// that we're getting in OSX/Windows and is maybe crashing Windows
|
||||||
|
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
||||||
|
cvColorImage1.clear();
|
||||||
|
cvGrayImage1.clear();
|
||||||
|
cvGrayDiff1.clear();
|
||||||
|
|
||||||
|
cvColorImage2.clear();
|
||||||
|
cvGrayImage2.clear();
|
||||||
|
cvGrayDiff2.clear();
|
||||||
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||||
@@ -57,6 +119,7 @@ void RelaxRateAnalysis::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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +132,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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -89,20 +152,20 @@ void RelaxRateAnalysis::acquire()
|
|||||||
|
|
||||||
void RelaxRateAnalysis::synthesise()
|
void RelaxRateAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
//cout << "IResponseAnalysis::saving synthesis...\n";
|
// cout << "RelaxRate::saving synthesis...\n";
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
||||||
|
|
||||||
//cout << "IResponseAnalysis::synthesis FOR LOOP...\n";
|
// cout << "StrobeAnalysis::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;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
@@ -114,34 +177,143 @@ void RelaxRateAnalysis::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;
|
//cvColorImage1.erode();
|
||||||
cvGrayImage2 = cvColorImage2;
|
//cvColorImage1.erode();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
cvColorImage1.blur(1);
|
||||||
cvGrayDiff1.erode();
|
cvColorImage2.blur(1);
|
||||||
cvGrayDiff1.contrastStretch();
|
|
||||||
cvGrayDiff1.blur(5);
|
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
||||||
|
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
||||||
|
|
||||||
|
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||||
|
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||||
|
|
||||||
|
//cvGrayImage1.convertToRange(0.0, 255.0);
|
||||||
|
//cvGrayImage2.convertToRange(0.0, 255.0);
|
||||||
|
|
||||||
|
//cvGrayImage1.adaptiveThreshold( 200, 0);
|
||||||
|
//cvGrayImage2.adaptiveThreshold( 200, 0);
|
||||||
|
|
||||||
|
//cvGrayImage1.contrastStretch();
|
||||||
|
//cvGrayImage2.contrastStretch();
|
||||||
|
|
||||||
|
cvGrayDiff1.absDiff(cvGrayImage1, cvGrayImage2);
|
||||||
|
|
||||||
|
//cvGrayDiff1.brightnessContrast(1.0,0.5);
|
||||||
|
|
||||||
|
//cvGrayImage1.brightnessContrast(1.0,0.5);
|
||||||
|
//cvGrayImage2.brightnessContrast(1.0,0.5);
|
||||||
|
|
||||||
|
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||||
|
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||||
|
|
||||||
|
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||||
|
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||||
|
|
||||||
|
//cvFloatImage1 = cvColorImage1;
|
||||||
|
//cvGrayImage1 = cvColorImage1;
|
||||||
|
|
||||||
|
|
||||||
|
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
|
||||||
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
|
|
||||||
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
|
|
||||||
|
// convert the CV image
|
||||||
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
|
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
||||||
|
|
||||||
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//subtract background begin///////////////
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
|
//DIFFERENCING SUBSEQUENT IMAGES
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||||
|
imagePixels1[i]-=imagePixels2[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//DIFFERENCING THE BACKGROUND
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
string file_name;
|
//string file_name;
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_RelaxRateAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_RelaxRateAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
//flag that we are finished
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
meshIsComplete=true;
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
||||||
|
/*
|
||||||
|
_RUN_DONE = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
meshIsComplete=false;
|
||||||
|
_synth_save_cnt=0;
|
||||||
|
|
||||||
// _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
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(3);
|
Thread::sleep(10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RelaxRateAnalysis::displayresults()
|
void RelaxRateAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -149,7 +321,7 @@ void RelaxRateAnalysis::displayresults()
|
|||||||
|
|
||||||
if(_state == STATE_STOP) 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);
|
||||||
@@ -158,7 +330,7 @@ void RelaxRateAnalysis::displayresults()
|
|||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
// cout << "didn't load image" << endl;
|
// cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
||||||
@@ -169,7 +341,6 @@ void RelaxRateAnalysis::displayresults()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,12 +348,28 @@ void RelaxRateAnalysis::displayresults()
|
|||||||
void RelaxRateAnalysis::draw()
|
void RelaxRateAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ofEnableSmoothing();
|
||||||
|
|
||||||
|
ofEnableLighting();
|
||||||
|
ofEnableSeparateSpecularLight();
|
||||||
|
light.setPointLight();
|
||||||
|
|
||||||
|
light.enable();
|
||||||
|
lightStatic.enable();
|
||||||
|
light.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
||||||
|
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,-1);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
ofSetLineWidth(2.0f);
|
||||||
|
glPointSize(1.0f);
|
||||||
|
|
||||||
|
ofEnableBlendMode(blendMode);
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@@ -213,6 +400,7 @@ 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";
|
||||||
@@ -265,7 +453,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) {
|
||||||
|
|
||||||
@@ -313,15 +501,10 @@ void RelaxRateAnalysis::draw()
|
|||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
{
|
||||||
//cout << "_show_image...\n" << endl;
|
for(int i=0;i<cvContourFinderVectDisplay.size();i++){
|
||||||
|
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
|
||||||
@@ -341,19 +524,441 @@ 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";
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void RelaxRateAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
mesh.setMode(meshMode);
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255);
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling_x;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling_y;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==2){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling_x;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling_y;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==3){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling_x;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling_y;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==4){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
int randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
x=x+vertexSubsampling_x;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling_y;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==5){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
int randomJitter2 = 0;
|
||||||
|
int randomJitter = 0;
|
||||||
|
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
ofColor currentSecondImageBW;
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling_x;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling_y;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> RelaxRateAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
||||||
|
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
int thisDiff=-abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getLightness());
|
||||||
|
//int thisDiff=-abs(imageColor1.r);
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
differences.push_back(multiplier * thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+32
-1
@@ -5,8 +5,12 @@
|
|||||||
|
|
||||||
#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:
|
||||||
@@ -19,6 +23,7 @@ public:
|
|||||||
void acquire();
|
void acquire();
|
||||||
void synthesise();
|
void synthesise();
|
||||||
void displayresults();
|
void displayresults();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
@@ -26,12 +31,19 @@ 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 _treshold;
|
||||||
|
int _maxblobs;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
ofImage image3;
|
||||||
@@ -54,6 +66,25 @@ protected:
|
|||||||
ofxCvGrayscaleImage cvGrayImage3;
|
ofxCvGrayscaleImage cvGrayImage3;
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
ofxCvGrayscaleImage cvGrayImage4;
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
vector<rfiCvContourFinder*> cvContourFinderVect;
|
||||||
|
vector<rfiCvContourFinder*> cvContourFinderVectDisplay;
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
int vertexSubsampling_x;
|
||||||
|
int vertexSubsampling_y;
|
||||||
|
int chooseColour;
|
||||||
|
ofPrimitiveMode meshMode;
|
||||||
|
ofBlendMode blendMode;
|
||||||
|
float multiplier;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+601
-113
@@ -5,6 +5,7 @@
|
|||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
#include "RefractiveIndex.h"
|
#include "RefractiveIndex.h"
|
||||||
|
|
||||||
|
//#include "ofxXmlSettings.h"
|
||||||
#include "ofxOpenCv.h"
|
#include "ofxOpenCv.h"
|
||||||
|
|
||||||
using Poco::Timer;
|
using Poco::Timer;
|
||||||
@@ -13,12 +14,71 @@ using Poco::Thread;
|
|||||||
|
|
||||||
#define STATE_SCAN 0
|
#define STATE_SCAN 0
|
||||||
#define STATE_ANALYSIS 1
|
#define STATE_ANALYSIS 1
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = 5;
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
int acq_run_time = 15; // 10 seconds of acquiring per run
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shadowscapes", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
_mesh_size_multiplier = 8;
|
||||||
|
vertexSubsampling = 1;
|
||||||
|
chooseColour = 5;
|
||||||
|
multiplier = 4.0;
|
||||||
|
|
||||||
|
ofSetLineWidth(5.0f);
|
||||||
|
glPointSize(5.0f);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
//blendMode = OF_BLENDMODE_ADD;
|
||||||
|
//blendMode = OF_BLENDMODE_MULTIPLY;
|
||||||
|
//blendMode = OF_BLENDMODE_SUBTRACT;
|
||||||
|
blendMode = OF_BLENDMODE_ALPHA;
|
||||||
|
//blendMode = OF_BLENDMODE_SCREEN;
|
||||||
|
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
||||||
|
meshMode = OF_PRIMITIVE_LINES;
|
||||||
|
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_POINTS;
|
||||||
|
|
||||||
|
///setup light
|
||||||
|
ofEnableLighting();
|
||||||
|
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||||
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||||
|
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHT0);
|
||||||
|
|
||||||
|
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHT1);
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shadowscapes", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME ShadowScapesAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
int screenSpan;
|
int screenSpan;
|
||||||
if (_dir == V) screenSpan = ofGetHeight();
|
if (_dir == V) screenSpan = ofGetHeight();
|
||||||
@@ -33,8 +93,6 @@ 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
|
||||||
|
|
||||||
//create_dir(); // this makes both synth and analysis folder structures
|
|
||||||
|
|
||||||
_scanLineWidth = 100.0;
|
_scanLineWidth = 100.0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_save_cnt = 0;
|
_save_cnt = 0;
|
||||||
@@ -46,6 +104,12 @@ 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
|
||||||
@@ -55,9 +119,27 @@ 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();
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -65,6 +147,8 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowScapesAnalysis::acquire()
|
void ShadowScapesAnalysis::acquire()
|
||||||
@@ -78,26 +162,22 @@ void ShadowScapesAnalysis::acquire()
|
|||||||
_line = 0;
|
_line = 0;
|
||||||
_RUN_DONE = false;
|
_RUN_DONE = false;
|
||||||
|
|
||||||
create_dir();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
//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";
|
||||||
|
|
||||||
@@ -111,7 +191,7 @@ void ShadowScapesAnalysis::synthesise()
|
|||||||
}
|
}
|
||||||
|
|
||||||
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])){
|
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 //////////////////////////
|
||||||
@@ -119,38 +199,108 @@ 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;
|
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||||
cvGrayImage2 = cvColorImage2;
|
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
cvGrayDiff1.erode();
|
//cvGrayDiff1.erode();
|
||||||
cvGrayDiff1.contrastStretch();
|
|
||||||
cvGrayDiff1.blur(5);
|
cvGrayImage1.dilate();
|
||||||
cvGrayDiff1.dilate();
|
cvGrayImage1.blur(5);
|
||||||
cvGrayDiff1.contrastStretch();
|
cvGrayImage1.contrastStretch();
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
string file_name;
|
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||||
|
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||||
|
|
||||||
if(_dir == H) {
|
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_H_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||||
|
|
||||||
|
//cvFloatImage1 = cvColorImage1;
|
||||||
|
//cvGrayImage1 = cvColorImage1;
|
||||||
|
|
||||||
|
|
||||||
|
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
|
||||||
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
|
|
||||||
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
|
|
||||||
|
// convert the CV image
|
||||||
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
|
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
||||||
|
|
||||||
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_dir == V) {
|
//subtract background begin///////////////
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_V_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_dir == D) {
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_D_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
}
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//DIFFERENCING SUBSEQUENT IMAGES
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||||
|
imagePixels1[i]-=imagePixels2[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
//DIFFERENCING THE BACKGROUND
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
|
//string file_name;
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShadowScapeAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
|
//flag that we are finished
|
||||||
|
meshIsComplete=true;
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,41 +336,6 @@ 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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -368,9 +483,9 @@ void ShadowScapesAnalysis::draw()
|
|||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl;
|
//cout << "_anim_cnt = " << _anim_cnt-(_anim_cnt_max-_fade_in_frames) << endl;
|
||||||
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
|
fade = ofMap(_anim_cnt-(_anim_cnt_max-_fade_in_frames), 0, _fade_in_frames, 0, 255);
|
||||||
cout << "fade down = " << fade << endl;
|
//cout << "fade down = " << fade << endl;
|
||||||
|
|
||||||
for (int i=0; i <= 15; i++){
|
for (int i=0; i <= 15; i++){
|
||||||
|
|
||||||
@@ -400,7 +515,6 @@ 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;
|
||||||
@@ -416,43 +530,20 @@ 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();
|
||||||
|
|
||||||
//cvGrayDiff1.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
|
|
||||||
// THE OLD SHIT
|
|
||||||
/*
|
|
||||||
ofEnableAlphaBlending();
|
|
||||||
|
|
||||||
ofSetColor(255, 255, 255, 200);
|
|
||||||
image3.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR);
|
|
||||||
image4.setFromPixels(image2.getPixels(),image2.width,image2.height, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image3.getPixels(), image3.width, image3.height);
|
|
||||||
cvColorImage2.setFromPixels(image4.getPixels(), image4.width, image4.height);
|
|
||||||
|
|
||||||
cvGrayImage1 = cvColorImage1;
|
|
||||||
cvGrayImage2 = cvColorImage2;
|
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
|
||||||
cvGrayDiff1.contrastStretch();
|
|
||||||
cvGrayDiff1.dilate();
|
|
||||||
|
|
||||||
cvGrayDiff1.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
|
||||||
*/
|
|
||||||
|
|
||||||
//image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
// display results of the synthesis
|
||||||
_RUN_DONE = true;
|
_RUN_DONE = true;
|
||||||
|
|
||||||
|
// clear allocated memory...?
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,17 +559,6 @@ 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) {
|
||||||
@@ -493,8 +573,416 @@ 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(file_name);
|
||||||
|
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ShadowScapesAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
mesh.setMode(meshMode);
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255);
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==2){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==3){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==4){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
int randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==5){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
int randomJitter2 = 0;
|
||||||
|
int randomJitter = 0;
|
||||||
|
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
ofColor currentSecondImageBW;
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> ShadowScapesAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
|
||||||
|
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
||||||
|
|
||||||
|
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
||||||
|
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
int thisDiff=-abs(imageColor1.getBrightness()+ofRandom(-50,50));
|
||||||
|
//int thisDiff=abs(imageColor1.getLightness());
|
||||||
|
//int thisDiff=-abs(imageColor1.r);
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
differences.push_back(multiplier * thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,4 +66,20 @@ protected:
|
|||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
int vertexSubsampling;
|
||||||
|
int chooseColour;
|
||||||
|
ofPrimitiveMode meshMode;
|
||||||
|
ofBlendMode blendMode;
|
||||||
|
float multiplier;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -10,18 +10,80 @@ using Poco::Timer;
|
|||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = 5;
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
int acq_run_time = 20; // 20 seconds of acquiring per run
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_shapefromshading", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
_mesh_size_multiplier = 8;
|
||||||
|
vertexSubsampling = 1;
|
||||||
|
chooseColour = 5;
|
||||||
|
multiplier = 3.0;
|
||||||
|
|
||||||
|
ofSetLineWidth(5.0f);
|
||||||
|
glPointSize(5.0f);
|
||||||
|
|
||||||
|
//blendMode = OF_BLENDMODE_ADD;
|
||||||
|
//blendMode = OF_BLENDMODE_MULTIPLY;
|
||||||
|
//blendMode = OF_BLENDMODE_SUBTRACT;
|
||||||
|
blendMode = OF_BLENDMODE_ALPHA;
|
||||||
|
//blendMode = OF_BLENDMODE_SCREEN;
|
||||||
|
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
||||||
|
meshMode = OF_PRIMITIVE_LINES;
|
||||||
|
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_POINTS;
|
||||||
|
|
||||||
|
///setup light
|
||||||
|
ofEnableLighting();
|
||||||
|
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||||
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||||
|
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHT0);
|
||||||
|
|
||||||
|
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||||
|
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHT1);
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shapefromshading", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME ShapeFromShadingAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
|
||||||
|
//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
|
||||||
// or 10 times per second = every 100 ms
|
// or 10 times per second = every 100 ms
|
||||||
|
|
||||||
_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();
|
//create_dir_allocate_images();
|
||||||
_synth_save_cnt = 0;
|
_synth_save_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_frame_cnt = 0;
|
_frame_cnt = 0;
|
||||||
@@ -30,10 +92,15 @@ 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
|
||||||
@@ -43,9 +110,28 @@ 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);
|
||||||
@@ -54,6 +140,8 @@ 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,7 +155,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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
_animation_cnt1 = 0;
|
_animation_cnt1 = 0;
|
||||||
_animation_cnt2 = 0;
|
_animation_cnt2 = 0;
|
||||||
@@ -128,33 +216,158 @@ void ShapeFromShadingAnalysis::synthesise()
|
|||||||
// cout << "LOADED image1!!!" << endl;
|
// cout << "LOADED image1!!!" << endl;
|
||||||
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
||||||
|
|
||||||
|
if(_saved_filenames_analysis[i].find("QUAD1")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameQuad = "QUAD1";
|
||||||
|
cout<<"FOUND QUAD1"<<endl;
|
||||||
|
} else if (_saved_filenames_analysis[i].find("QUAD2")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameQuad = "QUAD2";
|
||||||
|
cout<<"FOUND QUAD2"<<endl;
|
||||||
|
} else if(_saved_filenames_analysis[i].find("QUAD3")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameQuad = "QUAD3";
|
||||||
|
cout<<"FOUND QUAD3"<<endl;
|
||||||
|
} else if(_saved_filenames_analysis[i].find("QUAD4")<_saved_filenames_analysis[i].length())
|
||||||
|
{
|
||||||
|
fileNameQuad = "QUAD4";
|
||||||
|
cout<<"FOUND QUAD4"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////// 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);
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
||||||
|
|
||||||
cvGrayImage1 = cvColorImage1;
|
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||||
cvGrayImage2 = cvColorImage2;
|
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||||
cvGrayDiff1.erode();
|
//cvGrayDiff1.erode();
|
||||||
cvGrayDiff1.contrastStretch();
|
|
||||||
//cvGrayDiff1.blur(5);
|
cvGrayImage1.dilate();
|
||||||
//cvGrayDiff1.dilate();
|
cvGrayImage1.blur(5);
|
||||||
//cvGrayDiff1.contrastStretch();
|
cvGrayImage1.contrastStretch();
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
string file_name;
|
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||||
|
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||||
|
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//cvFloatImage1 = cvColorImage1;
|
||||||
|
//cvGrayImage1 = cvColorImage1;
|
||||||
|
|
||||||
ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
|
||||||
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
|
|
||||||
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
|
|
||||||
|
// convert the CV image
|
||||||
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
|
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
||||||
|
|
||||||
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//subtract background begin///////////////
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
|
//DIFFERENCING SUBSEQUENT IMAGES
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||||
|
imagePixels1[i]-=imagePixels2[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//DIFFERENCING THE BACKGROUND
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
|
//string file_name;
|
||||||
|
|
||||||
|
if(fileNameQuad=="QUAD1")
|
||||||
|
{
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
|
||||||
|
} else if(fileNameQuad=="QUAD2")
|
||||||
|
{
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
} else if(fileNameQuad=="QUAD3")
|
||||||
|
{
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
} else if(fileNameQuad=="QUAD4") {
|
||||||
|
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
|
//flag that we are finished
|
||||||
|
meshIsComplete=true;
|
||||||
_synth_save_cnt++;
|
_synth_save_cnt++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +408,48 @@ void ShapeFromShadingAnalysis::displayresults()
|
|||||||
void ShapeFromShadingAnalysis::draw()
|
void ShapeFromShadingAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//rotate light around origin ofviewspace
|
||||||
|
float xx=cos(ofGetElapsedTimef()*0.4)*150;
|
||||||
|
float yy=sin(ofGetElapsedTimef()*0.4)*150;
|
||||||
|
float zz=0;
|
||||||
|
|
||||||
|
if(fileNameQuad=="QUAD1")
|
||||||
|
{
|
||||||
|
|
||||||
|
GLfloat light_position[] = { 1000, 1000, 20, 0.0 };
|
||||||
|
GLfloat light_position1[] = { 1000, 1000, 20, 0.0 };
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
|
} else if(fileNameQuad=="QUAD2")
|
||||||
|
{
|
||||||
|
|
||||||
|
GLfloat light_position[] = { 1000, -1000, 20, 0.0 };
|
||||||
|
GLfloat light_position1[] = { 1000, -1000, 20, 0.0 };
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
|
|
||||||
|
} else if(fileNameQuad=="QUAD3")
|
||||||
|
{
|
||||||
|
|
||||||
|
GLfloat light_position[] = {-1000, 1000, 20, 0.0 };
|
||||||
|
GLfloat light_position1[] = { -1000, 1000, 20, 0.0 };
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
|
|
||||||
|
} else if(fileNameQuad=="QUAD4")
|
||||||
|
{
|
||||||
|
GLfloat light_position[] = { -1000, -1000, 20, 0.0 };
|
||||||
|
GLfloat light_position1[] = { -1000, -1000, 20, 0.0 };
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -514,7 +769,7 @@ void ShapeFromShadingAnalysis::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();
|
||||||
@@ -539,20 +794,416 @@ 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";
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(file_name);
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ShapeFromShadingAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
mesh.setMode(meshMode);
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255);
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==2){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==3){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==4){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
int randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==5){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
int randomJitter2 = 0;
|
||||||
|
int randomJitter = 0;
|
||||||
|
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
ofColor currentSecondImageBW;
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> ShapeFromShadingAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
|
||||||
|
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
||||||
|
|
||||||
|
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
||||||
|
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
int thisDiff=-abs(imageColor1.getBrightness()+ofRandom(-50,50));
|
||||||
|
//int thisDiff=abs(imageColor1.getLightness());
|
||||||
|
//int thisDiff=-abs(imageColor1.r);
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
differences.push_back(multiplier * thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
string quad;
|
string quad;
|
||||||
|
string fileNameQuad;
|
||||||
|
|
||||||
bool _RUN_DONE;
|
bool _RUN_DONE;
|
||||||
float _flip, _level;
|
float _flip, _level;
|
||||||
int _animation_cnt1;
|
int _animation_cnt1;
|
||||||
@@ -78,4 +80,23 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
int vertexSubsampling;
|
||||||
|
int chooseColour;
|
||||||
|
ofPrimitiveMode meshMode;
|
||||||
|
ofBlendMode blendMode;
|
||||||
|
float multiplier;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
};
|
};
|
||||||
|
|||||||
+619
-46
@@ -10,22 +10,55 @@ using Poco::Timer;
|
|||||||
using Poco::TimerCallback;
|
using Poco::TimerCallback;
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
|
|
||||||
|
#define NUMBER_RUNS 1
|
||||||
|
#define ACQUIRE_TIME 30
|
||||||
|
|
||||||
void StrobeAnalysis::setup(int camWidth, int camHeight)
|
void StrobeAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
NUM_RUN = 5;
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
int acq_run_time = 25; // 20 seconds of acquiring per run
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_strobe", NUMBER_RUNS);
|
||||||
|
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
|
||||||
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
|
//flag for main sketch
|
||||||
|
meshIsComplete=false;
|
||||||
|
_gotFirstImage=false;
|
||||||
|
_mesh_size_multiplier = 8;
|
||||||
|
vertexSubsampling = 3;
|
||||||
|
chooseColour = 2;
|
||||||
|
multiplier = 4.0;
|
||||||
|
|
||||||
|
//blendMode = OF_BLENDMODE_ADD;
|
||||||
|
//blendMode = OF_BLENDMODE_MULTIPLY;
|
||||||
|
blendMode = OF_BLENDMODE_SUBTRACT;
|
||||||
|
//blendMode = OF_BLENDMODE_ALPHA;
|
||||||
|
//blendMode = OF_BLENDMODE_SCREEN;
|
||||||
|
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
||||||
|
meshMode = OF_PRIMITIVE_LINES;
|
||||||
|
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
||||||
|
//meshMode = OF_PRIMITIVE_POINTS;
|
||||||
|
|
||||||
|
|
||||||
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_strobe", ACQUIRE_TIME);
|
||||||
|
cout << "ACQUIRE_TIME StrobeAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 100 files
|
DELTA_T_SAVE = 2*(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
|
||||||
|
|
||||||
_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
|
||||||
|
|
||||||
_strobe_interval = 1750; //every 1 seconds, or every thirty frames 30 frames
|
_strobe_interval = 2000; //every 1 seconds, or every thirty frames 30 frames
|
||||||
|
|
||||||
// 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();
|
//create_dir_allocate_images();
|
||||||
_synth_save_cnt = 0;
|
_synth_save_cnt = 0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
|
|
||||||
@@ -35,6 +68,12 @@ 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
|
||||||
@@ -44,9 +83,26 @@ 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();
|
||||||
|
|
||||||
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);
|
||||||
@@ -55,6 +111,7 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,7 +124,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();
|
create_dir_allocate_images();
|
||||||
|
|
||||||
// RUN ROUTINE
|
// RUN ROUTINE
|
||||||
//for(int i = 0; i < NUM_RUN; i++) {
|
//for(int i = 0; i < NUM_RUN; i++) {
|
||||||
@@ -107,47 +164,150 @@ void StrobeAnalysis::synthesise()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
// cout << "LOADED image1!!!" << endl;
|
//cout << "LOADED image1!!!" << endl;
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
|
||||||
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;
|
//cvColorImage1.erode();
|
||||||
//cvGrayImage2 = cvColorImage2;
|
//cvColorImage1.erode();
|
||||||
|
//cvColorImage1.dilate();
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
cvColorImage1.blur(1);
|
||||||
//cvGrayDiff1.erode();
|
cvColorImage2.blur(1);
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
//cvGrayDiff1.blur(5);
|
|
||||||
//cvGrayDiff1.dilate();
|
|
||||||
//cvGrayDiff1.contrastStretch();
|
|
||||||
|
|
||||||
cvGrayImage1.contrastStretch();
|
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
||||||
cvGrayImage1.blur(10);
|
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
||||||
cvGrayImage1.dilate();
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||||
string file_name;
|
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||||
|
|
||||||
file_name = ofToString(_synth_save_cnt, 2)+"_StrobeAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
//cvGrayImage1.convertToRange(0.0, 255.0);
|
||||||
|
//cvGrayImage2.convertToRange(0.0, 255.0);
|
||||||
|
|
||||||
//image4.setFromPixels(cvColorImage1.getPixelsRef(),image3.width, image3.height, OF_IMAGE_COLOR);
|
//cvGrayImage1.adaptiveThreshold( 200, 0);
|
||||||
|
//cvGrayImage2.adaptiveThreshold( 200, 0);
|
||||||
|
|
||||||
ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
//cvGrayImage1.contrastStretch();
|
||||||
//ofSaveImage(cvGrayDiff1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
//cvGrayImage2.contrastStretch();
|
||||||
_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
//}
|
cvGrayDiff1.absDiff(cvGrayImage1, cvGrayImage2);
|
||||||
|
|
||||||
|
cvGrayDiff1.brightnessContrast(1.0,0.5);
|
||||||
|
|
||||||
|
//cvGrayImage1.brightnessContrast(1.0,0.5);
|
||||||
|
//cvGrayImage2.brightnessContrast(1.0,0.5);
|
||||||
|
|
||||||
|
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||||
|
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||||
|
|
||||||
|
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||||
|
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||||
|
|
||||||
|
//cvFloatImage1 = cvColorImage1;
|
||||||
|
//cvGrayImage1 = cvColorImage1;
|
||||||
|
|
||||||
|
|
||||||
|
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
||||||
|
|
||||||
|
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
||||||
|
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
||||||
|
|
||||||
|
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
||||||
|
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
||||||
|
|
||||||
|
// convert the CV image
|
||||||
|
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||||
|
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
||||||
|
|
||||||
|
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||||
|
if(!_gotFirstImage){
|
||||||
|
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||||
|
_background=image1;
|
||||||
|
_gotFirstImage=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//subtract background begin///////////////
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||||
|
|
||||||
|
//DIFFERENCING SUBSEQUENT IMAGES
|
||||||
|
/*
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||||
|
imagePixels1[i]-=imagePixels2[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//DIFFERENCING THE BACKGROUND
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
//unsigned char val=imagePixels1[i];
|
||||||
|
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||||
|
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||||
|
imagePixels1[i]-=backgroundPixels[i];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
imagePixels1[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the images with their new background subtracted selves
|
||||||
|
image1.setFromPixels(imagePixels1);
|
||||||
|
|
||||||
|
//flag the main app that we aren't read yet
|
||||||
|
meshIsComplete=false;
|
||||||
|
|
||||||
|
//make a mesh - this mesh will be drawn in the main app
|
||||||
|
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||||
|
|
||||||
|
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||||
|
//string file_name;
|
||||||
|
|
||||||
|
//with jpgs this was refusing to save out
|
||||||
|
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_StrobeAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||||
|
_saved_filenames_synthesis.push_back(meshFileName);
|
||||||
|
|
||||||
|
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
|
//flag that we are finished
|
||||||
|
meshIsComplete=true;
|
||||||
|
_synth_save_cnt++;
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
||||||
|
/*
|
||||||
|
_RUN_DONE = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
meshIsComplete=false;
|
||||||
|
_synth_save_cnt=0;
|
||||||
|
|
||||||
// _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
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(3);
|
Thread::sleep(10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StrobeAnalysis::displayresults()
|
void StrobeAnalysis::displayresults()
|
||||||
@@ -184,6 +344,27 @@ void StrobeAnalysis::displayresults()
|
|||||||
void StrobeAnalysis::draw()
|
void StrobeAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ofEnableSmoothing();
|
||||||
|
|
||||||
|
ofEnableLighting();
|
||||||
|
ofEnableSeparateSpecularLight();
|
||||||
|
light.setPointLight();
|
||||||
|
|
||||||
|
light.enable();
|
||||||
|
lightStatic.enable();
|
||||||
|
|
||||||
|
light.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
||||||
|
|
||||||
|
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,-1);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
ofSetLineWidth(1.0f);
|
||||||
|
glPointSize(5.0f);
|
||||||
|
|
||||||
|
ofEnableBlendMode(blendMode);
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -202,7 +383,6 @@ void StrobeAnalysis::draw()
|
|||||||
ofRect(0, 0, ofGetWidth(), ofGetHeight());
|
ofRect(0, 0, ofGetWidth(), ofGetHeight());
|
||||||
//cout << "FADE IN STROBE TIME " << endl;
|
//cout << "FADE IN STROBE TIME " << 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)){
|
||||||
@@ -234,6 +414,7 @@ void StrobeAnalysis::draw()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//_state = STATE_SYNTHESISING;
|
//_state = STATE_SYNTHESISING;
|
||||||
_RUN_DONE = true;
|
_RUN_DONE = true;
|
||||||
@@ -347,7 +528,7 @@ void StrobeAnalysis::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();
|
||||||
@@ -372,20 +553,412 @@ 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";
|
||||||
|
|
||||||
ofSaveImage(RefractiveIndex::_pixels, _whole_file_path_analysis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
|
saveImageAnalysis(file_name);
|
||||||
_saved_filenames_analysis.push_back(_whole_file_path_analysis+"/"+file_name);
|
}
|
||||||
|
|
||||||
|
void StrobeAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
//get rid of all previous vectors and colours
|
||||||
|
mesh.clear();
|
||||||
|
mesh.setMode(meshMode);
|
||||||
|
|
||||||
|
ofColor meshColour=ofColor(255,255,255);
|
||||||
|
|
||||||
|
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
||||||
|
float zPlaneAverage=0;
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
zPlaneAverage+=sPixels[i];
|
||||||
|
}
|
||||||
|
if (sPixels.size()!=0) {
|
||||||
|
zPlaneAverage/=sPixels.size();
|
||||||
|
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==1){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==2){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==3){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor);
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==4){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
int randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||||
|
|
||||||
|
ofSeedRandom();
|
||||||
|
|
||||||
|
currentSecondImageColor.r = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.g = ofRandom(0,255);
|
||||||
|
currentSecondImageColor.b = ofRandom(0,255);
|
||||||
|
|
||||||
|
randomJitter = ofRandom(0,5);
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chooseColour==5){
|
||||||
|
|
||||||
|
for(int i=0;i<sPixels.size();i++){
|
||||||
|
|
||||||
|
int randomJitter2 = 0;
|
||||||
|
int randomJitter = 0;
|
||||||
|
|
||||||
|
ofColor currentSecondImageColor;
|
||||||
|
ofColor currentSecondImageBW;
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor(currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp());
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||||
|
|
||||||
|
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||||
|
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||||
|
|
||||||
|
mesh.addColor( currentSecondImageBW.clamp() );
|
||||||
|
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||||
|
|
||||||
|
x=x+vertexSubsampling;
|
||||||
|
if(x>=currentSecondImage.getWidth()-1){
|
||||||
|
x=0;
|
||||||
|
y=y+vertexSubsampling;
|
||||||
|
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
||||||
|
if(y>=currentSecondImage.getHeight()-1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<float> StrobeAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||||
|
|
||||||
|
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||||
|
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||||
|
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||||
|
vector<float> differences;
|
||||||
|
|
||||||
|
ofPixels difference;
|
||||||
|
|
||||||
|
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
||||||
|
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i++){
|
||||||
|
thesePixels[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x=0;
|
||||||
|
int y=0;
|
||||||
|
|
||||||
|
int chooseComparison=1;
|
||||||
|
|
||||||
|
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||||
|
|
||||||
|
if(chooseComparison==1){
|
||||||
|
//for each pixel...
|
||||||
|
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||||
|
|
||||||
|
for(int i=0;i<imagePixels1.size();i+=3){
|
||||||
|
|
||||||
|
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||||
|
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||||
|
|
||||||
|
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
||||||
|
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
||||||
|
|
||||||
|
//int thisDiff=abs(imageColor1.getHue());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||||
|
|
||||||
|
int thisDiff=-abs(imageColor1.getBrightness());
|
||||||
|
//int thisDiff=abs(imageColor1.getLightness());
|
||||||
|
//int thisDiff=-abs(imageColor1.r);
|
||||||
|
|
||||||
|
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||||
|
|
||||||
|
//red hue: 0
|
||||||
|
//green hue: 120
|
||||||
|
//blue hue: 240
|
||||||
|
|
||||||
|
differences.push_back(multiplier * thisDiff);
|
||||||
|
|
||||||
|
thesePixels[i]=thisDiff;
|
||||||
|
thesePixels[i+1]=thisDiff;
|
||||||
|
thesePixels[i+2]=thisDiff;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
if(x>=imagePixels1.getWidth()){
|
||||||
|
x=0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||||
|
return differences;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,4 +65,20 @@ protected:
|
|||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
ofxCvContourFinder cvContourFinder1;
|
||||||
|
|
||||||
|
//mesh making function
|
||||||
|
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||||
|
|
||||||
|
//depth map function
|
||||||
|
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||||
|
|
||||||
|
int vertexSubsampling;
|
||||||
|
int chooseColour;
|
||||||
|
ofPrimitiveMode meshMode;
|
||||||
|
ofBlendMode blendMode;
|
||||||
|
float multiplier;
|
||||||
|
|
||||||
|
bool _gotFirstImage;
|
||||||
|
ofImage _background;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,211 @@
|
|||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* 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