From f6b9c88ec183ee4e2387bfa6f860c893ed44b1e8 Mon Sep 17 00:00:00 2001 From: artvertiser-binoculars Date: Sat, 6 Feb 2010 13:14:38 +0100 Subject: [PATCH] - morning panick victory modified: artvertiser/FProfiler/FProfiler.h modified: artvertiser/artvertiser.cpp modified: artvertiser/calibmodel.cpp modified: artvertiser/calibmodel.h modified: artvertiser/models.xml modified: artvertiser/multigrab.cpp modified: artvertiser/multigrab.h --- artvertiser/FProfiler/FProfiler.h | 2 +- artvertiser/artvertiser.cpp | 120 ++++++++++++++++++++++++++++++-------- artvertiser/calibmodel.cpp | 9 ++- artvertiser/calibmodel.h | 2 +- artvertiser/models.xml | 100 ++++++++++++++++++++++++++++--- artvertiser/multigrab.cpp | 4 +- artvertiser/multigrab.h | 2 +- 7 files changed, 201 insertions(+), 38 deletions(-) diff --git a/artvertiser/FProfiler/FProfiler.h b/artvertiser/FProfiler/FProfiler.h index 150d26a..12fdeea 100644 --- a/artvertiser/FProfiler/FProfiler.h +++ b/artvertiser/FProfiler/FProfiler.h @@ -87,7 +87,7 @@ #define PROFILE_SECTION_POP() ; #define PROFILE_THIS_FUNCTION() ; #define PROFILE_THIS_BLOCK( label ); -#warning Profiling with FProfiler disabled +//#warning Profiling with FProfiler disabled #endif diff --git a/artvertiser/artvertiser.cpp b/artvertiser/artvertiser.cpp index 2ef27c9..e1b0b6c 100644 --- a/artvertiser/artvertiser.cpp +++ b/artvertiser/artvertiser.cpp @@ -125,6 +125,7 @@ pthread_t serial_thread; void startSerialThread(); void shutdownSerialThread(); void* serialThreadFunc( void* ); +bool running_on_binoculars = false; // we continue tracking for 1 second, then fade for 3 @@ -232,29 +233,68 @@ public: artvert_image=0; model_file="model.bmp"; artvert_image_file="artvert1.png"; + artvert_is_movie= false; artist = "unknown artist"; advert = "unknown advert"; name = "unnamed artvert"; + avi_capture = NULL; + avi_image = NULL; + avi_play_init = false; } ~Artvert() { if ( artvert_image ) cvReleaseImage( &artvert_image ); + if ( avi_capture ) + cvReleaseCapture( &avi_capture ); + if ( avi_image ) + cvReleaseImage( &avi_image ); } IplImage* getArtvertImage() { - if ( !artvert_image ) + if ( artvert_is_movie ) { - printf("loading artvert image '%s'\n", artvert_image_file.c_str() ); - artvert_image = cvLoadImage( artvert_image_file.c_str() ); + + if ( !avi_capture ) + { + avi_capture = cvCaptureFromAVI( artvert_movie_file.c_str() ); + avi_play_init = false; + } + + IplImage *avi_frame = 0; + avi_frame = cvQueryFrame( avi_capture ); + if ( avi_frame == 0 ) + return fallback_artvert_image; + if ( avi_image == 0 ) + avi_image = cvCreateImage( cvGetSize(avi_frame), avi_frame->depth, avi_frame->nChannels ); + cvCopy( avi_frame, avi_image ); + avi_image->origin = avi_frame->origin; + GLenum format = IsBGR(avi_image->channelSeq) ? GL_BGR_EXT : GL_RGBA; + + if (!avi_play_init) + { + glGenTextures(1, &imageID); + glBindTexture(GL_TEXTURE_2D, imageID); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + avi_play_init=true; + } + return avi_image; } - if ( !artvert_image ) + else { - fprintf(stderr, "couldn't load artvert image '%s'\n", artvert_image_file.c_str() ); - artvert_image = fallback_artvert_image; + if ( !artvert_image ) + { + printf("loading artvert image '%s'\n", artvert_image_file.c_str() ); + artvert_image = cvLoadImage( artvert_image_file.c_str() ); + } + if ( !artvert_image ) + { + fprintf(stderr, "couldn't load artvert image '%s'\n", artvert_image_file.c_str() ); + artvert_image = fallback_artvert_image; + } + return artvert_image; } - return artvert_image; } string model_file; @@ -262,7 +302,14 @@ public: string artist; string advert; string name; + bool artvert_is_movie; + string artvert_movie_file; private: + CvCapture* avi_capture; + IplImage* avi_image; + bool avi_play_init; + GLuint imageID; + IplImage* artvert_image; }; @@ -589,15 +636,20 @@ int serialport_read_until(int fd, char* buf, char until) { char b[1]; int i=0; + // 1000ms timeout + int timeout = 1000*1000; do { int n = read(fd, b, 1); // read a char at a time - if( n==-1) return -1; // couldn't read - if( n==0 ) { + if( n==0||n==-1 ) { + timeout -= 100; usleep( 100 ); // wait 100 usec try again continue; } buf[i] = b[0]; i++; - } while( b[0] != until ); + } while( b[0] != until && timeout > 0 ); + + if ( timeout<=0 ) + fprintf(stderr, "serialport_read_until timed out\n"); buf[i] = 0; // null terminate the string return 0; @@ -622,7 +674,7 @@ bool loadOrTrain( int new_index ) model_file != artvert_list[current_artvert_index].model_file ) { // load - bool trained = multi->loadOrTrainCache( wants_training, model_file.c_str()); + bool trained = multi->loadOrTrainCache( wants_training, model_file.c_str(), running_on_binoculars ); if ( !trained ) { // fail @@ -713,6 +765,11 @@ static bool init( int argc, char** argv ) printf(" -m: adding model image '%s'\n", argv[i+1] ); i++; } + else if ( strcmp(argv[i], "-binoc" ) == 0 ) + { + running_on_binoculars = true; +printf(" -binoc: running on binoculars\n"); + } else if ( strcmp(argv[i], "-ml" )== 0 ) { if ( i==argc-1) @@ -833,9 +890,20 @@ static bool init( int argc, char** argv ) data.pushTag("artvert", j ); a.name = data.getValue( "name", "unnamed" ); a.artist = data.getValue( "artist", "unknown artist" ); - a.artvert_image_file = data.getValue( "image_filename", "artvert1.png" ); + if ( data.getNumTags("movie_filename") != 0 ) + { + // load a movie + a.artvert_is_movie = true; + a.artvert_movie_file = data.getValue("movie_filename", "artvertmovie1.mp4" ); + } + else + { + // load an image + a.artvert_image_file = data.getValue( "image_filename", "artvert1.png" ); + } printf(" %i: %s:%s:%s\n", j, a.name.c_str(), a.artist.c_str(), - a.artvert_image_file.c_str() ); + a.artvert_is_movie?(a.artvert_movie_file+"( movie)").c_str() : a.artvert_image_file.c_str() ); + artvert_list.push_back( a ); data.popTag(); } @@ -1123,14 +1191,12 @@ int main(int argc, char *argv[]) glutDisplayFunc(emptyWindow); - glutReshapeFunc(reshape); + //glutReshapeFunc(reshape); //glutCreateWindow("The Artvertiser 0.4"); glutMouseFunc(mouse); glutEntryFunc(entry); - /* use this to explicitly set the window size for glut Game Mode glutGameModeString("1024x768:16@60"); - */ glutEnterGameMode(); glutSetCursor(GLUT_CURSOR_NONE); @@ -1888,6 +1954,7 @@ void* serialThreadFunc( void* data ) char serialport[256]; int baudrate = B9600; // default char buf[256]; + char buf2[256]; int rc,n; fd = serialport_init( "/dev/ttyUSB0", 9600 ); @@ -1896,7 +1963,7 @@ void* serialThreadFunc( void* data ) while ( !serial_thread_should_exit ) { int read = serialport_read_until(fd, buf, '\n'); - // printf("read: %s\n",buf); + //printf("read: %s then %s\n",buf2, buf); if ( (read==0) && strlen( buf ) >= 4 /*includes final \n*/ ) { bool button_red = (buf[0]=='1'); @@ -1911,6 +1978,8 @@ void* serialThreadFunc( void* data ) // deal with debounce if ( new_button_state != button_state ) { + printf( "serialport read %s -> 0x%x (old was 0x%x)\n", + buf, new_button_state, button_state ); button_state_changed = true; button_state = new_button_state; } @@ -2137,7 +2206,8 @@ void updateMenu() if ( !button_state_changed ) return; - printf("new button state: %s %s %s\n", button_state&BUTTON_RED?"red":" ", + printf("menu sees new button state: %s %s %s\n", + button_state&BUTTON_RED?"red":" ", button_state&BUTTON_GREEN?"green":" ", button_state&BUTTON_BLUE?"blue":" "); @@ -2159,14 +2229,14 @@ void updateMenu() return; // navigation - if( button_state == BUTTON_RED ) + if( button_state == BUTTON_BLUE ) { menu_index++; if ( menu_index >= artvert_list.size() ) menu_index = 0; menu_timer.SetNow(); } - if ( button_state == BUTTON_BLUE ) + if ( button_state == BUTTON_RED ) { menu_index--; if ( menu_index < 0 ) @@ -2205,7 +2275,7 @@ void drawMenu() glTranslatef(-.8, 0.65, 0.0); glScalef(.003, .003, .003); ftglFont->FaceSize(24); - glColor4f(1.0, 1.0, 1.0, 1); + glColor4f(0.0, 1.0, 0.0, 1); ftglFont->Render("changing artvert..."); @@ -2222,10 +2292,10 @@ void drawMenu() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_BLEND); - glTranslatef(-.8, 0.65, 0.0); + glTranslatef(-.85, 0.65, 0.0); glScalef(.003, .003, .003); ftglFont->FaceSize(24); - glColor4f(1.0, 1.0, 1.0, 1); + glColor4f(.25, 1.0, 0.0, 1); ftglFont->Render("Select artvert:"); glTranslatef( 0, -26, 0 ); @@ -2239,11 +2309,11 @@ void drawMenu() if ( i == menu_index ) { - glColor4f( 1,1,1,1 ); + glColor4f( 1,0.37,0,1 ); } else { - glColor4f( 0.5f, 0.5f, 0.5f, 1 ); + glColor4f( .25f, 1.f, 0.0f, 1 ); } ftglFont->Render(line.c_str()); glTranslatef(0, -26, 0 ); diff --git a/artvertiser/calibmodel.cpp b/artvertiser/calibmodel.cpp index e36af50..07a2402 100644 --- a/artvertiser/calibmodel.cpp +++ b/artvertiser/calibmodel.cpp @@ -55,7 +55,7 @@ void CalibModel::onMouse(int event, int x, int y, int flags) } } -bool CalibModel::buildCached(int nbcam, CvCapture *capture, bool cache, planar_object_recognizer &detector) +bool CalibModel::buildCached(int nbcam, CvCapture *capture, bool cache, planar_object_recognizer &detector, bool dont_try_to_train ) { detector.clear(); @@ -156,6 +156,13 @@ bool CalibModel::buildCached(int nbcam, CvCapture *capture, bool cache, planar_o cvReleaseImage( &image ); image =0; // ask the user the take a shot of the model + if ( !cache && dont_try_to_train ) + { + printf("CalibModel: would normally try to train now but we were told not to\n"); + detector.clear(); + detector.unlock(); + return false; + } if (!interactiveSetup(capture)) { printf("interactiveSetup failed\n"); diff --git a/artvertiser/calibmodel.h b/artvertiser/calibmodel.h index 7528562..a238084 100644 --- a/artvertiser/calibmodel.h +++ b/artvertiser/calibmodel.h @@ -18,7 +18,7 @@ public: void useModelFile( const char *modelfile ); - bool buildCached(int nbcam, CvCapture *capture, bool cache, planar_object_recognizer &detector); + bool buildCached(int nbcam, CvCapture *capture, bool cache, planar_object_recognizer &detector, bool dont_try_to_train ); int getImageWidth() { return image_width; } int getImageHeight() { return image_height; } diff --git a/artvertiser/models.xml b/artvertiser/models.xml index 216da35..2c03609 100644 --- a/artvertiser/models.xml +++ b/artvertiser/models.xml @@ -19,7 +19,7 @@ --> - models/posters4.bmp + models/posters1.bmp kunst beer your art here @@ -27,15 +27,101 @@ us - spider + USB Bomb + artverts/usb_bomb.png + us + + + + models/posters4.bmp + Sport Hilfe + + Paradise Berlin + artverts/posters4.png + us + + + + models/posters7.bmp + Rathaus Passagen + + Rathaus Passagen artverts/spider.png - julian + us + + + + + models/posters8.bmp + Motor Welt + + You're not here + artverts/mountains.jpg + us + + + + models/posters9.bmp + 94.3 RS2 + + obey + artverts/obey.png + obey + + + models/ships.bmp + Sparkasse + + A Tradition of The Best Advice + artverts/advice_flat.mp4 + Jason Reizner + + + + models/posters11.bmp + Pixar + + Enlightenment + artverts/Enlightenment.jpg + Bjorn Erik Haugen + + + + models/posters12.bmp + Avene/Apotheke + + Temple of Health + artverts/01_The_temple_of_health.jpg + Ivana Kohlhammer + + + Untitled + artverts/woman_art_Torres.jpg + Gerardo Torres + + + + models/posters13.bmp + La Roche + + Hair Helmuts are Super Cool + artverts/laroche-ad-hairJustinYoung1500x980.jpg + Justin Young + + + Untitled + artverts/laroche-ad-pattern-JustinYoung850x555.jpg + Justin Young + + + + models/posters15.bmp + Ulla - moviething - artverts/moviething.mp4 - 1 - damian + Publicity Against Consumption + artverts/publicity_against_consumption.mov + Animazon