diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index 73406a0..8277f08 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -42,6 +42,9 @@ ofxXmlSettings RefractiveIndex::XML; void RefractiveIndex::setup() { + camDist=1000; + + //camera.setOrientation(ofVec3f(1,-1,1)); bool save_config = false; cout << "Loading configuration..." << endl; @@ -109,7 +112,6 @@ void RefractiveIndex::setup() _analysisVector.push_back(new ShadowScapesAnalysis(D)); _analysisVector.push_back(new RelaxRateAnalysis()); - _analysisVector.push_back(new IResponseAnalysis()); @@ -132,9 +134,7 @@ void RefractiveIndex::setup() _currentAnalysis = NULL; _state = ISTATE_UNDEF; - - fbo.allocate(_vid_w,_vid_h); - _meshRotation=0; + } @@ -151,6 +151,16 @@ 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); + _meshRotation=0; + + } void RefractiveIndex::stop_analysis() @@ -213,30 +223,46 @@ void RefractiveIndex::draw() // black ofBackground(0, 0, 0); - + if(_currentAnalysis){ _currentAnalysis->draw(); - + + if(_currentAnalysis->meshIsComplete){ - fbo.begin(); + fbo.begin(); + glShadeModel(GL_SMOOTH); + ofClear(0,0,0); + + camera.begin(); ofSetColor(0, 0, 0); - ofRect(0, 0, fbo.getWidth(), fbo.getHeight()); + //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(fbo.getWidth()/2, fbo.getHeight()/2); - ofRotateY(_meshRotation ); - ofTranslate(-fbo.getWidth()/2, -fbo.getHeight()/2); - _meshRotation+=0.5; + 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 ); _currentAnalysis->aMesh.draw(); - fbo.end(); + + camera.end(); + fbo.end(); + ofPixels pixels; fbo.readToPixels(pixels); - - + ofSaveImage(pixels,_currentAnalysis->meshFileName, OF_IMAGE_QUALITY_BEST); - //saving jpgs doesn't work maybe because of of_image_quality + //saving jpgs doesn't work - pngs only! } + } } diff --git a/example/RefractiveIndex.h b/example/RefractiveIndex.h index ba4c263..9b5bd26 100644 --- a/example/RefractiveIndex.h +++ b/example/RefractiveIndex.h @@ -10,6 +10,8 @@ #include "ofxOpenCv.h" #include "ofxXmlSettings.h" +#include "ofxOpenCv.h" + #define MODE_DRAWING 0xEEFF #define MODE_ANALYSING 0xFFEE @@ -55,7 +57,8 @@ protected: vector _analysisVector; float _meshRotation; - + float camDist; + ofEasyCam cam; public: // acquisition static ofPixels _pixels; @@ -70,8 +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; - - + ofLight light; }; \ No newline at end of file diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index c277f91..7603881 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -8,6 +8,8 @@ void AbstractAnalysis::setup(int camWidth, int camHeight) { meshIsComplete=false; + imageForContourAvailable=false; + _cam_w = camWidth; _cam_h = camHeight; if(RefractiveIndex::_mode == MODE_DRAWING) { ofFileDialogResult r = ofSystemLoadDialog("choooose da folda", true); diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index dae0cc8..214342e 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -62,10 +62,20 @@ public: // event ofEvent _synthesize_cb; bool meshIsComplete; + bool imageForContourAvailable; ofMesh aMesh; 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; string _whole_file_path_analysis, _whole_file_path_synthesis; diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index 969fdd4..81f8d23 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -29,6 +29,8 @@ void IResponseAnalysis::setup(int camWidth, int camHeight) meshIsComplete=false; _gotFirstImage=false; + _mesh_size_multiplier=4; + //int acq_run_time = 20; // 20 seconds of acquiring per run @@ -175,24 +177,18 @@ void IResponseAnalysis::synthesise() else{ imagePixels1[i]=0; } - if(imagePixels2[i]-backgroundPixels[i]>0){ - imagePixels2[i]-=backgroundPixels[i]; - } - else{ - imagePixels2[i]=0; - } - + } + //update the images with their new background subtracted selves image1.setFromPixels(imagePixels1); - image5.setFromPixels(imagePixels2); - //subtract background end/////////////// //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(make3DZmap(image1, image5, _background), image1,image5, 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"; _saved_filenames_synthesis.push_back(meshFileName); @@ -200,6 +196,7 @@ void IResponseAnalysis::synthesise() //flag that we are finished meshIsComplete=true; _synth_save_cnt++; + } } } @@ -417,65 +414,139 @@ void IResponseAnalysis::save_cb(Timer& timer) saveImageAnalysis(file_name); } -void IResponseAnalysis::setMeshFromPixels(ofPixels somePixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){ +void IResponseAnalysis::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); - //unsigned char * thesePixels =currentSecondImage.getPixels(); + ofColor meshColour=ofColor(255,0,0); - for(int i=0;i=somePixels.getWidth()){ - x=0; - y++; - } - + 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>=479){ + 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 + + } -ofPixels IResponseAnalysis::make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImag){ +vector IResponseAnalysis::_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++; - - } - - } - } + //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... @@ -483,14 +554,15 @@ ofPixels IResponseAnalysis::make3DZmap(ofImage &image1, ofImage &image2, ofImage for(int i=0;i sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh); //returns ofPixels but these pixels actually hold depth data. - ofPixels make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + //ofPixels make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + vector _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage); bool _gotFirstImage; ofImage _background; };