summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2014-03-14 00:51:24 +0000
committerComment <tim@gray.(none)>2014-03-14 00:51:24 +0000
commitbb852cee91b52b71fccade7d4a1ef065eb0de2f0 (patch)
tree97ded3b49faa5d444fa5e9e6c9e58a04d8440afc
parent8072eb4d248debf2d049548dd5dec21cc0152c52 (diff)
nice
-rw-r--r--offsetProject/config.make4
-rw-r--r--offsetProject/src/imageStore.h10
-rw-r--r--offsetProject/src/ofApp.cpp164
-rw-r--r--offsetProject/src/ofApp.h4
-rw-r--r--test-tycbutton/Makefile13
-rw-r--r--test-tycbutton/addons.make1
-rw-r--r--test-tycbutton/config.make1
-rw-r--r--test-tycbutton/src/buttonChecker.cpp8
-rw-r--r--test-tycbutton/src/buttonChecker.h72
-rw-r--r--test-tycbutton/src/main.cpp16
-rw-r--r--test-tycbutton/src/testApp.cpp57
-rw-r--r--test-tycbutton/src/testApp.h26
12 files changed, 299 insertions, 77 deletions
diff --git a/offsetProject/config.make b/offsetProject/config.make
index 6edaada..5729780 100644
--- a/offsetProject/config.make
+++ b/offsetProject/config.make
@@ -78,7 +78,7 @@
################################################################################
# PROJECT_LDFLAGS=-Wl,-rpath=./libs
-PROJECT_LDFLAGS= -ljsoncpp -lflann
+PROJECT_LDFLAGS= -ljsoncpp
################################################################################
# PROJECT DEFINES
@@ -106,7 +106,7 @@ PROJECT_LDFLAGS= -ljsoncpp -lflann
#
# Note: Leave a leading space when adding list items with the += operator
################################################################################
- PROJECT_CFLAGS = `pkg-config --cflags jsoncpp`
+ PROJECT_CFLAGS = `pkg-config --cflags jsoncpp` -pg
################################################################################
diff --git a/offsetProject/src/imageStore.h b/offsetProject/src/imageStore.h
index a2bd39d..9cde96c 100644
--- a/offsetProject/src/imageStore.h
+++ b/offsetProject/src/imageStore.h
@@ -3,15 +3,17 @@
#define IMAGE_STORE_SIZE 256
#define MIN_TILE_SIZE 8
-#define MAX_TILE_SIZE 16
+#define MAX_TILE_SIZE 32
-#define FLANN_MATRIX_SIZE 3
+#define FLANN_MATRIX_SIZE 5
#include "ofMain.h"
#include "ofxJSONElement.h"
#include "ofxOpenCv.h"
//#include <opencv/include/opencv2/flann/flann.hpp>
+//~9fps@33% 32*3
+
using namespace cvflann;
long ofToLong(const string& intString);
@@ -115,7 +117,7 @@ class imageStore : public ofThread{
Matrix<float> query(test,1,3);
Matrix<int> indices(new int[1], query.rows, 1);
Matrix<float> dists(new float[1], query.rows, 1);
- index->knnSearch(query, indices, dists, 1,SearchParams(10));
+ index->knnSearch(query, indices, dists, 1,SearchParams(20));
im=*imageptrs[*indices[0]];
//int i=rand()%imageptrs.size();
//im=images[imageptrs[i]];
@@ -159,6 +161,8 @@ class imageStore : public ofThread{
}
}
+ //void flann(const ofImage& _img){
+
//--------------------------
void threadedFunction(){
diff --git a/offsetProject/src/ofApp.cpp b/offsetProject/src/ofApp.cpp
index 51795f5..c5163f9 100644
--- a/offsetProject/src/ofApp.cpp
+++ b/offsetProject/src/ofApp.cpp
@@ -5,27 +5,9 @@ so far so good, NOW
threading
-parse response and identify new pictures
-save pictures & metadata - rather than reloading each time?
-local images format
-do we need any metadata? I guess not other than to know the tag id
-could save with the tag id as the name of file, simpler
-
-how exactly do we parse or mipmap the images
-do we worry about memory - I guess not
-
-identify the images
-
-image save- reload system (? even necessary ?)
camera + button
transitions
-should the loader own the images?
-should the whole image bank be locked while loading?
-alternatively each image could have a lock? - threadedImage
-
-or true mip map via drawsubsection?
-
start with a max size say 64 - should be 16k inc mip maps
graphics card has 2048MB
@@ -33,38 +15,29 @@ graphics card has 2048MB
117964 textures
I wonder is this faster with shared memory..
-load app
-get list of images in defined folder
-load them and create mip maps
-store indexed by file stub
-
-start thread
-when a new image comes in
-load and create mip maps
-
-how to store pictures
-threaded loader works away in the background
-when a new picture comes in
+performance?
-a data structure which is part of the threaded object
-each image contains a mutex to enable the threaded object to be accessed
-the instagram id is just used to match against incoming - there needs to be the pattern matching algorithm
-
-how to draw pictures
-need to search the db for pictures of a certain colour
+use opencv to convert to floats? its a quick one..
*/
//--------------------------------------------------------------
void ofApp::setup() {
ofSetLogLevel(OF_LOG_WARNING);
-
+
ofSetFrameRate(60);
- kinect.setRegistration(true);
+ kinect.setRegistration(true);
kinect.init();
kinect.open();
- colourImage.allocate(kinect.width, kinect.height);
- depthImage.allocate(kinect.width, kinect.height);
+ //colourImage.allocate(kinect.width, kinect.height);
+ //depthImage.allocate(kinect.width, kinect.height);
+ //floatImage.setNativeScale(0.0f,255.0f);
+ int h=ceil(ofGetHeight()/MAX_TILE_SIZE);
+ //int w=(h*4)/3;
+ //floatImage.allocate(w*FLANN_MATRIX_SIZE,h*FLANN_MATRIX_SIZE);
+ floatImage=new float[h*FLANN_MATRIX_SIZE*h*FLANN_MATRIX_SIZE*3];
+ //cerr<<"floatImage: "<<h<<"*"<<FLANN_MATRIX_SIZE<<"*"<<h<<"*"<<FLANN_MATRIX_SIZE<<"*3"<<endl;
+
farThreshold = 70;
angle = 0;
kinect.setCameraTiltAngle(angle);
@@ -72,27 +45,28 @@ void ofApp::setup() {
kinect.setDepthClipping(0,4000);
store.start();
-
+
mode=MODE_COLOURTILES;
fullscreen=false;
tiledata=new float[FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE*3];
+ frametiledata=new float[FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE*3*h*h];
}
//--------------------------------------------------------------
void ofApp::update() {
-
+
ofSetWindowTitle(ofToString(ofGetFrameRate()));
-
+
kinect.update();
-
+
// there is a new frame and we are connected
if(kinect.isFrameNew()) {
-
+
depthImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
colourImage.setFromPixels(kinect.getPixels(), kinect.width, kinect.height);
-
+
depthImage.threshold(farThreshold);
//threshold needs to be multiplied by the original
@@ -105,11 +79,49 @@ void ofApp::update() {
int h=ceil(ofGetHeight()/MAX_TILE_SIZE);
int w=(h*4)/3;
depthImage.resize(w,h);
- colourImage.resize(w*FLANN_MATRIX_SIZE,h*FLANN_MATRIX_SIZE);
+
+ int fh=h*FLANN_MATRIX_SIZE;
+ int fw=w*FLANN_MATRIX_SIZE;
+ colourImage.resize(fw,fh);
+
+ //cerr<<"needed: "<<h<<"*"<<FLANN_MATRIX_SIZE<<"*"<<h<<"*"<<FLANN_MATRIX_SIZE<<"*3"<<endl;
+
+
+ int kinexstart=(colourImage.getWidth()/2)+(colourImage.getHeight()/2);
+ uint8_t* cptr=colourImage.getPixels();
+ for (int i=0;i<fh;i++){
+ for (int j=0;j<fh;j++){
+ floatImage[(i*fh+j)*3]=cptr[(((i*fw)+kinexstart)-j)*3];
+ floatImage[(i*fh+j)*3+1]=cptr[(((i*fw)+kinexstart)-j)*3+1];
+ floatImage[(i*fh+j)*3+2]=cptr[(((i*fw)+kinexstart)-j)*3+2];
+ }
+ }
+/*
+ store.flann(cptr,w,h);
+
+ int tilestep=(FLANN_MATRIX_SIZE*FLANN_MATRIX_SIZE*3);
+ for (int i=0;i<h;i++){
+ for (int j=0;j<w;j++){
+ for (int k=0;k<FLANN_MATRIX_SIZE;k++){
+ for (int l=0;l<FLANN_MATRIX_SIZE;l++){
+ frametiledata[((k*FLANN_MATRIX_SIZE+l)*3)+(tilestep*(j*w+i))]=cptr[((i*FLANN_MATRIX_SIZE+k)*fw+kinexstart)-(j*FLANN_MATRIX_SIZE+l))*3];
+ frametiledata[((k*FLANN_MATRIX_SIZE+l)*3)+(tilestep*(j*w+i))]=cptr[((i*FLANN_MATRIX_SIZE+k)*fw+kinexstart)-(j*FLANN_MATRIX_SIZE+l))*3];
+ frametiledata[((k*FLANN_MATRIX_SIZE+l)*3)+(tilestep*(j*w+i))]=cptr[((i*FLANN_MATRIX_SIZE+k)*fw+kinexstart)-(j*FLANN_MATRIX_SIZE+l))*3];
+ }
+ }
+ }
+ }
+*/
+
+ //floatImage.allocate(w*FLANN_MATRIX_SIZE,h*FLANN_MATRIX_SIZE);
+ //floatImage=colourImage;
+ //floatImage.scaleIntoMe(colourImage);
+
// mark pixels and texture dirty
depthImage.flagImageChanged();
- colourImage.flagImageChanged();
+ //colourImage.flagImageChanged();
+ //floatImage.flagImageChanged();
/*
ofxCvColorImage *prevCol=&colourImage;
@@ -129,8 +141,8 @@ void ofApp::update() {
}
store.update();
-
-
+
+
}
@@ -142,7 +154,7 @@ void ofApp::draw() {
ofSetColor(255, 255, 255);
- int w,xstart,ystart,kinexstart;
+ int fw,w,xstart,ystart,kinexstart;
switch(mode){
case MODE_COLOURTILES:
@@ -153,18 +165,25 @@ void ofApp::draw() {
ofPushMatrix();
ofTranslate(xstart,ystart);
w=colourImage.getWidth();
+ fw=colourImage.getHeight();
for (int i=0;i<depthImage.getHeight();i++){
for (int j=0;j<depthImage.getHeight();j++){
//uint8_t* ppt=&colourImage.getPixels()[((j*FLANN_MATRIX_SIZE)*w+(w-((i*FLANN_MATRIX_SIZE)+kinexstart)))*3];
-
+
for (int k=0;k<FLANN_MATRIX_SIZE;k++){
for (int l=0;l<FLANN_MATRIX_SIZE;l++){
- tiledata[(l*FLANN_MATRIX_SIZE+k)*3]=colourImage.getPixels()[((j*FLANN_MATRIX_SIZE+l)*w+(w-((i*FLANN_MATRIX_SIZE+k)+kinexstart)))*3];
- tiledata[(l*FLANN_MATRIX_SIZE+k)*3+1]=colourImage.getPixels()[((j*FLANN_MATRIX_SIZE+l)*w+(w-((i*FLANN_MATRIX_SIZE+k)+kinexstart)))*3+1];
- tiledata[(l*FLANN_MATRIX_SIZE+k)*3+2]=colourImage.getPixels()[((j*FLANN_MATRIX_SIZE+l)*w+(w-((i*FLANN_MATRIX_SIZE+k)+kinexstart)))*3+2];
+
+ //tiledata[(l*FLANN_MATRIX_SIZE+k)*3]=colourImage.getPixels()[((j*FLANN_MATRIX_SIZE+l)*w+(w-((i*FLANN_MATRIX_SIZE+k)+kinexstart)))*3];
+ //tiledata[(l*FLANN_MATRIX_SIZE+k)*3+1]=colourImage.getPixels()[((j*FLANN_MATRIX_SIZE+l)*w+(w-((i*FLANN_MATRIX_SIZE+k)+kinexstart)))*3+1];
+ //tiledata[(l*FLANN_MATRIX_SIZE+k)*3+2]=colourImage.getPixels()[((j*FLANN_MATRIX_SIZE+l)*w+(w-((i*FLANN_MATRIX_SIZE+k)+kinexstart)))*3+2];
+
+ tiledata[(l*FLANN_MATRIX_SIZE+k)*3]=floatImage[(((j*FLANN_MATRIX_SIZE+l)*fw)+(i*FLANN_MATRIX_SIZE)+k)*3];
+ tiledata[(l*FLANN_MATRIX_SIZE+k)*3+1]=floatImage[(((j*FLANN_MATRIX_SIZE+l)*fw)+(i*FLANN_MATRIX_SIZE)+k)*3+1];
+ tiledata[(l*FLANN_MATRIX_SIZE+k)*3+2]=floatImage[(((j*FLANN_MATRIX_SIZE+l)*fw)+(i*FLANN_MATRIX_SIZE)+k)*3+2];
+
}
}
-
+
//ofImage& im=store.get_image(ofColor(ppt[0],ppt[1],ppt[2]));
//ofSetColor(ppt[0],ppt[1],ppt[2]);
//ofRect(i*MAX_TILE_SIZE,j*MAX_TILE_SIZE,MAX_TILE_SIZE,MAX_TILE_SIZE);
@@ -188,7 +207,7 @@ void ofApp::draw() {
//colourImage.draw(640,0, 640,480);
break;
}
-
+
}
@@ -196,6 +215,7 @@ void ofApp::draw() {
//--------------------------------------------------------------
void ofApp::exit() {
delete tiledata;
+ delete floatImage;
kinect.setCameraTiltAngle(0); // zero the tilt on exit
kinect.close();
}
@@ -203,70 +223,70 @@ void ofApp::exit() {
//--------------------------------------------------------------
void ofApp::keyPressed (int key) {
switch (key) {
-
+
case '>':
case '.':
farThreshold ++;
if (farThreshold > 255) farThreshold = 255;
break;
-
+
case '<':
case ',':
farThreshold --;
if (farThreshold < 0) farThreshold = 0;
break;
-
-
+
+
case 'w':
kinect.enableDepthNearValueWhite(!kinect.isDepthNearValueWhite());
break;
-
+
case 'o':
kinect.setCameraTiltAngle(angle); // go back to prev tilt
kinect.open();
break;
-
+
case 'c':
kinect.setCameraTiltAngle(0); // zero the tilt
kinect.close();
break;
-
+
case '1':
kinect.setLed(ofxKinect::LED_GREEN);
break;
-
+
case '2':
kinect.setLed(ofxKinect::LED_YELLOW);
break;
-
+
case '3':
kinect.setLed(ofxKinect::LED_RED);
break;
-
+
case '4':
kinect.setLed(ofxKinect::LED_BLINK_GREEN);
break;
-
+
case '5':
kinect.setLed(ofxKinect::LED_BLINK_YELLOW_RED);
break;
-
+
case '0':
kinect.setLed(ofxKinect::LED_OFF);
break;
-
+
case OF_KEY_UP:
angle++;
if(angle>30) angle=30;
kinect.setCameraTiltAngle(angle);
break;
-
+
case OF_KEY_DOWN:
angle--;
if(angle<-30) angle=-30;
kinect.setCameraTiltAngle(angle);
break;
-
+
case OF_KEY_LEFT:
mode--;
if (mode<0) mode=NUM_MODES-1;
diff --git a/offsetProject/src/ofApp.h b/offsetProject/src/ofApp.h
index f3aa3be..e31c5b1 100644
--- a/offsetProject/src/ofApp.h
+++ b/offsetProject/src/ofApp.h
@@ -37,7 +37,11 @@ public:
ofxCvGrayscaleImage depthImage,depthImage2;
ofxKinect kinect;
+ //ofxCvFloatImage floatImage;
+ float* floatImage;
+
float* tiledata;
+ float* frametiledata;
bool fullscreen;
};
diff --git a/test-tycbutton/Makefile b/test-tycbutton/Makefile
new file mode 100644
index 0000000..7a7fe8b
--- /dev/null
+++ b/test-tycbutton/Makefile
@@ -0,0 +1,13 @@
+# Attempt to load a config.make file.
+# If none is found, project defaults in config.project.make will be used.
+ifneq ($(wildcard config.make),)
+ include config.make
+endif
+
+# make sure the the OF_ROOT location is defined
+ifndef OF_ROOT
+ OF_ROOT=../../..
+endif
+
+# call the project makefile!
+include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
diff --git a/test-tycbutton/addons.make b/test-tycbutton/addons.make
new file mode 100644
index 0000000..c42773e
--- /dev/null
+++ b/test-tycbutton/addons.make
@@ -0,0 +1 @@
+ofxHttpUtils
diff --git a/test-tycbutton/config.make b/test-tycbutton/config.make
new file mode 100644
index 0000000..98bb09c
--- /dev/null
+++ b/test-tycbutton/config.make
@@ -0,0 +1 @@
+OF_ROOT=../../openFrameworks
diff --git a/test-tycbutton/src/buttonChecker.cpp b/test-tycbutton/src/buttonChecker.cpp
new file mode 100644
index 0000000..b8170e8
--- /dev/null
+++ b/test-tycbutton/src/buttonChecker.cpp
@@ -0,0 +1,8 @@
+#include "buttonChecker.h"
+
+long ofToLong(const string& intString) {
+ long x = 0;
+ istringstream cur(intString);
+ cur >> x;
+ return x;
+} \ No newline at end of file
diff --git a/test-tycbutton/src/buttonChecker.h b/test-tycbutton/src/buttonChecker.h
new file mode 100644
index 0000000..2de14cb
--- /dev/null
+++ b/test-tycbutton/src/buttonChecker.h
@@ -0,0 +1,72 @@
+#ifndef _BUTTON_CHECK
+#define _BUTTON_CHECK
+
+#include "ofMain.h"
+#include "ofURLFileLoader.h"
+
+long ofToLong(const string& intString);
+
+class buttonChecker : public ofThread{
+
+ public:
+
+ float interval; //time between refreshes in seconds
+ std::string url;
+ long last;
+ float triggerTime;
+ bool active;
+
+ buttonChecker(){
+ url = "http://tycleeson.com/trigger.php";
+ interval=0.05;
+ last=0;
+ triggerTime=0.0f;
+ active=false;
+ }
+
+ void set_interval(float _interval){
+ interval=_interval;
+ }
+
+ void start(){
+ startThread(true, false); // blocking, verbose
+ }
+
+ void stop(){
+ stopThread();
+ }
+
+ bool action(){
+ if(active){
+ active=false;
+ return true;
+ }
+ return false;
+ }
+
+
+ //--------------------------
+ void threadedFunction(){
+
+ cout << "Api: " << url<<endl;
+
+ while( isThreadRunning() != 0 ){
+
+ //cout<<"."<<std::flush;
+
+ long result = ofToLong(ofLoadURL(url).data.getText());
+ if (result>last){
+ last=result;
+ active=true;
+ triggerTime=ofGetElapsedTimef();
+ }
+
+
+ ofSleepMillis(interval * 1000);
+ }
+ }
+
+
+};
+
+#endif \ No newline at end of file
diff --git a/test-tycbutton/src/main.cpp b/test-tycbutton/src/main.cpp
new file mode 100644
index 0000000..6a32c6a
--- /dev/null
+++ b/test-tycbutton/src/main.cpp
@@ -0,0 +1,16 @@
+#include "ofMain.h"
+#include "testApp.h"
+#include "ofAppGlutWindow.h"
+
+//========================================================================
+int main( ){
+
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ // pass in width and height too:
+ ofRunApp( new testApp());
+
+}
diff --git a/test-tycbutton/src/testApp.cpp b/test-tycbutton/src/testApp.cpp
new file mode 100644
index 0000000..422b728
--- /dev/null
+++ b/test-tycbutton/src/testApp.cpp
@@ -0,0 +1,57 @@
+#include "testApp.h"
+
+//--------------------------------------------------------------
+void testApp::setup(){
+ ofSetVerticalSync(true);
+
+ ofBackground(0,0,0);
+ ofSetColor(255,255,255);
+
+ button.start();
+}
+
+//--------------------------------------------------------------
+void testApp::update(){
+ if (button.action()) cout<<"SNAP!"<<endl;
+}
+
+//--------------------------------------------------------------
+void testApp::draw(){
+ //ofDrawBitmapString(requestStr,20,20);
+ //ofDrawBitmapString(responseStr,20,60);
+ float ttime=ofGetElapsedTimef()-button.triggerTime;
+
+ int b=(1.0f-ttime)*255;
+
+ if (b>-1) ofBackground(b,b,b);
+}
+
+//--------------------------------------------------------------
+
+//--------------------------------------------------------------
+void testApp::keyPressed (int key){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void testApp::mousePressed(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::windowResized(int w, int h){
+
+}
+
diff --git a/test-tycbutton/src/testApp.h b/test-tycbutton/src/testApp.h
new file mode 100644
index 0000000..de233d5
--- /dev/null
+++ b/test-tycbutton/src/testApp.h
@@ -0,0 +1,26 @@
+#ifndef _TEST_APP
+#define _TEST_APP
+
+#include "ofMain.h"
+#include "buttonChecker.h"
+
+class testApp : public ofBaseApp{
+
+ public:
+
+ void setup();
+ void update();
+ void draw();
+
+ void keyPressed (int key);
+ void mouseMoved(int x, int y );
+ void mouseDragged(int x, int y, int button);
+ void mousePressed(int x, int y, int button);
+ void mouseReleased(int x, int y, int button);
+ void windowResized(int w, int h);
+
+ buttonChecker button;
+
+};
+
+#endif