diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index e26495b..ae0364a 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -19,7 +19,7 @@ #define CAMERA_ACQU_WIDTH 640 #define CAMERA_ACQU_HEIGHT 480 -#define LOCATION "MIDDLESBOROUGH" +#define LOCATION "BRADFORD" #define ISTATE_UNDEF 0xEEEE #define ISTATE_START 0xAAAA @@ -101,7 +101,7 @@ 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)); @@ -133,6 +133,9 @@ void RefractiveIndex::setup() _currentAnalysis = NULL; _state = ISTATE_UNDEF; + fbo.allocate(_vid_w,_vid_h); + _meshRotation=0; + } void RefractiveIndex::analysis_cb(string & analysis) @@ -211,8 +214,30 @@ void RefractiveIndex::draw() // black ofBackground(0, 0, 0); - if(_currentAnalysis) + if(_currentAnalysis){ _currentAnalysis->draw(); + cout<<_currentAnalysis->meshIsComplete<meshIsComplete){ + fbo.begin(); + + ofSetColor(0, 0, 0); + ofRect(0, 0, fbo.getWidth(), fbo.getHeight()); + ofPushMatrix(); + ofTranslate(fbo.getWidth()/2, fbo.getHeight()/2); + ofRotateY(_meshRotation ); + ofTranslate(-fbo.getWidth()/2, -fbo.getHeight()/2); + _meshRotation+=0.5; + _currentAnalysis->aMesh.draw(); + fbo.end(); + ofPixels pixels; + fbo.readToPixels(pixels); + cout<<_currentAnalysis->meshFileName<meshFileName, OF_IMAGE_QUALITY_BEST); + //saving jpgs doesn't work maybe because of of_image_quality + + } + } } void RefractiveIndex::setup_camera() diff --git a/example/RefractiveIndex.h b/example/RefractiveIndex.h index 61b40f8..ba4c263 100644 --- a/example/RefractiveIndex.h +++ b/example/RefractiveIndex.h @@ -54,6 +54,8 @@ protected: AnalysisAdaptor* _analysisAdapator; vector _analysisVector; + float _meshRotation; + public: // acquisition static ofPixels _pixels; @@ -69,4 +71,7 @@ public: static string _location; static ofxXmlSettings XML; // made this static so we can access RUN_NUM in the analyses + ofFbo fbo; + + }; \ No newline at end of file diff --git a/src/AbstractAnalysis.cpp b/src/AbstractAnalysis.cpp index 752f0ba..c277f91 100644 --- a/src/AbstractAnalysis.cpp +++ b/src/AbstractAnalysis.cpp @@ -7,8 +7,8 @@ void AbstractAnalysis::setup(int camWidth, int camHeight) { + meshIsComplete=false; _cam_w = camWidth; _cam_h = camHeight; - if(RefractiveIndex::_mode == MODE_DRAWING) { ofFileDialogResult r = ofSystemLoadDialog("choooose da folda", true); if(!r.bSuccess) { @@ -19,7 +19,7 @@ void AbstractAnalysis::setup(int camWidth, int camHeight) { _whole_file_path_analysis = r.filePath; _whole_file_path_synthesis = r.filePath + "/darwings"; } - + } // this is the main threaded loop for a given analysis @@ -50,6 +50,8 @@ void AbstractAnalysis::do_synthesize() { case MODE_DRAWING: { + + ofxFileHelper fileHelperDrawing; if(!fileHelperDrawing.doesDirectoryExist(_whole_file_path_synthesis)){ fileHelperDrawing.makeDirectory(_whole_file_path_synthesis); @@ -153,6 +155,7 @@ void AbstractAnalysis::create_dir_allocate_images() myGrayImage1.setUseTexture(false); myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE); + //////////////////////////////END ALLOCATE IMAGES ////////////////////////////////////////////////// } diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index f736b21..dae0cc8 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -61,6 +61,10 @@ public: // event ofEvent _synthesize_cb; + bool meshIsComplete; + ofMesh aMesh; + string meshFileName; + protected: int _cam_w, _cam_h; diff --git a/src/ColorSingleAnalysis.h b/src/ColorSingleAnalysis.h index 6a9a8dd..4b131e5 100755 --- a/src/ColorSingleAnalysis.h +++ b/src/ColorSingleAnalysis.h @@ -1,4 +1,4 @@ -/* + /* ~ author: dviid ~ contact: dviid@labs.ciid.dk */ diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index 884f6a9..df3c795 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -25,6 +25,10 @@ void IResponseAnalysis::setup(int camWidth, int camHeight) 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; + //int acq_run_time = 20; // 20 seconds of acquiring per run @@ -125,7 +129,9 @@ void IResponseAnalysis::acquire() void IResponseAnalysis::synthesise() { + cout<<"SYNTHESISING IRESPONSE"; + //cout << "IResponseAnalysis::saving synthesis...\n"; if(_state == STATE_STOP) return; @@ -147,50 +153,51 @@ void IResponseAnalysis::synthesise() 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]< - // 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); - - _synth_save_cnt++; - - + //subtract background begin/////////////// + ofPixels imagePixels1 = image1.getPixelsRef(); + ofPixels imagePixels2 = image5.getPixelsRef(); + ofPixels backgroundPixels = _background.getPixelsRef(); + + for(int i=0;i0){ + imagePixels1[i]-=backgroundPixels[i]; + } + 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); + //with jpgs this was refusing to save out + meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".png"; + //flag that we are finished + meshIsComplete=true; + _synth_save_cnt++; } } } @@ -407,3 +414,95 @@ void IResponseAnalysis::save_cb(Timer& timer) saveImageAnalysis(file_name); } + +void IResponseAnalysis::setMeshFromPixels(ofPixels somePixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){ + int x=0; + int y=0; + + //get rid of all previous vectors and colours + mesh.clear(); + + //unsigned char * thesePixels =currentSecondImage.getPixels(); + + for(int i=0;i=somePixels.getWidth()){ + x=0; + y++; + } + + } +} +ofPixels IResponseAnalysis::make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImag){ + + ofPixels imagePixels1 = image1.getPixelsRef(); + ofPixels imagePixels2 = image2.getPixelsRef(); + ofPixels backgroundPixels = backgroundImag.getPixelsRef(); + + + 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]; + + int x=0; + int y=0; + + int chooseComparison=1; + //previous versiom which compared two images -now deprecated + if(chooseComparison==0){ + //for each pixel... + 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... + 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 difference; + +} + diff --git a/src/IResponseAnalysis.h b/src/IResponseAnalysis.h index ebd471f..0cd7374 100755 --- a/src/IResponseAnalysis.h +++ b/src/IResponseAnalysis.h @@ -62,4 +62,10 @@ protected: //this is the temporary container to allow us to convert and save out greyscale images ofxCvColorImage cvConvertorImage; + //mesh making function + void setMeshFromPixels(ofPixels somePixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh); + //returns ofPixels but these pixels actually hold depth data. + ofPixels make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + bool _gotFirstImage; + ofImage _background; };