diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index 8277f08..2164bcf 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -107,27 +107,26 @@ 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 ColorMultiAnalysis()); //0 - _analysisVector.push_back(new DiffNoiseAnalysis()); + _analysisVector.push_back(new DiffNoiseAnalysis()); //Q - //_currentAnalysisIndx = 0; //_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); //_state = ISTATE_START; @@ -141,7 +140,6 @@ void RefractiveIndex::setup() void RefractiveIndex::analysis_cb(string & analysis) { assert(analysis == _currentAnalysis->_name); - _state = ISTATE_STOP; } @@ -159,8 +157,7 @@ void RefractiveIndex::start_analysis() // 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); _meshRotation=0; - - + } void RefractiveIndex::stop_analysis() @@ -232,26 +229,30 @@ 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); + 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; + + ofTranslate(xDiff,yDiff,-_currentAnalysis->zPlaneAverage ); + + ofEnableBlendMode ( OF_BLENDMODE_ADD ) ; + _currentAnalysis->aMesh.draw(); + ofDisableBlendMode( ) ; - 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; - - - ofTranslate(xDiff,yDiff,-_currentAnalysis->zPlaneAverage ); - _currentAnalysis->aMesh.draw(); - + 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! } - } } diff --git a/example/main.cpp b/example/main.cpp index 9f4b2f7..2dea266 100755 --- a/example/main.cpp +++ b/example/main.cpp @@ -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() { diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index 7603881..8b0cba6 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -227,7 +227,6 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels { #ifdef TARGET_OSX - ofSaveImage(newPixels->getPixelsRef(), _whole_file_path_synthesis+"/"+filename, OF_IMAGE_QUALITY_BEST); @@ -256,4 +255,3 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels } - diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index 214342e..3e5352c 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -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; diff --git a/src/CamNoiseAnalysis.cpp b/src/CamNoiseAnalysis.cpp index e59b364..5fd60c7 100755 --- a/src/CamNoiseAnalysis.cpp +++ b/src/CamNoiseAnalysis.cpp @@ -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; diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index f07439e..9ce59e8 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -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]<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 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=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 ColorMultiAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){ + + ofPixels imagePixels1 = image1.getPixelsRef(); + //ofPixels imagePixels2 = image2.getPixelsRef(); + ofPixels backgroundPixels = backgroundImag.getPixelsRef(); + vector 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.getWidth()){ + x=0; + y++; + } + } + } + + //difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3); + return differences; +} diff --git a/src/ColorMultiAnalysis.h b/src/ColorMultiAnalysis.h index b70c77e..841673e 100755 --- a/src/ColorMultiAnalysis.h +++ b/src/ColorMultiAnalysis.h @@ -58,5 +58,15 @@ protected: //this is the temporary container to allow us to convert and save out greyscale images ofxCvColorImage cvConvertorImage; + + //mesh making function + void setMeshFromPixels(vector sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh); + + //depth map function + vector _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + + bool _gotFirstImage; + ofImage _background; + }; diff --git a/src/ColorSingleAnalysis.cpp b/src/ColorSingleAnalysis.cpp index cc7c78c..a68d988 100755 --- a/src/ColorSingleAnalysis.cpp +++ b/src/ColorSingleAnalysis.cpp @@ -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 @@ -96,14 +109,12 @@ void ColorSingleAnalysis::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); - + cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h); } void ColorSingleAnalysis::acquire() { - Timer* save_timer; TimerCallback save_callback(*this, &ColorSingleAnalysis::save_cb); @@ -126,8 +137,6 @@ void ColorSingleAnalysis::acquire() save_timer->stop(); - - // } } void ColorSingleAnalysis::synthesise() @@ -150,49 +159,82 @@ void ColorSingleAnalysis::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.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]<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"; - - - //<---- 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); + //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); - //_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> /// + //file_name = ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".jpg"; - 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 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=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 ColorSingleAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){ + + ofPixels imagePixels1 = image1.getPixelsRef(); + //ofPixels imagePixels2 = image2.getPixelsRef(); + ofPixels backgroundPixels = backgroundImag.getPixelsRef(); + vector 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.getWidth()){ + x=0; + y++; + } + } + } + + //difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3); + return differences; +} + diff --git a/src/ColorSingleAnalysis.h b/src/ColorSingleAnalysis.h index 4b131e5..3afd9b9 100755 --- a/src/ColorSingleAnalysis.h +++ b/src/ColorSingleAnalysis.h @@ -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 sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh); + + //depth map function + vector _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + + bool _gotFirstImage; + ofImage _background; }; diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index 81f8d23..d5e24da 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -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 @@ -132,7 +131,6 @@ void IResponseAnalysis::acquire() 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){ @@ -163,13 +161,14 @@ void IResponseAnalysis::synthesise() //subtract background begin/////////////// - ofPixels imagePixels1 = image1.getPixelsRef(); - ofPixels imagePixels2 = image5.getPixelsRef(); - ofPixels backgroundPixels = _background.getPixelsRef(); + ofPixels imagePixels1 = image1.getPixelsRef(); + //ofPixels imagePixels2 = image5.getPixelsRef(); + ofPixels backgroundPixels = _background.getPixelsRef(); + //background subtraction// + for(int i=0;i0){ 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 sPixels, ofImage current } if(chooseColour==1){ + for(int i=0;i sPixels, ofImage current break; } } - } + } } - /*else{ - for(int i=0;i=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 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 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 IResponseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofIma float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2); for(int i=0;i=imagePixels1.getWidth()){ x=0; y++; - } - } } difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3); return differences; - } diff --git a/src/RelaxRateAnalysis.cpp b/src/RelaxRateAnalysis.cpp index 16c3e46..d68b193 100755 --- a/src/RelaxRateAnalysis.cpp +++ b/src/RelaxRateAnalysis.cpp @@ -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; diff --git a/src/ShapeFromShadingAnalysis.cpp b/src/ShapeFromShadingAnalysis.cpp index a2bf3ae..ce72cc9 100755 --- a/src/ShapeFromShadingAnalysis.cpp +++ b/src/ShapeFromShadingAnalysis.cpp @@ -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; diff --git a/src/StrobeAnalysis.cpp b/src/StrobeAnalysis.cpp index b45241a..b4d7336 100755 --- a/src/StrobeAnalysis.cpp +++ b/src/StrobeAnalysis.cpp @@ -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;