corrected file confusion AGAIN

This commit is contained in:
Tom Schofield 2012-02-19 18:25:37 +00:00
parent 1d5d6abbde
commit c53eb2eb6c
3 changed files with 127 additions and 3 deletions

View File

@ -41,6 +41,7 @@ void AbstractAnalysis::do_synthesize() {
_state = STATE_SYNTHESISING; _state = STATE_SYNTHESISING;
synthesise(); synthesise();
_state = STATE_DISPLAY_RESULTS; _state = STATE_DISPLAY_RESULTS;
display_results();
ofNotifyEvent(_synthesize_cb, _name); ofNotifyEvent(_synthesize_cb, _name);
} }
@ -143,7 +144,70 @@ ofPixels AbstractAnalysis::calculateListOfZValues(ofImage image1, ofImage image2
} }
void AbstractAnalysis:: setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh){ ofPixels AbstractAnalysis::calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison, int colourValue){
//zScale is the mapping factor from pixel difference to shift on the zPlane
int zScale=200;
ofPixels imagePixels1 = image1.getPixelsRef();
ofPixels imagePixels2 = image2.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];
//where are we in the image pixel array
int x=0;
int y=0;
//for each pixel...
for(int i=0;i<imagePixels1.size();i+=3){
//get the colour of each image at this x y location - we will use these colours for comparison according to the below criteria
ofColor colourImage1 = imagePixels1.getColor(x, y);
ofColor colourImage2 = imagePixels2.getColor(x, y);
//COMPARE THIS PIXEL'S VALUES with the first image in the sequence
int thisDiff;
//compare Red
if (whichComparison==1) {
thisDiff=ofMap((colourImage1.r-colourImage2.r),-255,255,0,zScale);
}
//compare blue
if (whichComparison==2) {
thisDiff=ofMap((colourImage1.g-colourImage2.g),-255,255,0,zScale);
}
//compare green
if (whichComparison==3) {
thisDiff=ofMap((colourImage1.b-colourImage2.b),-255,255,0,zScale);
}
//compare hue
if (whichComparison==4) {
thisDiff=ofMap((colourImage1.getHue()-colourImage2.getHue()),-255,255,0,zScale);
}
//compare brightness
if (whichComparison==5) {
thisDiff=ofMap((colourImage1.getBrightness()-colourImage2.getBrightness()),-255,255,0,zScale);
}
thesePixels[i]=thisDiff;
thesePixels[i+1]=thisDiff;
thesePixels[i+2]=thisDiff;
x++;
//new line
if(x>imagePixels1.getWidth()){
x=0;
y++;
}
}
difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
return difference;
}
void AbstractAnalysis::setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh){
int x=0; int x=0;
int y=0; int y=0;
@ -165,3 +229,55 @@ void AbstractAnalysis:: setMeshFromPixels(ofPixels somePixels, ofImage currentSe
} }
} }
vector<string>AbstractAnalysis:: getListOfImageFilePaths(string location, string whichAnalysis){
string path = ofToDataPath("")+"debug_analysis/"+location+"/"+whichAnalysis;
ofxDirList dirList;
int numDirs = dirList.listDir(path);
vector<string>directoryNames;
//get the last folder alphabetically - this should probably change to do something fancy with date to find most recent but don't want to code that until we are sure
string dirName=dirList.getName(numDirs-1);
const char *results=dirName.c_str();
ofFile file=ofFile(path+"/"+dirName);
vector<string>fileNamesToReturn;
// get
if(file.isDirectory()){
dirList.listDir(path+"/"+dirName);
//if there are no files, exit here
if(dirList.size()==0){
//if it's empty return an error warning
fileNamesToReturn.push_back("NO FILE HERE!");
cout<<"NO FILE HERE!";
return fileNamesToReturn;
}
for (int i=0; i<dirList.size(); i++) {
string fname=dirList.getName(i);
const char *results=fname.c_str();
//full path is what actually gets written into the vector
string fullPath=path+"/"+dirName+"/"+fname;
fileNamesToReturn.push_back(fullPath);
}
}
else{
cout<<"WARNING, DIRECTORY NOT FOUND";
fileNamesToReturn.push_back("NO FILE HERE!");
}
return fileNamesToReturn;
}

View File

@ -40,10 +40,18 @@ protected:
// analysis + synthesize images - all the children (see - do_synthesize) // analysis + synthesize images - all the children (see - do_synthesize)
virtual void synthesise() = 0; virtual void synthesise() = 0;
virtual ofPixels calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison); //added tom s 19/2 function runs a call back exactly like acquire.
virtual void display_results() = 0;
//returns ofPixels which contain the color differences between the two images. Is overloaded to include comparison with values written in to file names for some analyses
virtual ofPixels calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison);
virtual ofPixels calculateListOfZValues(ofImage image1, ofImage image2, int whichComparison, int colourValue);
//uses the returned pixels from make3DZmap to make a mesh of points whose Z positions are set by the brightness values in ofPixels - ofPixels is being used as a convenient container for a bunch of z coordinates
virtual void setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh); virtual void setMeshFromPixels(ofPixels somePixels, ofImage currentSecondImage, ofMesh * someMesh);
//this is purely for debug purposes and loads old images from middlesborough test
virtual vector<string> getListOfImageFilePaths(string location, string whichAnalysis);
public: public:
string _name; string _name;

View File

@ -77,7 +77,7 @@ void ColorSingleAnalysis::synthesise()
int index=0; int index=0;
//if you want to see what this looks like with real data ignore the new filenames and load teh old ones. //if you want to see what this looks like with real data ignore the new filenames and load teh old ones.
bool debug=false; bool debug=true;
if(debug){ if(debug){
_saved_filenames.clear(); _saved_filenames.clear();
_saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name); _saved_filenames=getListOfImageFilePaths("MIDDLESBOROUGH", _name);