17 Commits

Author SHA1 Message Date
Jamie Allen 7e7136fad0 post future everything commit 2012-05-19 18:43:54 +02:00
Jamie Allen 58fdce259f added a new version of camnoiseanalysis by Tom S 2012-05-13 21:06:31 +01:00
Jamie Allen 9a6c1c6a55 safety commit prior to leaving for manchester 2012-05-11 23:37:50 +02:00
Jamie Allen 35aa74f743 further commit with correct orientation / placement of the images for FCP 2012-05-11 20:25:57 +02:00
Jamie Allen 0dc006af44 fixes in preparation for Future Everything renders tonight 2012-05-11 17:15:24 +02:00
Jamie Allen 357573f81a added the meshcode to all analyses (just for consistency... see extended description
1) Live/interactive version of one or two of the algorithms. I'd vote
for IResponse, RelaxRate and ColorMulti as the ones to do live on the
laptop.  David is looking at this...

2) The frame skipping issue remains.  I looked at this while travelling
today, but couldn't figure it out.  We're still saving out meshes at
about half the rate of them being created.

3) The following three analyses do exactly the same thing currently,
and it would be good if they had something approaching a real analysis
happening.  Right now it's just a simple z-map in black and white with
some noise on top and lighting... kind of pretty but bit boring
currently:
	ShapeFromShadingAnalysis
	CamNoiseAnalysis
	ShadowScapesAnalysis
