summaryrefslogtreecommitdiff
path: root/offsetProject/src/imageStore.h
diff options
context:
space:
mode:
Diffstat (limited to 'offsetProject/src/imageStore.h')
-rw-r--r--offsetProject/src/imageStore.h87
1 files changed, 83 insertions, 4 deletions
diff --git a/offsetProject/src/imageStore.h b/offsetProject/src/imageStore.h
index 9cde96c..2f8ccbb 100644
--- a/offsetProject/src/imageStore.h
+++ b/offsetProject/src/imageStore.h
@@ -7,6 +7,9 @@
#define FLANN_MATRIX_SIZE 5
+#define INSTAGRAM_DISPLAY_TIME 5
+#define IMAGE_FREEZE_TIME 5
+
#include "ofMain.h"
#include "ofxJSONElement.h"
#include "ofxOpenCv.h"
@@ -29,6 +32,9 @@ class imageStore : public ofThread{
std::map<std::string,ofImage> images;
vector<ofImage*> imageptrs;
deque<std::string> to_update;
+ bool newinstagram;
+ ofImage instagram_image;
+ float newinstagramtime;
//Matrix<float> dataset; doesn't need to be retained?
@@ -56,7 +62,7 @@ class imageStore : public ofThread{
img.update();
images["000000"]=img;
//colours["000000"]=ofColor(0,0,0);
-
+ newinstagram=false;
}
~imageStore(){
delete index;
@@ -161,6 +167,46 @@ class imageStore : public ofThread{
}
}
+ bool new_instagram(){
+ if (newinstagram){
+ if( lock() ){
+ loadtexture(instagram_image);
+ newinstagram=false;
+ newinstagramtime=ofGetElapsedTimef();
+ unlock();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ bool drawinstagram(int x,int y,int w,int h){
+ if( lock() ){
+ instagram_image.draw(x,y,w,h);
+ unlock();
+ }
+ if (ofGetElapsedTimef()-newinstagramtime>INSTAGRAM_DISPLAY_TIME) return false;
+ return true;
+ }
+
+ void instagram_floats(float* floatImage){
+ if( lock() ){
+
+ int size=ceil(ofGetHeight()/MAX_TILE_SIZE)*FLANN_MATRIX_SIZE;
+ ofImage imm=instagram_image;
+ imm.resize(size,size);
+ uint8_t* cptr=imm.getPixels();
+ for (int i=0;i<size;i++){
+ for (int j=0;j<size;j++){
+ floatImage[(i*size+j)*3]=cptr[(i*size+j)*3];
+ floatImage[(i*size+j)*3+1]=cptr[(i*size+j)*3+1];
+ floatImage[(i*size+j)*3+2]=cptr[(i*size+j)*3+2];
+ }
+ }
+ unlock();
+ }
+ }
+
//void flann(const ofImage& _img){
//--------------------------
@@ -178,6 +224,9 @@ class imageStore : public ofThread{
ofImage img;
img.setUseTexture(false);
img.loadImage(ofToString(IMAGE_STORE_SIZE)+"/"+image_path.getFiles()[i].getFileName());
+
+ if (i==image_path.size()-1) instagram_image=img;
+
img.resize(MAX_TILE_SIZE,MAX_TILE_SIZE);
//colours[image_path.getFiles()[i].getBaseName()]=get_colour(img);
@@ -193,6 +242,8 @@ class imageStore : public ofThread{
image_path.create();
}
+
+
//build the flann index
Matrix<float> dataset(&data[0],data.size()/(3*FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE),3*FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE);
index= new Index<L2<float> >(dataset, KDTreeIndexParams(4));
@@ -205,7 +256,7 @@ class imageStore : public ofThread{
while( isThreadRunning() != 0 ){
- /*
+
cout<<"."<<std::flush;
if (!response.open(instagram_url)) {
@@ -225,29 +276,57 @@ class imageStore : public ofThread{
ofImage img;
img.setUseTexture(false);
img.loadImage(url);
+ if( lock() ){
+ instagram_image=img;
+ unlock();
+ }
img.resize(IMAGE_STORE_SIZE,IMAGE_STORE_SIZE);
img.saveImage(ofToString(IMAGE_STORE_SIZE)+"/"+id+".png");
img.resize(MAX_TILE_SIZE,MAX_TILE_SIZE);
if( lock() ){
+ newinstagram=true;
colours[id]=get_colour(img);
+ add_data(img);
images[id]=img;
+ imageptrs.push_back(&images[id]);
to_update.push_back(id);
+ //rebuild the flann index
+ float t=ofGetElapsedTimef();
+ delete index;
+ Matrix<float> dataset(&data[0],data.size()/(3*FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE),3*FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE);
+ index= new Index<L2<float> >(dataset, KDTreeIndexParams(4));
+ index->buildIndex();
+ cout<<"rebuilt flann index of "<<data.size()/(3*FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE)<<" images in "<<(ofGetElapsedTimef()-t)<<"seconds"<<endl;
unlock();
}
}
}
}
- */
+
ofSleepMillis(interval * 1000);
}
}
+ void loadtexture(ofImage& im){
+ const ofPixels& pix = im.getPixelsRef();
+ im.getTextureReference().allocate(
+ pix.getWidth()
+ ,pix.getHeight()
+ ,ofGetGlInternalFormat(pix)
+ );
+
+ im.setUseTexture(true);
+ im.update();
+ }
+
void update(){
//loads one texture
if( lock() ){
if (to_update.size()){
std::string im = to_update.front();
+ loadtexture(images[im]);
+/*
const ofPixels& pix = images[im].getPixelsRef();
images[im].getTextureReference().allocate(
pix.getWidth()
@@ -257,7 +336,7 @@ class imageStore : public ofThread{
images[im].setUseTexture(true);
images[im].update();
-
+*/
to_update.pop_front();
/*