added the meshcode to all analyses (just for consistency... see extended description
1) Live/interactive version of one or two of the algorithms. I'd vote for IResponse, RelaxRate and ColorMulti as the ones to do live on the laptop. David is looking at this... 2) The frame skipping issue remains. I looked at this while travelling today, but couldn't figure it out. We're still saving out meshes at about half the rate of them being created. 3) The following three analyses do exactly the same thing currently, and it would be good if they had something approaching a real analysis happening. Right now it's just a simple z-map in black and white with some noise on top and lighting... kind of pretty but bit boring currently: ShapeFromShadingAnalysis CamNoiseAnalysis ShadowScapesAnalysis
This commit is contained in:
parent
8872b60133
commit
357573f81a
@ -21,12 +21,58 @@ 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 = 15;
|
||||
vertexSubsampling = 1;
|
||||
chooseColour = 5;
|
||||
multiplier = 4.0;
|
||||
|
||||
ofSetLineWidth(5.0f);
|
||||
glPointSize(5.0f);
|
||||
|
||||
//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;
|
||||
|
||||
///setup light
|
||||
ofEnableLighting();
|
||||
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
|
||||
_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;
|
||||
@ -88,7 +134,6 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||
cvGrayImage2.clear();
|
||||
cvGrayDiff2.clear();
|
||||
|
||||
cvConvertorImage.clear();
|
||||
|
||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
@ -97,9 +142,6 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
|
||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -150,63 +192,118 @@ void CamNoiseAnalysis::synthesise()
|
||||
}
|
||||
|
||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||
//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.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||
// cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||
//added by tom we weren't actually setting cvgrayimage1 anywhere
|
||||
// cvGrayImage1.setFromPixels(cvColorImage1.getPixels(),cvColorImage1.width,cvColorImage1.height);
|
||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||
//cvGrayImage1=cvColorImage1;
|
||||
|
||||
cvGrayImage1.erode();
|
||||
cvGrayImage1.erode();
|
||||
cvGrayImage1.erode();
|
||||
cvGrayImage1.blur();
|
||||
cvGrayImage1.contrastStretch();
|
||||
/* cvColorImage1.erode();
|
||||
cvColorImage1.erode();
|
||||
cvColorImage1.erode();
|
||||
cvColorImage1.blur();
|
||||
cvColorImage1.contrastStretch();*/
|
||||
|
||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||
string file_name;
|
||||
|
||||
file_name = ofToString(_synth_save_cnt, 2)+"_CamNoiseAnalysis_"+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(cvGrayImage1.width, cvGrayImage1.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(cvGrayImage1.getPixels(), cvGrayImage1.width, cvGrayImage1.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(cvGrayImage1,cvGrayImage1,cvGrayImage1);
|
||||
//cvConvertorImage.setFromGrayscalePlanarImages(cvColorImage1,cvColorImage1,cvColorImage1);
|
||||
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
|
||||
_synth_save_cnt++;
|
||||
|
||||
|
||||
//}
|
||||
// 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.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||
|
||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||
//cvGrayDiff1.erode();
|
||||
|
||||
cvGrayImage1.dilate();
|
||||
cvGrayImage1.blur(5);
|
||||
cvGrayImage1.contrastStretch();
|
||||
|
||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||
|
||||
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||
|
||||
//cvFloatImage1 = cvColorImage1;
|
||||
//cvGrayImage1 = cvColorImage1;
|
||||
|
||||
|
||||
//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());
|
||||
|
||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||
if(!_gotFirstImage){
|
||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||
_background=image1;
|
||||
_gotFirstImage=true;
|
||||
}
|
||||
|
||||
//subtract background begin///////////////
|
||||
|
||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||
|
||||
//DIFFERENCING SUBSEQUENT IMAGES
|
||||
/*
|
||||
for(int i=0;i<imagePixels1.size();i++){
|
||||
//unsigned char val=imagePixels1[i];
|
||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||
imagePixels1[i]-=imagePixels2[i];
|
||||
}
|
||||
else{
|
||||
imagePixels1[i]=0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//DIFFERENCING THE BACKGROUND
|
||||
/*
|
||||
for(int i=0;i<imagePixels1.size();i++){
|
||||
//unsigned char val=imagePixels1[i];
|
||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||
if(imagePixels1[i]-backgroundPixels[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;
|
||||
|
||||
//with jpgs this was refusing to save out
|
||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_CamNoiseAnalysis_"+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]<<endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||
@ -440,3 +537,411 @@ void CamNoiseAnalysis::save_cb(Timer& timer)
|
||||
|
||||
saveImageAnalysis(file_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CamNoiseAnalysis::setMeshFromPixels(vector<float> 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<sPixels.size();i++){
|
||||
zPlaneAverage+=sPixels[i];
|
||||
}
|
||||
if (sPixels.size()!=0) {
|
||||
zPlaneAverage/=sPixels.size();
|
||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||
}
|
||||
|
||||
else{
|
||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||
}
|
||||
|
||||
if(chooseColour==1){
|
||||
|
||||
for(int i=0;i<sPixels.size();i++){
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
ofColor currentSecondImageColor;
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
ofColor currentSecondImageColor;
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
int randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
|
||||
int randomJitter2 = 0;
|
||||
int randomJitter = 0;
|
||||
|
||||
ofColor currentSecondImageColor;
|
||||
ofColor currentSecondImageBW;
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor(currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor(currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW.clamp());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW.clamp() );
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<float> CamNoiseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||
|
||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||
vector<float> 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.size();i++){
|
||||
thesePixels[i]=0;
|
||||
}
|
||||
|
||||
int x=0;
|
||||
int y=0;
|
||||
|
||||
int chooseComparison=1;
|
||||
|
||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||
|
||||
if(chooseComparison==1){
|
||||
//for each pixel...
|
||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||
|
||||
for(int i=0;i<imagePixels1.size();i+=3){
|
||||
|
||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||
|
||||
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
||||
|
||||
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
||||
|
||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||
|
||||
//int thisDiff=abs(imageColor1.getHue());
|
||||
//int thisDiff=abs(imageColor1.getBrightness());
|
||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||
|
||||
int thisDiff=-abs(imageColor1.getBrightness()+ofRandom(-50,50));
|
||||
//int thisDiff=abs(imageColor1.getLightness());
|
||||
//int thisDiff=-abs(imageColor1.r);
|
||||
|
||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||
|
||||
//red hue: 0
|
||||
//green hue: 120
|
||||
//blue hue: 240
|
||||
|
||||
differences.push_back(multiplier * thisDiff);
|
||||
|
||||
thesePixels[i]=thisDiff;
|
||||
thesePixels[i+1]=thisDiff;
|
||||
thesePixels[i+2]=thisDiff;
|
||||
x++;
|
||||
|
||||
if(x>=imagePixels1.getWidth()){
|
||||
x=0;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||
return differences;
|
||||
}
|
||||
|
||||
@ -61,10 +61,21 @@ protected:
|
||||
|
||||
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<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||
|
||||
//depth map function
|
||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||
|
||||
int vertexSubsampling;
|
||||
int chooseColour;
|
||||
ofPrimitiveMode meshMode;
|
||||
ofBlendMode blendMode;
|
||||
float multiplier;
|
||||
|
||||
bool _gotFirstImage;
|
||||
ofImage _background;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -28,10 +28,52 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
||||
//flag for main sketch
|
||||
meshIsComplete=false;
|
||||
_gotFirstImage=false;
|
||||
_mesh_size_multiplier = 15;
|
||||
vertexSubsampling = 1;
|
||||
chooseColour = 5;
|
||||
multiplier = 4.0;
|
||||
|
||||
_mesh_size_multiplier=4;
|
||||
ofSetLineWidth(5.0f);
|
||||
glPointSize(5.0f);
|
||||
|
||||
|
||||
//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;
|
||||
|
||||
///setup light
|
||||
ofEnableLighting();
|
||||
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
int acq_run_time; // 10 seconds of acquiring per run
|
||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shadowscapes", ACQUIRE_TIME);
|
||||
@ -95,8 +137,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
||||
cvColorImage2.clear();
|
||||
cvGrayImage2.clear();
|
||||
cvGrayDiff2.clear();
|
||||
|
||||
cvConvertorImage.clear();
|
||||
|
||||
|
||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
||||
@ -106,7 +147,6 @@ void ShadowScapesAnalysis::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);
|
||||
|
||||
}
|
||||
|
||||
@ -150,65 +190,116 @@ void ShadowScapesAnalysis::synthesise()
|
||||
}
|
||||
|
||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||
|
||||
// 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);
|
||||
|
||||
//cvGrayImage1 = cvColorImage1;
|
||||
//cvGrayImage2 = cvColorImage2;
|
||||
|
||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
||||
|
||||
cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||
cvGrayDiff1.erode();
|
||||
cvGrayDiff1.contrastStretch();
|
||||
cvGrayDiff1.blur(5);
|
||||
cvGrayDiff1.dilate();
|
||||
|
||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||
//cvGrayDiff1.erode();
|
||||
|
||||
cvGrayImage1.dilate();
|
||||
cvGrayImage1.blur(5);
|
||||
cvGrayImage1.contrastStretch();
|
||||
|
||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||
string file_name;
|
||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
||||
|
||||
if(_dir == H) {
|
||||
file_name = ofToString(_synth_save_cnt, 2)+"_H_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
||||
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
||||
|
||||
//cvFloatImage1 = cvColorImage1;
|
||||
//cvGrayImage1 = cvColorImage1;
|
||||
|
||||
|
||||
//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());
|
||||
|
||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||
if(!_gotFirstImage){
|
||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||
_background=image1;
|
||||
_gotFirstImage=true;
|
||||
}
|
||||
|
||||
if(_dir == V) {
|
||||
file_name = ofToString(_synth_save_cnt, 2)+"_V_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
||||
}
|
||||
//subtract background begin///////////////
|
||||
|
||||
if(_dir == D) {
|
||||
file_name = ofToString(_synth_save_cnt, 2)+"_D_ShadowScapesSynthesis_"+ofToString(_run_cnt,2)+".jpg";
|
||||
}
|
||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
||||
|
||||
//DIFFERENCING SUBSEQUENT IMAGES
|
||||
/*
|
||||
for(int i=0;i<imagePixels1.size();i++){
|
||||
//unsigned char val=imagePixels1[i];
|
||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
||||
imagePixels1[i]-=imagePixels2[i];
|
||||
}
|
||||
else{
|
||||
imagePixels1[i]=0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//DIFFERENCING THE BACKGROUND
|
||||
/*
|
||||
for(int i=0;i<imagePixels1.size();i++){
|
||||
//unsigned char val=imagePixels1[i];
|
||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
||||
imagePixels1[i]-=backgroundPixels[i];
|
||||
}
|
||||
else{
|
||||
imagePixels1[i]=0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//<---- 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);
|
||||
//update the images with their new background subtracted selves
|
||||
image1.setFromPixels(imagePixels1);
|
||||
|
||||
//flag the main app that we aren't read yet
|
||||
meshIsComplete=false;
|
||||
|
||||
//<---- NEW SAVING - seems to fix WINDOWS saving out BLACK FRAMES PROBLEM ---->
|
||||
//ofImage image;
|
||||
//image.allocate(cvGrayDiff1.width, cvGrayDiff1.height, OF_IMAGE_GRAYSCALE);
|
||||
//make a mesh - this mesh will be drawn in the main app
|
||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||
|
||||
//*** This needs to be here for OSX of we get a BAD ACCESS ERROR. DOES IT BREAK WINDOWS? ***//
|
||||
//image.setUseTexture(false);
|
||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
||||
|
||||
//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);
|
||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||
//string file_name;
|
||||
|
||||
//with jpgs this was refusing to save out
|
||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShadowScapeAnalysis_"+ofToString(_run_cnt,2)+".png";
|
||||
_saved_filenames_synthesis.push_back(meshFileName);
|
||||
|
||||
saveImageSynthesis(file_name, &cvConvertorImage, OF_IMAGE_GRAYSCALE);
|
||||
//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]<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,3 +575,413 @@ void ShadowScapesAnalysis::save_cb(Timer& timer)
|
||||
saveImageAnalysis(file_name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ShadowScapesAnalysis::setMeshFromPixels(vector<float> 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<sPixels.size();i++){
|
||||
zPlaneAverage+=sPixels[i];
|
||||
}
|
||||
if (sPixels.size()!=0) {
|
||||
zPlaneAverage/=sPixels.size();
|
||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
||||
}
|
||||
|
||||
else{
|
||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
||||
}
|
||||
|
||||
if(chooseColour==1){
|
||||
|
||||
for(int i=0;i<sPixels.size();i++){
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
ofColor currentSecondImageColor;
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
mesh.addColor( currentSecondImageColor);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
ofColor currentSecondImageColor;
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
int randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
||||
|
||||
ofSeedRandom();
|
||||
|
||||
currentSecondImageColor.r = ofRandom(0,255);
|
||||
currentSecondImageColor.g = ofRandom(0,255);
|
||||
currentSecondImageColor.b = ofRandom(0,255);
|
||||
|
||||
randomJitter = ofRandom(0,5);
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<sPixels.size();i++){
|
||||
|
||||
int randomJitter2 = 0;
|
||||
int randomJitter = 0;
|
||||
|
||||
ofColor currentSecondImageColor;
|
||||
ofColor currentSecondImageBW;
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor(currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor(currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW.clamp());
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW.clamp() );
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
||||
|
||||
x=x+vertexSubsampling;
|
||||
if(x>=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<float> ShadowScapesAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
||||
|
||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
||||
vector<float> 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.size();i++){
|
||||
thesePixels[i]=0;
|
||||
}
|
||||
|
||||
int x=0;
|
||||
int y=0;
|
||||
|
||||
int chooseComparison=1;
|
||||
|
||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
||||
|
||||
if(chooseComparison==1){
|
||||
//for each pixel...
|
||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
||||
|
||||
for(int i=0;i<imagePixels1.size();i+=3){
|
||||
|
||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||
|
||||
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
||||
|
||||
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
||||
|
||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||
|
||||
//int thisDiff=abs(imageColor1.getHue());
|
||||
//int thisDiff=abs(imageColor1.getBrightness());
|
||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||
|
||||
int thisDiff=-abs(imageColor1.getBrightness()+ofRandom(-50,50));
|
||||
//int thisDiff=abs(imageColor1.getLightness());
|
||||
//int thisDiff=-abs(imageColor1.r);
|
||||
|
||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
||||
|
||||
//red hue: 0
|
||||
//green hue: 120
|
||||
//blue hue: 240
|
||||
|
||||
differences.push_back(multiplier * thisDiff);
|
||||
|
||||
thesePixels[i]=thisDiff;
|
||||
thesePixels[i+1]=thisDiff;
|
||||
thesePixels[i+2]=thisDiff;
|
||||
x++;
|
||||
|
||||
if(x>=imagePixels1.getWidth()){
|
||||
x=0;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
||||
return differences;
|
||||
}
|
||||
|
||||
|
||||
@ -66,10 +66,20 @@ protected:
|
||||
|
||||
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<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
||||
|
||||
//depth map function
|
||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
||||
|
||||
int vertexSubsampling;
|
||||
int chooseColour;
|
||||
ofPrimitiveMode meshMode;
|
||||
ofBlendMode blendMode;
|
||||
float multiplier;
|
||||
|
||||
bool _gotFirstImage;
|
||||
ofImage _background;
|
||||
|
||||
|
||||
};
|
||||
@ -24,24 +24,53 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
||||
//flag for main sketch
|
||||
meshIsComplete=false;
|
||||
_gotFirstImage=false;
|
||||
_mesh_size_multiplier = 10;
|
||||
_mesh_size_multiplier = 15;
|
||||
vertexSubsampling = 1;
|
||||
chooseColour = 5;
|
||||
multiplier = 4.0;
|
||||
|
||||
ofSetLineWidth(5.0f);
|
||||
glPointSize(5.0f);
|
||||
|
||||
//blendMode = OF_BLENDMODE_ADD;
|
||||
//blendMode = OF_BLENDMODE_MULTIPLY;
|
||||
//blendMode = OF_BLENDMODE_SUBTRACT;
|
||||
//blendMode = OF_BLENDMODE_ALPHA;
|
||||
blendMode = OF_BLENDMODE_ALPHA;
|
||||
//blendMode = OF_BLENDMODE_SCREEN;
|
||||
|
||||
meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
||||
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
||||
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
||||
//meshMode = OF_PRIMITIVE_LINES;
|
||||
meshMode = OF_PRIMITIVE_LINES;
|
||||
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
||||
//meshMode = OF_PRIMITIVE_POINTS;
|
||||
|
||||
///setup light
|
||||
ofEnableLighting();
|
||||
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
||||
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
glEnable(GL_LIGHT1);
|
||||
|
||||
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;
|
||||
@ -204,8 +233,6 @@ void ShapeFromShadingAnalysis::synthesise()
|
||||
fileNameQuad = "QUAD4";
|
||||
cout<<"FOUND QUAD4"<<endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||
|
||||
@ -217,12 +244,10 @@ void ShapeFromShadingAnalysis::synthesise()
|
||||
|
||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
||||
//cvGrayDiff1.erode();
|
||||
cvGrayImage1.contrastStretch();
|
||||
|
||||
cvGrayImage1.dilate();
|
||||
cvGrayImage1.blur(5);
|
||||
|
||||
//cvGrayDiff1.dilate();
|
||||
//cvGrayDiff1.contrastStretch();
|
||||
cvGrayImage1.contrastStretch();
|
||||
|
||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
||||
@ -248,8 +273,6 @@ void ShapeFromShadingAnalysis::synthesise()
|
||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
||||
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
||||
|
||||
|
||||
|
||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
||||
if(!_gotFirstImage){
|
||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
||||
@ -278,7 +301,7 @@ void ShapeFromShadingAnalysis::synthesise()
|
||||
*/
|
||||
|
||||
//DIFFERENCING THE BACKGROUND
|
||||
|
||||
/*
|
||||
for(int i=0;i<imagePixels1.size();i++){
|
||||
//unsigned char val=imagePixels1[i];
|
||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
||||
@ -289,6 +312,7 @@ void ShapeFromShadingAnalysis::synthesise()
|
||||
imagePixels1[i]=0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//update the images with their new background subtracted selves
|
||||
image1.setFromPixels(imagePixels1);
|
||||
@ -319,23 +343,20 @@ void ShapeFromShadingAnalysis::synthesise()
|
||||
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";
|
||||
@ -387,42 +408,48 @@ void ShapeFromShadingAnalysis::displayresults()
|
||||
void ShapeFromShadingAnalysis::draw()
|
||||
{
|
||||
|
||||
ofEnableSmoothing();
|
||||
|
||||
ofEnableLighting();
|
||||
ofEnableSeparateSpecularLight();
|
||||
light.enable();
|
||||
lightStatic.enable();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
ofSetLineWidth(5.0f);
|
||||
glPointSize(5.0f);
|
||||
|
||||
ofEnableBlendMode(blendMode);
|
||||
//rotate light around origin ofviewspace
|
||||
float xx=cos(ofGetElapsedTimef()*0.4)*150;
|
||||
float yy=sin(ofGetElapsedTimef()*0.4)*150;
|
||||
float zz=0;
|
||||
|
||||
if(fileNameQuad=="QUAD1")
|
||||
{
|
||||
light.setPosition(ofGetWidth(),ofGetHeight()/2,1);
|
||||
lightStatic.setPosition(ofGetWidth(),ofGetHeight()/2,1);
|
||||
|
||||
GLfloat light_position[] = { 1000, 1000, 20, 0.0 };
|
||||
GLfloat light_position1[] = { 1000, 1000, 20, 0.0 };
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
} else if(fileNameQuad=="QUAD2")
|
||||
{
|
||||
light.setPosition(ofGetWidth()/2,ofGetHeight(),1);
|
||||
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight(),1);
|
||||
|
||||
GLfloat light_position[] = { 1000, -1000, 20, 0.0 };
|
||||
GLfloat light_position1[] = { 1000, -1000, 20, 0.0 };
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
|
||||
} else if(fileNameQuad=="QUAD3")
|
||||
{
|
||||
light.setPosition(0,ofGetHeight()/2,5);
|
||||
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
||||
|
||||
GLfloat light_position[] = {-1000, 1000, 20, 0.0 };
|
||||
GLfloat light_position1[] = { -1000, 1000, 20, 0.0 };
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
|
||||
} else if(fileNameQuad=="QUAD4")
|
||||
{
|
||||
light.setPosition(ofGetWidth()/2,0,5);
|
||||
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
||||
GLfloat light_position[] = { -1000, -1000, 20, 0.0 };
|
||||
GLfloat light_position1[] = { -1000, -1000, 20, 0.0 };
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (_state) {
|
||||
case STATE_ACQUIRING:
|
||||
{
|
||||
@ -1053,7 +1080,7 @@ void ShapeFromShadingAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW.clamp());
|
||||
mesh.addColor( currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
@ -1061,7 +1088,7 @@ void ShapeFromShadingAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor(currentSecondImageBW.clamp());
|
||||
mesh.addColor(currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
@ -1069,7 +1096,7 @@ void ShapeFromShadingAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor(currentSecondImageBW.clamp());
|
||||
mesh.addColor(currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
||||
@ -1077,7 +1104,7 @@ void ShapeFromShadingAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage
|
||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
||||
|
||||
mesh.addColor( currentSecondImageBW.clamp() );
|
||||
mesh.addColor( currentSecondImageBW);
|
||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
||||
|
||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
||||
@ -1141,16 +1168,18 @@ vector<float> ShapeFromShadingAnalysis::_returnDepthsAtEachPixel(ofImage &image1
|
||||
for(int i=0;i<imagePixels1.size();i+=3){
|
||||
|
||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||
|
||||
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
||||
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
||||
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
||||
|
||||
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
||||
|
||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
||||
|
||||
//int thisDiff=abs(imageColor1.getHue());
|
||||
//int thisDiff=abs(imageColor1.getBrightness());
|
||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
||||
|
||||
int thisDiff=-abs(imageColor1.getBrightness());
|
||||
|
||||
int thisDiff=-abs(imageColor1.getBrightness()+ofRandom(-50,50));
|
||||
//int thisDiff=abs(imageColor1.getLightness());
|
||||
//int thisDiff=-abs(imageColor1.r);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user