working on color single and color multi, some openCV implementations in both
still needs work
This commit is contained in:
parent
8b9c3eaebc
commit
e0e170b522
@ -107,26 +107,25 @@ void RefractiveIndex::setup()
|
||||
|
||||
//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());
|
||||
_analysisVector.push_back(new IResponseAnalysis()); //5
|
||||
|
||||
_analysisVector.push_back(new ShapeFromShadingAnalysis());
|
||||
_analysisVector.push_back(new ShapeFromShadingAnalysis()); //6
|
||||
|
||||
_analysisVector.push_back(new StrobeAnalysis());
|
||||
_analysisVector.push_back(new StrobeAnalysis()); //7
|
||||
|
||||
_analysisVector.push_back(new CamNoiseAnalysis());
|
||||
_analysisVector.push_back(new CamNoiseAnalysis()); //8
|
||||
|
||||
_analysisVector.push_back(new ColorSingleAnalysis());
|
||||
_analysisVector.push_back(new ColorSingleAnalysis()); //9
|
||||
|
||||
_analysisVector.push_back(new ColorMultiAnalysis());
|
||||
|
||||
_analysisVector.push_back(new DiffNoiseAnalysis());
|
||||
_analysisVector.push_back(new ColorMultiAnalysis()); //0
|
||||
|
||||
_analysisVector.push_back(new DiffNoiseAnalysis()); //Q
|
||||
|
||||
//_currentAnalysisIndx = 0;
|
||||
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
||||
@ -141,7 +140,6 @@ void RefractiveIndex::setup()
|
||||
void RefractiveIndex::analysis_cb(string & analysis)
|
||||
{
|
||||
assert(analysis == _currentAnalysis->_name);
|
||||
|
||||
_state = ISTATE_STOP;
|
||||
}
|
||||
|
||||
@ -160,7 +158,6 @@ void RefractiveIndex::start_analysis()
|
||||
camera.setPosition(fbo.getWidth()/2, fbo.getHeight()/2,_currentAnalysis->_mesh_size_multiplier *500);
|
||||
_meshRotation=0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RefractiveIndex::stop_analysis()
|
||||
@ -232,25 +229,29 @@ void RefractiveIndex::draw()
|
||||
|
||||
fbo.begin();
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
ofClear(0,0,0);
|
||||
|
||||
camera.begin();
|
||||
|
||||
ofSetColor(0, 0, 0);
|
||||
|
||||
//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);
|
||||
ofRect(-fbo.getWidth(), -fbo.getHeight(), fbo.getWidth()*3, fbo.getHeight()*3);
|
||||
|
||||
|
||||
ofPopMatrix();
|
||||
ofSetColor(255);
|
||||
|
||||
float xDiff= (fbo.getWidth()- (_currentAnalysis->_mesh_size_multiplier *_vid_w))/2;
|
||||
float yDiff= (fbo.getHeight()- (_currentAnalysis->_mesh_size_multiplier *_vid_h))/2;
|
||||
|
||||
float xDiff= (fbo.getWidth()- (_currentAnalysis->_mesh_size_multiplier * _vid_w))/2;
|
||||
float yDiff= (fbo.getHeight()- (_currentAnalysis->_mesh_size_multiplier * _vid_h))/2;
|
||||
|
||||
ofTranslate(xDiff,yDiff,-_currentAnalysis->zPlaneAverage );
|
||||
|
||||
ofEnableBlendMode ( OF_BLENDMODE_ADD ) ;
|
||||
_currentAnalysis->aMesh.draw();
|
||||
ofDisableBlendMode( ) ;
|
||||
|
||||
|
||||
camera.end();
|
||||
fbo.end();
|
||||
@ -260,9 +261,9 @@ void RefractiveIndex::draw()
|
||||
|
||||
ofSaveImage(pixels,_currentAnalysis->meshFileName, OF_IMAGE_QUALITY_BEST);
|
||||
//saving jpgs doesn't work - pngs only!
|
||||
// PNG is fine - better for Final Cut anyway!
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
|
||||
@ -228,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)
|
||||
@ -256,4 +255,3 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -64,6 +64,7 @@ public:
|
||||
bool meshIsComplete;
|
||||
bool imageForContourAvailable;
|
||||
ofMesh aMesh;
|
||||
|
||||
string meshFileName;
|
||||
//difference between our image size and the size of the fbo
|
||||
float widthScaleFactor;
|
||||
|
||||
@ -21,6 +21,12 @@ 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=4;
|
||||
|
||||
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;
|
||||
|
||||
@ -20,6 +20,13 @@ 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=4;
|
||||
|
||||
|
||||
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 +148,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,40 +158,75 @@ 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, 9, 9);
|
||||
cvXorS( cvColorImage1.getCvImage(), cvScalarAll(1), 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++;
|
||||
|
||||
// }
|
||||
@ -411,8 +454,149 @@ 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_LINE_STRIP);
|
||||
|
||||
/*
|
||||
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,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> 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=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;
|
||||
}
|
||||
|
||||
@ -59,4 +59,14 @@ 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);
|
||||
|
||||
bool _gotFirstImage;
|
||||
ofImage _background;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -21,10 +21,23 @@ 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=4;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
//flag for main sketch
|
||||
meshIsComplete=false;
|
||||
_gotFirstImage=false;
|
||||
|
||||
_mesh_size_multiplier=3;
|
||||
|
||||
//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
|
||||
@ -97,13 +110,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 +137,6 @@ void ColorSingleAnalysis::acquire()
|
||||
|
||||
save_timer->stop();
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
void ColorSingleAnalysis::synthesise()
|
||||
@ -158,41 +167,74 @@ void ColorSingleAnalysis::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.erode();
|
||||
cvColorImage1.erode();
|
||||
cvColorImage1.erode();
|
||||
cvColorImage1.erode();
|
||||
//cvColorImage1.blur(1);
|
||||
//cvColorImage1.erode();
|
||||
|
||||
//cvColorImage1.dilate();
|
||||
//cvColorImage1.dilate();
|
||||
//cvColorImage1.dilate();
|
||||
//cvColorImage1.dilate();
|
||||
|
||||
//cvFloatImage1 = cvColorImage1;
|
||||
//cvGrayImage1 = cvColorImage1;
|
||||
|
||||
cvXorS( cvColorImage1.getCvImage(), cvScalarAll(255), cvColorImage1.getCvImage(), 0 );
|
||||
//cvSmooth( cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), CV_GAUSSIAN, 3, 3 );
|
||||
//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++;
|
||||
|
||||
// }
|
||||
@ -433,3 +475,133 @@ 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);
|
||||
|
||||
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> 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...
|
||||
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.getHue());
|
||||
int thisDiff=abs(imageColor1.getBrightness());
|
||||
|
||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||
|
||||
//red hue: 0
|
||||
//green hue: 120
|
||||
//blue hue: 240
|
||||
|
||||
float multiplier=2.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;
|
||||
}
|
||||
|
||||
|
||||
@ -60,10 +60,21 @@ 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);
|
||||
|
||||
bool _gotFirstImage;
|
||||
ofImage _background;
|
||||
|
||||
};
|
||||
|
||||
@ -31,7 +31,6 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
|
||||
|
||||
_mesh_size_multiplier=4;
|
||||
|
||||
|
||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||
|
||||
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||
@ -133,7 +132,6 @@ void IResponseAnalysis::synthesise()
|
||||
{
|
||||
cout<<"SYNTHESISING IRESPONSE";
|
||||
|
||||
|
||||
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||
if(_state == STATE_STOP) return;
|
||||
|
||||
@ -152,7 +150,7 @@ 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){
|
||||
@ -164,12 +162,13 @@ void IResponseAnalysis::synthesise()
|
||||
//subtract background begin///////////////
|
||||
|
||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||
//ofPixels imagePixels2 = image5.getPixelsRef();
|
||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||
|
||||
for(int i=0;i<imagePixels1.size();i++){
|
||||
//background subtraction//
|
||||
|
||||
unsigned char val=imagePixels1[i];
|
||||
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];
|
||||
@ -177,17 +176,16 @@ void IResponseAnalysis::synthesise()
|
||||
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);
|
||||
|
||||
//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";
|
||||
@ -198,14 +196,12 @@ void IResponseAnalysis::synthesise()
|
||||
_synth_save_cnt++;
|
||||
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||
while(!_RUN_DONE && _state != STATE_STOP)
|
||||
Thread::sleep(3);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -442,20 +438,21 @@ void IResponseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage current
|
||||
}
|
||||
|
||||
if(chooseColour==1){
|
||||
|
||||
for(int i=0;i<sPixels.size();i++){
|
||||
mesh.addColor( currentSecondImage.getColor(x, y+1) );
|
||||
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.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.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.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.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) );
|
||||
@ -472,76 +469,24 @@ void IResponseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage current
|
||||
}
|
||||
}
|
||||
}
|
||||
/*else{
|
||||
for(int i=0;i<somePixels.getWidth()*(somePixels.getHeight()-1);i++){
|
||||
|
||||
|
||||
ofVec3f U;
|
||||
ofVec3f V;
|
||||
//tri 1
|
||||
U =ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- somePixels.getColor(x, y).getBrightness() ).operator- ( ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- somePixels.getColor(x, y).getBrightness() ) );
|
||||
V =ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- somePixels.getColor(x+1, y+1).getBrightness() ).operator-(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- somePixels.getColor(x, y).getBrightness() ));
|
||||
|
||||
ofVec3f normal;
|
||||
float mult=5.2;
|
||||
normal = ofVec3f( (U.y*V.z)-(U.z-V.y) , (U.z*V.x)-(U.x*V.z) , (U.x*V.y)-(U.y*V.x) );
|
||||
|
||||
mesh.addColor(meshColour);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- mult*(1+somePixels.getColor(x, y+1).getBrightness() ) ));
|
||||
|
||||
mesh.addColor(meshColour);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- mult*(1+somePixels.getColor(x, y).getBrightness() ) ));
|
||||
|
||||
mesh.addColor(meshColour);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- mult*(1+somePixels.getColor(x+1, y+1).getBrightness()) ));
|
||||
|
||||
mesh.addNormal(normal);
|
||||
|
||||
//tri 2
|
||||
U =ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*y,- somePixels.getColor(x, y).getBrightness() ).operator-(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- somePixels.getColor(x+1, y+1).getBrightness() ) );
|
||||
V =ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- somePixels.getColor(x+1, y).getBrightness() ).operator-(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- somePixels.getColor(x+1, y+1).getBrightness() ) );
|
||||
|
||||
normal = ofVec3f( (U.y*V.z)-(U.z-V.y) , (U.z*V.x)-(U.x*V.z) , (U.x*V.y)-(U.y*V.x) );
|
||||
|
||||
mesh.addColor(meshColour);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- mult*(1+somePixels.getColor(x+1, y+1).getBrightness()) ));
|
||||
// mesh.addColor( ofColor(255,10,10) );
|
||||
|
||||
mesh.addColor(meshColour);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*y,- mult*(1+somePixels.getColor(x, y).getBrightness() ) ));
|
||||
|
||||
mesh.addColor(meshColour);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,-mult*(1+ somePixels.getColor(x+1, y).getBrightness()) ));
|
||||
|
||||
mesh.addNormal(normal);
|
||||
|
||||
x++;
|
||||
if(x>=somePixels.getWidth()-1){
|
||||
x=0;
|
||||
y++;
|
||||
if(y>=479){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// add colour from current second image of two - this is a hang over from when i was comparing two image
|
||||
|
||||
|
||||
}
|
||||
|
||||
vector<float> IResponseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||
|
||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||
ofPixels imagePixels2 = image2.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];
|
||||
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;
|
||||
|
||||
@ -553,32 +498,36 @@ vector<float> IResponseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofIma
|
||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||
for(int i=0;i<imagePixels1.size();i+=3){
|
||||
|
||||
ofColor colourImage1 = imagePixels1.getColor(x, y);
|
||||
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=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
||||
|
||||
//float _presumedBrightness=255;
|
||||
int thisDiff=abs(colourImage1.getBrightness()-_presumedBrightness);
|
||||
|
||||
int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||
|
||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||
float multiplier=2.0;
|
||||
differences.push_back(multiplier* thisDiff);
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -23,6 +23,12 @@ 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=4;
|
||||
|
||||
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;
|
||||
|
||||
@ -21,6 +21,13 @@ 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=4;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -21,6 +21,12 @@ 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=4;
|
||||
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user