2012-05-09 21:11:16 +02:00
Jamie Allen 8872b60133 strobe is somewhere (done for now)... pushing so david can pick this up tonight
still working on shapefromshading so it looks neato
2012-05-09 19:34:37 +02:00
Jamie Allen da5da62160 diffnoise, strobe and relaxrate updates 2012-05-08 21:59:35 +02:00
Jamie Allen ec8d6f1296 colorsingle and colormulti are in interesting places -
* need to talk to tom about _mesh_size_multiplier and the camera
positionings
* still need to fix the file saving thing - we're getting very few
frames out for the number of frames in current (threading issue)
2012-05-08 01:11:31 +02:00
Jamie Allen 34f3cf6ffd safety commit - still working on colorsingle 2012-05-07 21:59:50 +02:00
Jamie Allen 1e5bb28b43 a few tweaks to the main draw loop
working on the colormulti and colorsingle outputs still
2012-05-07 01:08:59 +02:00
Jamie Allen e0e170b522 working on color single and color multi, some openCV implementations in both
still needs work
2012-05-06 22:47:06 +02:00
Tom Schofield 8b9c3eaebc added triangular mesh and scaling for z axis. 2012-05-04 16:48:17 +01:00
Tom Schofield a9c8a56850 now displays images after saving them out and also fixed maths booboo with analysis 2012-04-13 11:16:51 +01:00
Tom Schofield 706eb9354d just sorting out my gitignore file 2012-04-12 10:24:18 +01:00
Tom Schofield 21791b9769 added zmapper from inverse square law saves from main app draw() 2012-04-12 10:21:37 +01:00
dviid e29accb9ce fixed file ordering 2012-04-09 13:35:16 +02:00
25 changed files with 4823 additions and 459 deletions
+6
View File
@@ -1,2 +1,8 @@
src/.DS_Store
.DS_Store
Project.xcconfig
bin/
openFrameworks-Info.plist
opencvExample.xcodeproj/
config.refindx
-46
View File
@@ -1,46 +0,0 @@
<!-- THIS FILE NEEDS TO GO IN THE APPLICATION /data/ folder -->
<config>
<mode>drawing</mode>
<camera>
<id>1</id>
<width>640</width>
<height>480</height>
</camera>
<display>
<fps>30</fps>
</display>
<locale>
<name>SWANSEA</name>
</locale>
<analysis_NUM_RUN>
<NUM_RUN_shadowscapes> 3 </NUM_RUN_shadowscapes>
<NUM_RUN_relaxrate> 3 </NUM_RUN_relaxrate>
<NUM_RUN_iresponse> 3 </NUM_RUN_iresponse>
<NUM_RUN_shapefromshading> 3 </NUM_RUN_shapefromshading>
<NUM_RUN_strobe> 5 </NUM_RUN_strobe>
<NUM_RUN_camnoise> 5 </NUM_RUN_camnoise>
<NUM_RUN_colorsingle> 5 </NUM_RUN_colorsingle>
<NUM_RUN_colormulti> 5 </NUM_RUN_colormulti>
<NUM_RUN_diffnoise> 3 </NUM_RUN_diffnoise>
</analysis_NUM_RUN>
<analysis_time>
<acquiretime_shadowscapes> 30 </acquiretime_shadowscapes>
<acquiretime_relaxrate> 30 </acquiretime_relaxrate>
<acquiretime_iresponse> 30 </acquiretime_iresponse>
<acquiretime_shapefromshading> 30 </acquiretime_shapefromshading>
<acquiretime_strobe> 30 </acquiretime_strobe>
<acquiretime_camnoise> 30 </acquiretime_camnoise>
<acquiretime_colorsingle> 40 </acquiretime_colorsingle>
<acquiretime_colormulti> 40 </acquiretime_colormulti>
<acquiretime_diffnoise> 30 </acquiretime_diffnoise>
</analysis_time>
<relaxrate>
<treshold>51</treshold>
<maxblobs>25</maxblobs>
</relaxrate>
</config>
+73 -17
View File
@@ -19,7 +19,7 @@
#define CAMERA_ACQU_WIDTH 640
#define CAMERA_ACQU_HEIGHT 480
#define LOCATION "MIDDLESBOROUGH"
#define LOCATION "MANCHESTER"
#define ISTATE_UNDEF 0xEEEE
#define ISTATE_START 0xAAAA
@@ -42,6 +42,10 @@ ofxXmlSettings RefractiveIndex::XML;
void RefractiveIndex::setup()
{
camDist=1000;
ofBackground(0, 0, 0);
ofSetBackgroundAuto(false);
bool save_config = false;
cout << "Loading configuration..." << endl;
@@ -101,30 +105,27 @@ void RefractiveIndex::setup()
//void ofPixels::allocate(int w, int h, ofImageType type)
_pixels.allocate(_vid_w, _vid_h, OF_IMAGE_COLOR);
//TODO: whichever one of these is first - it always runs twice ?
_analysisVector.push_back(new ShadowScapesAnalysis(V));
_analysisVector.push_back(new ShadowScapesAnalysis(H));
_analysisVector.push_back(new ShadowScapesAnalysis(D));
_analysisVector.push_back(new ShadowScapesAnalysis(V)); //1
_analysisVector.push_back(new ShadowScapesAnalysis(H)); //2
_analysisVector.push_back(new ShadowScapesAnalysis(D)); //3
_analysisVector.push_back(new RelaxRateAnalysis());
_analysisVector.push_back(new RelaxRateAnalysis()); //4
_analysisVector.push_back(new IResponseAnalysis()); //5
_analysisVector.push_back(new IResponseAnalysis());
_analysisVector.push_back(new ShapeFromShadingAnalysis()); //6
_analysisVector.push_back(new ShapeFromShadingAnalysis());
_analysisVector.push_back(new StrobeAnalysis()); //7
_analysisVector.push_back(new StrobeAnalysis());
_analysisVector.push_back(new CamNoiseAnalysis()); //8
_analysisVector.push_back(new CamNoiseAnalysis());
_analysisVector.push_back(new ColorSingleAnalysis()); //9
_analysisVector.push_back(new ColorSingleAnalysis());
_analysisVector.push_back(new ColorMultiAnalysis());
_analysisVector.push_back(new DiffNoiseAnalysis());
_analysisVector.push_back(new ColorMultiAnalysis()); //0
_analysisVector.push_back(new DiffNoiseAnalysis()); //Q
//_currentAnalysisIndx = 0;
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
@@ -133,12 +134,12 @@ void RefractiveIndex::setup()
_currentAnalysis = NULL;
_state = ISTATE_UNDEF;
}
void RefractiveIndex::analysis_cb(string & analysis)
{
assert(analysis == _currentAnalysis->_name);
_state = ISTATE_STOP;
}
@@ -148,6 +149,17 @@ void RefractiveIndex::start_analysis()
_analysisAdapator = new AnalysisAdaptor(_currentAnalysis);
_currentAnalysis->setup(_vid_w, _vid_h);
_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()
@@ -211,8 +223,52 @@ void RefractiveIndex::draw()
// black
ofBackground(0, 0, 0);
if(_currentAnalysis)
if(_currentAnalysis){
_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()
+8
View File
@@ -10,6 +10,8 @@
#include "ofxOpenCv.h"
#include "ofxXmlSettings.h"
#include "ofxOpenCv.h"
#define MODE_DRAWING 0xEEFF
#define MODE_ANALYSING 0xFFEE
@@ -54,6 +56,9 @@ protected:
AnalysisAdaptor* _analysisAdapator;
vector<AbstractAnalysis*> _analysisVector;
float _meshRotation;
float camDist;
ofEasyCam cam;
public:
// acquisition
static ofPixels _pixels;
@@ -68,5 +73,8 @@ public:
// this should be in xml
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
View File
@@ -1,8 +1,8 @@
#include "ofAppGlutWindow.h"
#include "RefractiveIndex.h"
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 800
int main() {
+19 -3
View File
@@ -7,8 +7,10 @@
void AbstractAnalysis::setup(int camWidth, int camHeight) {
_cam_w = camWidth; _cam_h = 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) {
@@ -50,6 +52,8 @@ void AbstractAnalysis::do_synthesize() {
case MODE_DRAWING:
{
ofxFileHelper fileHelperDrawing;
if(!fileHelperDrawing.doesDirectoryExist(_whole_file_path_synthesis)){
fileHelperDrawing.makeDirectory(_whole_file_path_synthesis);
@@ -153,10 +157,18 @@ void AbstractAnalysis::create_dir_allocate_images()
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);
@@ -164,9 +176,15 @@ void AbstractAnalysis::read_dir_create_list(string 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;
}
}
}
@@ -210,7 +228,6 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
#ifdef TARGET_OSX
ofSaveImage(newPixels->getPixelsRef(), _whole_file_path_synthesis+"/"+filename, OF_IMAGE_QUALITY_BEST);
#elif defined(TARGET_WIN32)
@@ -238,4 +255,3 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
}
+17
View File
@@ -61,6 +61,23 @@ public:
// event
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:
int _cam_w, _cam_h;
+693 -41
View File
@@ -21,6 +21,62 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
//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;
@@ -82,7 +138,6 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
@@ -91,9 +146,6 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@@ -130,10 +182,25 @@ void CamNoiseAnalysis::synthesise()
//cout << "CamNoiseAnalysis::saving synthesis...\n";
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";
//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;
if(_state == STATE_STOP) return;
@@ -144,63 +211,118 @@ void CamNoiseAnalysis::synthesise()
}
if(image1.loadImage(_saved_filenames_analysis[i])){
//cout << "LOADED image1!!!" << endl;
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
// cout << "LOADED image1!!!" << endl;
if(image5.loadImage(_saved_filenames_analysis[i+1])){
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
/* cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
// cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
//added by tom we weren't actually setting cvgrayimage1 anywhere
// cvGrayImage1.setFromPixels(cvColorImage1.getPixels(),cvColorImage1.width,cvColorImage1.height);
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
//cvGrayImage1=cvColorImage1;
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
cvGrayImage1.erode();
cvGrayImage1.erode();
cvGrayImage1.erode();
cvGrayImage1.blur();
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
//cvGrayDiff1.erode();
cvGrayImage1.dilate();
cvGrayImage1.blur(5);
cvGrayImage1.contrastStretch();
/* cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.blur();
cvColorImage1.contrastStretch();*/
/////////////////////////////////// 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);
//cvFloatImage1 = cvColorImage1;
//cvGrayImage1 = cvColorImage1;
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//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);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
// 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;
}
//image.setFromPixels(cvGrayImage1.getPixels(), cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//subtract background begin///////////////
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
ofPixels imagePixels1 = image1.getPixelsRef();
ofPixels imagePixels2 = image5.getPixelsRef();
ofPixels backgroundPixels = _background.getPixelsRef();
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayImage1,cvGrayImage1,cvGrayImage1);
//cvConvertorImage.setFromGrayscalePlanarImages(cvColorImage1,cvColorImage1,cvColorImage1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
//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
@@ -434,3 +556,533 @@ void CamNoiseAnalysis::save_cb(Timer& timer)
saveImageAnalysis(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 ";
}
}
+24 -2
View File
@@ -61,7 +61,29 @@ protected:
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, 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;
};
+253 -31
View File
@@ -20,6 +20,14 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
//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;
@@ -141,6 +149,7 @@ void ColorMultiAnalysis::synthesise()
cout << "didn't load image" << endl;
}
if(image1.loadImage(_saved_filenames_analysis[i])){
//cout << "LOADED image1!!!" << endl;
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
@@ -150,47 +159,91 @@ void ColorMultiAnalysis::synthesise()
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
cvColorImage1.blur(5);
cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.dilate();
cvColorImage1.blur(5);
cvColorImage1.dilate();
cvColorImage1.dilate();
cvColorImage1.dilate();
cvColorImage1.dilate();
//cvColorImage1.blur(1);
//cvColorImage1.erode();
//cvColorImage1.dilate();
//cvColorImage1.dilate();
//cvColorImage1.dilate();
//cvColorImage1.dilate();
//cvFloatImage1 = cvColorImage1;
//cvGrayImage1 = cvColorImage1;
cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 15, 15);
cvXorS( cvColorImage1.getCvImage(), cvScalarAll(2), cvColorImage1.getCvImage(), 0 );
//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());
///////////////////////// 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 ////////////////////////////////
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);
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
//flag that we are finished
meshIsComplete=true;
_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
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
}
@@ -226,6 +279,27 @@ void ColorMultiAnalysis::displayresults()
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) {
case STATE_ACQUIRING:
{
@@ -411,8 +485,156 @@ void ColorMultiAnalysis::draw()
void ColorMultiAnalysis::save_cb(Timer& timer)
{
_save_cnt++;
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
saveImageAnalysis(file_name);
}
void ColorMultiAnalysis::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);
//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;
}
}
}
}
}
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;
}
+13
View File
@@ -59,4 +59,17 @@ protected:
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;
};
+406 -35
View File
@@ -1,9 +1,11 @@
#include "ColorSingleAnalysis.h"
#include "ofMain.h"
#include "Poco/Timer.h"
#include "Poco/Thread.h"
#include <string>
#include <iostream>
#include "RefractiveIndex.h"
using Poco::Timer;
@@ -21,10 +23,18 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
//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
@@ -47,6 +57,7 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
b = 0;
fileNameTag = "";
fileNameColor = "";
_show_image = false;
_image_shown = false;
@@ -97,13 +108,11 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
void ColorSingleAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<ColorSingleAnalysis> save_callback(*this, &ColorSingleAnalysis::save_cb);
@@ -126,8 +135,6 @@ void ColorSingleAnalysis::acquire()
save_timer->stop();
// }
}
void ColorSingleAnalysis::synthesise()
@@ -155,51 +162,121 @@ void ColorSingleAnalysis::synthesise()
///////////////////////// 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);
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
cvColorImage1.blur(5);
cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.dilate();
cvColorImage1.blur(5);
cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.erode();
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;
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(255), cvColorImage1.getCvImage(), 0 );
//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());
///////////////////////// 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 ////////////////////////////////
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);
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".jpg";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height,OF_IMAGE_COLOR);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
//flag that we are finished
meshIsComplete=true;
_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
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
@@ -236,12 +313,31 @@ void ColorSingleAnalysis::displayresults()
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) {
case STATE_ACQUIRING:
{
if (_frame_cnt < _frame_cnt_max)
{
@@ -433,3 +529,278 @@ void ColorSingleAnalysis::save_cb(Timer& timer)
saveImageAnalysis(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;
}
+16 -1
View File
@@ -1,4 +1,4 @@
/*
/*
~ author: dviid
~ contact: dviid@labs.ciid.dk
*/
@@ -32,6 +32,7 @@ protected:
bool _RUN_DONE;
string fileNameTag;
string fileNameColor;
float r,g,b;
int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt;
@@ -60,10 +61,24 @@ protected:
ofxCvGrayscaleImage cvGrayImage3;
ofxCvGrayscaleImage cvGrayImage4;
ofxCvFloatImage cvFloatImage1;
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;
};
+560 -26
View File
@@ -18,9 +18,32 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
AbstractAnalysis::setup(camWidth, camHeight);
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
//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;
@@ -91,7 +114,6 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@@ -151,45 +173,133 @@ void DiffNoiseAnalysis::synthesise()
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
cvColorImage1.invert();
cvColorImage1.blur(5);
cvColorImage1.erode();
cvColorImage1.erode();
cvColorImage1.blur(5);
cvColorImage1.erode();
cvColorImage1.erode();
//cvColorImage1.erode();
//cvColorImage1.dilate();
//////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
string file_name;
//cvColorImage1.blur(5);
//cvColorImage2.blur(5);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
//cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
file_name = ofToString(_synth_save_cnt, 2)+"_DiffNoiseAnalysis_"+ofToString(_run_cnt,2)+".jpg";
//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;
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
//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);
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
// 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;
}
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvColorImage1.width, cvGrayImage1.height, OF_IMAGE_COLOR);
//subtract background begin///////////////
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
ofPixels imagePixels1 = image1.getPixelsRef();
//ofPixels imagePixels2 = image5.getPixelsRef();
ofPixels backgroundPixels = _background.getPixelsRef();
//image.setFromPixels(cvColorImage1.getPixels(), cvColorImage1.width, cvColorImage1.height, OF_IMAGE_COLOR);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//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;
}
}
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
*/
//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;
}
}
*/
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
saveImageSynthesis(file_name, &cvColorImage1, OF_IMAGE_COLOR);
//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++;
// }
}
//}
} 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
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
@@ -229,6 +339,26 @@ void DiffNoiseAnalysis::displayresults()
// this runs at frame rate = 33 ms for 30 FPS
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) {
case STATE_ACQUIRING:
{
@@ -275,7 +405,6 @@ void DiffNoiseAnalysis::draw()
}
}
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt <= _frame_cnt_max) {
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
@@ -436,3 +565,408 @@ void DiffNoiseAnalysis::save_cb(Timer& timer)
saveImageAnalysis(file_name);
}
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;
}
+16
View File
@@ -63,4 +63,20 @@ protected:
//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;
};
+178 -47
View File
@@ -21,10 +21,21 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
//NUM_RUN = 5;
//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
@@ -80,8 +91,6 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
@@ -89,15 +98,10 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
void IResponseAnalysis::acquire()
{
Timer* save_timer;
TimerCallback<IResponseAnalysis> save_callback(*this, &IResponseAnalysis::save_cb);
@@ -125,6 +129,7 @@ void IResponseAnalysis::acquire()
void IResponseAnalysis::synthesise()
{
cout<<"SYNTHESISING IRESPONSE";
//cout << "IResponseAnalysis::saving synthesis...\n";
if(_state == STATE_STOP) return;
@@ -144,62 +149,66 @@ void IResponseAnalysis::synthesise()
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 //////////////////////////
if(!_gotFirstImage){
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
_background=image1;
_gotFirstImage=true;
}
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
//subtract background begin///////////////
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
ofPixels imagePixels1 = image1.getPixelsRef();
//ofPixels imagePixels2 = image5.getPixelsRef();
ofPixels backgroundPixels = _background.getPixelsRef();
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
cvGrayDiff1.erode();
cvGrayDiff1.contrastStretch();
//cvGrayDiff1.blur(5);
//cvGrayDiff1.dilate();
//cvGrayDiff1.contrastStretch();
//background subtraction//
/*
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);
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
string file_name;
//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);
file_name = ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".jpg";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
//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);
//flag that we are finished
meshIsComplete=true;
_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
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
}
@@ -407,3 +416,125 @@ void IResponseAnalysis::save_cb(Timer& timer)
saveImageAnalysis(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;
}
+7 -3
View File
@@ -59,7 +59,11 @@ protected:
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);
//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;
};
+627 -33
View File
@@ -23,6 +23,28 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
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;
@@ -57,18 +79,47 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
_image_shown = false;
image1.clear();
image2.clear();
image3.clear();
image4.clear();
image5.clear();
// images use for drawing the synthesized files to the screen ///
image1.setUseTexture(false); // the non texture image that is needed to first load the image
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
// images used for re-loading and saving out the synthesized files ///
image3.setUseTexture(false);
image4.setUseTexture(false);
image5.setUseTexture(false);
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
// that we're getting in OSX/Windows and is maybe crashing Windows
// http://forum.openframeworks.cc/index.php?topic=1867.0
cvColorImage1.clear();
cvGrayImage1.clear();
cvGrayDiff1.clear();
cvColorImage2.clear();
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@@ -101,76 +152,194 @@ void RelaxRateAnalysis::acquire()
void RelaxRateAnalysis::synthesise()
{
//cout << "IResponseAnalysis::saving synthesis...\n";
// cout << "RelaxRate::saving synthesis...\n";
if(_state == STATE_STOP) return;
cvContourFinderVect.clear();
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
// cout << "StrobeAnalysis::synthesis FOR LOOP...\n";
for(float i=1;i<_saved_filenames_analysis.size();i++){
// cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
if(_state == STATE_STOP) return;
if(!image1.loadImage(_saved_filenames_analysis[i])){
//couldn't load image
// cout << "didn't load image" << endl;
}
if(image1.loadImage(_saved_filenames_analysis[i])){
//cout << "LOADED image1!!!" << endl;
if(image5.loadImage(_saved_filenames_analysis[i+1])){
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
cvColorImage1.convertToGrayscalePlanarImage(cvGrayDiff1, 1);
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
cvGrayDiff1.threshold(_treshold);
//cvColorImage1.erode();
//cvColorImage1.erode();
//cvColorImage1.dilate();
rfiCvContourFinder* cf = new rfiCvContourFinder();
cvColorImage1.blur(1);
cvColorImage2.blur(1);
cf->findContours(cvGrayDiff1, 20, (image1.width * image1.height) / 4, _maxblobs, true);
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
cvContourFinderVect.push_back(cf);
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 ////////////////////////////////
//string file_name;
//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);
//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
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
Thread::sleep(10);
}
void RelaxRateAnalysis::displayresults()
{
//cvContourFinderVectDisplay.clear();
clearcfindervectdisplay();
for(float i=1;i<_saved_filenames_synthesis.size();i++){
for(int i=1;i<cvContourFinderVect.size();i++){
if(_state == STATE_STOP) return;
if(_state == STATE_STOP){
clearcfindervectdisplay();
clearcfindervect();
return;
}
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
// cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
while(!_image_shown){
Thread::sleep(2);
if(_state == STATE_STOP) return;
//cout << "!_image_shown" << endl;
}
cvContourFinderVectDisplay.push_back(cvContourFinderVect[i]);
_show_image = true;
_image_shown = false;
if(!image3.loadImage(_saved_filenames_synthesis[i])){
//couldn't load image
// cout << "didn't load image" << endl;
}
clearcfindervectdisplay();
clearcfindervect();
//cvContourFinderVectDisplay.clear();
//cvContourFinderVect.clear();
if(image3.loadImage(_saved_filenames_synthesis[i])){
image3.loadImage(_saved_filenames_synthesis[i]);
//cout << "_show_image = true;" << endl;
_show_image = true;
_image_shown = false;
}
}
}
@@ -179,6 +348,24 @@ void RelaxRateAnalysis::displayresults()
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) {
case STATE_ACQUIRING:
{
@@ -368,3 +555,410 @@ 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;
}
+36
View File
@@ -45,10 +45,46 @@ protected:
bool _show_image, _image_shown;
ofImage image1;
ofImage image2;
ofImage image3;
ofImage image4;
ofImage image5;
ofImage image6;
ofxCvColorImage cvColorImage1;
ofxCvColorImage cvColorImage2;
ofxCvColorImage cvColorImage3;
ofxCvColorImage cvColorImage4;
ofxCvColorImage cvColorImage5;
ofxCvColorImage cvColorImage6;
ofxCvGrayscaleImage cvGrayDiff1;
ofxCvGrayscaleImage cvGrayDiff2;
ofxCvGrayscaleImage cvGrayImage1;
ofxCvGrayscaleImage cvGrayImage2;
ofxCvGrayscaleImage cvGrayImage3;
ofxCvGrayscaleImage cvGrayImage4;
vector<rfiCvContourFinder*> cvContourFinderVect;
vector<rfiCvContourFinder*> cvContourFinderVectDisplay;
//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;
};
+543 -33
View File
@@ -25,6 +25,57 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
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;
@@ -88,7 +139,6 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
@@ -98,7 +148,6 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@@ -142,7 +191,7 @@ void ShadowScapesAnalysis::synthesise()
}
if(image1.loadImage(_saved_filenames_analysis[i])){
// cout << "LOADED image1!!!" << endl;
if(image5.loadImage(_saved_filenames_analysis[i+1])){
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
@@ -150,57 +199,108 @@ void ShadowScapesAnalysis::synthesise()
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
//cvGrayImage1 = cvColorImage1;
//cvGrayImage2 = cvColorImage2;
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
cvGrayDiff1.erode();
cvGrayDiff1.contrastStretch();
cvGrayDiff1.blur(5);
cvGrayDiff1.dilate();
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
//cvGrayDiff1.erode();
cvGrayImage1.dilate();
cvGrayImage1.blur(5);
cvGrayImage1.contrastStretch();
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
string file_name;
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
if(_dir == H) {
file_name = ofToString(_synth_save_cnt, 2)+"_H_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
//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;
}
if(_dir == V) {
file_name = ofToString(_synth_save_cnt, 2)+"_V_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
//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];
}
if(_dir == D) {
file_name = ofToString(_synth_save_cnt, 2)+"_D_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
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);
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//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);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
//string file_name;
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+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);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
//flag that we are finished
meshIsComplete=true;
_synth_save_cnt++;
}
} else {
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
}
}
@@ -476,3 +576,413 @@ void ShadowScapesAnalysis::save_cb(Timer& timer)
saveImageAnalysis(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;
}
+15 -2
View File
@@ -66,7 +66,20 @@ protected:
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;
};
+630 -21
View File
@@ -21,6 +21,56 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
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;
@@ -166,6 +216,24 @@ void ShapeFromShadingAnalysis::synthesise()
// cout << "LOADED image1!!!" << endl;
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 //////////////////////////
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
@@ -174,42 +242,132 @@ void ShapeFromShadingAnalysis::synthesise()
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
cvGrayDiff1.erode();
cvGrayDiff1.contrastStretch();
//cvGrayDiff1.blur(5);
//cvGrayDiff1.dilate();
//cvGrayDiff1.contrastStretch();
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
//cvGrayDiff1.erode();
cvGrayImage1.dilate();
cvGrayImage1.blur(5);
cvGrayImage1.contrastStretch();
/////////////////////////////////// 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);
//cvFloatImage1 = cvColorImage1;
//cvGrayImage1 = cvColorImage1;
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
// convert the CV image
image1.setFromPixels(cvColorImage1.getPixelsRef());
image5.setFromPixels(cvColorImage2.getPixelsRef());
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
///////////////////////// 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);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
} else if(fileNameQuad=="QUAD2")
{
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
//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++;
}
} else {
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
}
}
@@ -250,6 +408,48 @@ void ShapeFromShadingAnalysis::displayresults()
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) {
case STATE_ACQUIRING:
{
@@ -598,3 +798,412 @@ void ShapeFromShadingAnalysis::save_cb(Timer& timer)
saveImageAnalysis(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;
}
+17
View File
@@ -31,6 +31,8 @@ public:
protected:
string quad;
string fileNameQuad;
bool _RUN_DONE;
float _flip, _level;
int _animation_cnt1;
@@ -82,4 +84,19 @@ protected:
//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;
};
+571 -36
View File
@@ -21,6 +21,28 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
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;
@@ -81,8 +103,6 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
cvGrayImage2.clear();
cvGrayDiff2.clear();
cvConvertorImage.clear();
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
@@ -91,7 +111,6 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
}
@@ -145,7 +164,7 @@ void StrobeAnalysis::synthesise()
}
if(image1.loadImage(_saved_filenames_analysis[i])){
// cout << "LOADED image1!!!" << endl;
//cout << "LOADED image1!!!" << endl;
if(image5.loadImage(_saved_filenames_analysis[i+1])){
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
@@ -153,52 +172,142 @@ void StrobeAnalysis::synthesise()
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
//cvColorImage1.erode();
//cvColorImage1.erode();
//cvColorImage1.dilate();
cvColorImage1.blur(1);
cvColorImage2.blur(1);
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
cvGrayDiff1.dilate();
cvGrayDiff1.dilate();
cvGrayDiff1.contrastStretch();
//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 ////////////////////////////////
string file_name;
//string file_name;
file_name = ofToString(_synth_save_cnt, 2)+"_StrobeAnalysis_"+ofToString(_run_cnt,2)+".jpg";
//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";
//<---- THE OLD WAY OF SAVING - works on OSX but generates BLACK FRAMES on WINDOWS ---->
// ofSaveImage(cvGrayImage1.getPixelsRef(),_whole_file_path_synthesis+"/"+file_name, OF_IMAGE_QUALITY_BEST);
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
//ofImage image;
//image.allocate(cvGrayImage1.width, cvGrayImage1.height, OF_IMAGE_GRAYSCALE);
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
//image.setUseTexture(false);
//image.setFromPixels(cvGrayDiff1.getPixels(), cvGrayDiff1.width, cvGrayDiff1.height,OF_IMAGE_GRAYSCALE);
//image.saveImage(_whole_file_path_synthesis+"/"+file_name);
//_saved_filenames_synthesis.push_back(_whole_file_path_synthesis+"/"+file_name);
// <--- REALLY NEW SAVING METHOD --- 26 feb 2012 --- consolidated the save function into Abstract Analysis> ///
cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1);
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
//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
while(!_RUN_DONE && _state != STATE_STOP)
Thread::sleep(3);
Thread::sleep(10);
}
void StrobeAnalysis::displayresults()
@@ -235,6 +344,27 @@ void StrobeAnalysis::displayresults()
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) {
case STATE_ACQUIRING:
{
@@ -253,7 +383,6 @@ void StrobeAnalysis::draw()
ofRect(0, 0, ofGetWidth(), ofGetHeight());
//cout << "FADE IN STROBE TIME " << endl;
}
if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){
@@ -285,6 +414,7 @@ void StrobeAnalysis::draw()
}
ofDisableAlphaBlending();
} else {
//_state = STATE_SYNTHESISING;
_RUN_DONE = true;
@@ -427,3 +557,408 @@ void StrobeAnalysis::save_cb(Timer& timer)
saveImageAnalysis(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;
}
+15 -2
View File
@@ -65,7 +65,20 @@ protected:
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;
};