diff --git a/src/RelaxRateAnalysis.cpp b/src/RelaxRateAnalysis.cpp index 405c7e8..0ac85fc 100755 --- a/src/RelaxRateAnalysis.cpp +++ b/src/RelaxRateAnalysis.cpp @@ -356,9 +356,7 @@ void RelaxRateAnalysis::draw() light.enable(); lightStatic.enable(); - light.setPosition(ofGetWidth()/2,ofGetHeight()/2,5); - lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,-1); glEnable(GL_DEPTH_TEST); diff --git a/src/ShapeFromShadingAnalysis.cpp b/src/ShapeFromShadingAnalysis.cpp index ce72cc9..56c1716 100755 --- a/src/ShapeFromShadingAnalysis.cpp +++ b/src/ShapeFromShadingAnalysis.cpp @@ -24,9 +24,23 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight) //flag for main sketch meshIsComplete=false; _gotFirstImage=false; + _mesh_size_multiplier = 10; + vertexSubsampling = 1; + chooseColour = 5; + multiplier = 4.0; - _mesh_size_multiplier=4; - + //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_shapefromshading", ACQUIRE_TIME); @@ -173,6 +187,26 @@ 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"< - // 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); + + //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()); + - //<---- 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); + ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// + if(!_gotFirstImage){ + cout<<"background image is"<< _saved_filenames_analysis[i]< /// - cvConvertorImage.setFromGrayscalePlanarImages(cvGrayDiff1,cvGrayDiff1,cvGrayDiff1); + //DIFFERENCING SUBSEQUENT IMAGES + /* + for(int i=0;i0){ + imagePixels1[i]-=imagePixels2[i]; + } + else{ + imagePixels1[i]=0; + } + } + */ - saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE); + //DIFFERENCING THE BACKGROUND + + for(int i=0;i0){ + 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); + + + } else if(fileNameQuad=="QUAD2") + { + + //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]< 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=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=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=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=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=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 ShapeFromShadingAnalysis::_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/ShapeFromShadingAnalysis.h b/src/ShapeFromShadingAnalysis.h index c4b16e6..46045b5 100755 --- a/src/ShapeFromShadingAnalysis.h +++ b/src/ShapeFromShadingAnalysis.h @@ -31,6 +31,8 @@ public: protected: string quad; + string fileNameQuad; + bool _RUN_DONE; float _flip, _level; int _animation_cnt1; @@ -82,6 +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 sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh); + + //depth map function + vector _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + + int vertexSubsampling; + int chooseColour; + ofPrimitiveMode meshMode; + ofBlendMode blendMode; + float multiplier; + bool _gotFirstImage; ofImage _background; }; diff --git a/src/StrobeAnalysis.cpp b/src/StrobeAnalysis.cpp index 387e004..65ffa2c 100755 --- a/src/StrobeAnalysis.cpp +++ b/src/StrobeAnalysis.cpp @@ -102,9 +102,7 @@ void StrobeAnalysis::setup(int camWidth, int camHeight) 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);