main.cpp
Go to the documentation of this file.
00001 
00007 #include <pangolin/pangolin.h>
00008 #include <pangolin/video.h>
00009 
00010 using namespace pangolin;
00011 using namespace std;
00012 
00013 void VideoSample(const std::string uri)
00014 {
00015     // Setup Video Source
00016     VideoInput video(uri);
00017     VideoPixelFormat vid_fmt = VideoFormatFromString(video.PixFormat());
00018     const unsigned w = video.Width();
00019     const unsigned h = video.Height();
00020 
00021     // Create Glut window
00022     pangolin::CreateGlutWindowAndBind("Main",w,h);
00023 
00024     // Create viewport for video with fixed aspect
00025     View& vVideo = Display("Video").SetAspect((float)w/h);
00026 
00027     // OpenGl Texture for video frame
00028     GlTexture texVideo(w,h,GL_RGBA8);
00029 
00030     unsigned char* img = new unsigned char[video.SizeBytes()];
00031 
00032     for(int frame=0; !pangolin::ShouldQuit(); ++frame)
00033     {
00034         glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
00035 
00036         video.GrabNext(img,true);
00037         texVideo.Upload(img, vid_fmt.channels==1 ? GL_LUMINANCE:GL_RGB, GL_UNSIGNED_BYTE);
00038 
00039         // Activate video viewport and render texture
00040         vVideo.Activate();
00041         texVideo.RenderToViewportFlipY();
00042 
00043         // Swap back buffer with front and process window events via GLUT
00044         pangolin::FinishGlutFrame();
00045     }
00046 
00047     delete[] img;
00048 }
00049 
00050 
00051 int main( int argc, char* argv[] )
00052 {
00053     std::string uris[] = {
00054         "dc1394:[fps=30,dma=10,size=640x480,iso=400]//0",
00055         "convert:[fmt=RGB24]//v4l:///dev/video0",
00056         "convert:[fmt=RGB24]//v4l:///dev/video1",
00057         ""
00058     };
00059 
00060     if( argc > 1 ) {
00061         const string uri = std::string(argv[1]);
00062         VideoSample(uri);
00063     }else{
00064         cout << "Usage  : SimpleRecord [video-uri]" << endl << endl;
00065         cout << "Where video-uri describes a stream or file resource, e.g." << endl;
00066         cout << "\tfile:[realtime=1]///home/user/video/movie.pvn" << endl;
00067         cout << "\tfile:///home/user/video/movie.avi" << endl;
00068         cout << "\tfiles:///home/user/seqiemce/foo%03d.jpeg" << endl;
00069         cout << "\tdc1394:[fmt=RGB24,size=640x480,fps=30,iso=400,dma=10]//0" << endl;
00070         cout << "\tdc1394:[fmt=FORMAT7_1,size=640x480,pos=2+2,iso=400,dma=10]//0" << endl;
00071         cout << "\tv4l:///dev/video0" << endl;
00072         cout << "\tconvert:[fmt=RGB24]//v4l:///dev/video0" << endl;
00073         cout << "\tmjpeg://http://127.0.0.1/?action=stream" << endl;
00074         cout << endl;
00075 
00076         // Try to open some video device
00077         for(int i=0; !uris[i].empty(); ++i )
00078         {
00079             try{
00080                 cout << "Trying: " << uris[i] << endl;
00081                 VideoSample(uris[i]);
00082                 return 0;
00083             }catch(VideoException) {}
00084         }
00085     }
00086 
00087     return 0;
00088 }
 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