main.cpp
Go to the documentation of this file.
00001 
00007 #include <pangolin/pangolin.h>
00008 #include <pangolin/video.h>
00009 #include <pangolin/video_record_repeat.h>
00010 #include <pangolin/input_record_repeat.h>
00011 
00012 using namespace pangolin;
00013 using namespace std;
00014 
00015 void RecordSample(const std::string uri, const std::string vid_file, const std::string ui_file)
00016 {
00017     // Setup Video Source
00018     VideoRecordRepeat video(uri, vid_file, 1024*1024*200);
00019     VideoPixelFormat vid_fmt = VideoFormatFromString(video.PixFormat());
00020     const unsigned w = video.Width();
00021     const unsigned h = video.Height();
00022 
00023     InputRecordRepeat input("ui.");
00024     input.LoadBuffer(ui_file);
00025 
00026     // Create Glut window
00027     const int panel_width = 200;
00028     pangolin::CreateGlutWindowAndBind("Main",w + panel_width,h);
00029 
00030     // Create viewport for video with fixed aspect
00031     View& d_panel = pangolin::CreatePanel("ui.")
00032         .SetBounds(0.0, 1.0, 0.0, Attach::Pix(panel_width));
00033 
00034     View& vVideo = Display("Video")
00035         .SetBounds(0.0, 1.0, Attach::Pix(panel_width), 1.0)
00036         .SetAspect((float)w/h);
00037 
00038     // OpenGl Texture for video frame
00039     GlTexture texVideo(w,h,GL_RGBA8);
00040 
00041     unsigned char* img = new unsigned char[video.SizeBytes()];
00042 
00043     static Var<bool> record("ui.Record",false,false);
00044     static Var<bool> play("ui.Play",false,false);
00045     static Var<bool> source("ui.Source",false,false);
00046     static Var<bool> realtime("ui.realtime",true,true);
00047 
00048     static Var<float> hue("ui.Hue",0,0,360);
00049     static Var<bool> colour("ui.Colour Video",false,true);
00050 
00051     while( !pangolin::ShouldQuit() )
00052     {
00053         // Load next video frame
00054         video.GrabNext(img,true);
00055         texVideo.Upload(img, vid_fmt.channels==1 ? GL_LUMINANCE:GL_RGB, GL_UNSIGNED_BYTE);
00056 
00057         // Associate input with this video frame
00058         input.SetIndex(video.FrameId());
00059 
00060         // Activate video viewport and render texture
00061         vVideo.ActivateScissorAndClear();
00062 
00063         if( colour ) {
00064             glColorHSV(hue,0.5,1.0);
00065         }else{
00066             glColor3f(1,1,1);
00067         }
00068         texVideo.RenderToViewportFlipY();
00069 
00070         if(pangolin::Pushed(record)) {
00071             video.Record();
00072             input.Record();
00073         }
00074 
00075         if(pangolin::Pushed(play)) {
00076             video.Play(realtime);
00077             input.PlayBuffer(0,input.Size()-1);
00078             input.SaveBuffer(ui_file);
00079         }
00080 
00081         if(pangolin::Pushed(source)) {
00082             video.Source();
00083             input.Stop();
00084             input.SaveBuffer(ui_file);
00085         }
00086 
00087         d_panel.Render();
00088         pangolin::FinishGlutFrame();
00089     }
00090 
00091     delete[] img;
00092 }
00093 
00094 int main( int argc, char* argv[] )
00095 {
00096     std::string uris[] = {
00097         "dc1394:[fps=30,dma=10,size=640x480,iso=400]//0",
00098         "convert:[fmt=RGB24]//v4l:///dev/video0",
00099         "convert:[fmt=RGB24]//v4l:///dev/video1",
00100         ""
00101     };
00102 
00103     std::string filename = "video.pvn";
00104 
00105     if( argc >= 2 ) {
00106         const string uri = std::string(argv[1]);
00107         if( argc == 3 ) {
00108             filename = std::string(argv[2]);
00109         }
00110         RecordSample(uri, filename, filename + ".ui");
00111     }else{
00112         cout << "Usage  : SimpleRepeatVideo [video-uri] [buffer-filename]" << endl << endl;
00113         cout << "Where video-uri describes a stream or file resource, e.g." << endl;
00114         cout << "\tfile:[realtime=1]///home/user/video/movie.pvn" << endl;
00115         cout << "\tfile:///home/user/video/movie.avi" << endl;
00116         cout << "\tfiles:///home/user/seqiemce/foo%03d.jpeg" << endl;
00117         cout << "\tdc1394:[fmt=RGB24,size=640x480,fps=30,iso=400,dma=10]//0" << endl;
00118         cout << "\tdc1394:[fmt=FORMAT7_1,size=640x480,pos=2+2,iso=400,dma=10]//0" << endl;
00119         cout << "\tv4l:///dev/video0" << endl;
00120         cout << "\tconvert:[fmt=RGB24]//v4l:///dev/video0" << endl;
00121         cout << "\tmjpeg://http://127.0.0.1/?action=stream" << endl;
00122         cout << endl;
00123 
00124         // Try to open some video device
00125         for(int i=0; !uris[i].empty(); ++i )
00126         {
00127             try{
00128                 cout << "Trying: " << uris[i] << endl;
00129                 RecordSample(uris[i], filename, filename + ".ui");
00130                 return 0;
00131             }catch(VideoException) {}
00132         }
00133     }
00134 
00135     return 0;
00136 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


pangolin_wrapper
Author(s): Todor Stoyanov
autogenerated on Wed Feb 13 2013 14:03:25