complex.cpp
Go to the documentation of this file.
00001 //command line parameters
00002 #include "cmd_line/cmd_line.h"
00003 
00004 //detectors
00005 #include "detectors/datamatrix/detector.h"
00006 #include "detectors/qrcode/detector.h"
00007 
00008 //tracking
00009 #include "libauto_tracker/tracking.h"
00010 #include "libauto_tracker/threading.h"
00011 #include "libauto_tracker/events.h"
00012 
00013 //visp includes
00014 #include <visp/vpImageIo.h>
00015 #include <visp/vpVideoReader.h>
00016 #include <visp/vpVideoWriter.h>
00017 #include <visp/vpV4l2Grabber.h>
00018 #include <visp/vpMbEdgeKltTracker.h>
00019 #include <visp/vpMbKltTracker.h>
00020 #include <visp/vpMbEdgeTracker.h>
00021 #include <visp/vpDisplayX.h>
00022 
00023 int main(int argc, char**argv)
00024 {
00025   //Parse command line arguments
00026   CmdLine cmd(argc,argv);
00027 
00028   if(cmd.should_exit()) return 0; //exit if needed
00029 
00030   //Read video from a set of images, a single image or a camera
00031   vpImage<vpRGBa> I;
00032   vpVideoReader reader;
00033   vpV4l2Grabber video_reader;
00034   vpVideoWriter writer;
00035   vpImage<vpRGBa> logI;
00036   vpMbTracker* tracker;
00037 
00038   vpCameraParameters cam = cmd.get_cam_calib_params();
00039   if(cmd.get_verbose())
00040     std::cout << "loaded camera parameters:" << cam << std::endl;
00041 
00042 
00043   if(cmd.logging_video()){
00044     writer.setFileName((cmd.get_data_dir() + cmd.get_log_file_pattern()).c_str());
00045     writer.open(logI);
00046   }
00047 
00048   if(cmd.using_single_image()){
00049     if(cmd.get_verbose())
00050       std::cout << "Loading: " << cmd.get_single_image_path() << std::endl;
00051     vpImageIo::read(I,cmd.get_single_image_path());
00052   }else if(cmd.using_video_camera()){
00053     video_reader.setDevice(cmd.get_video_channel().c_str());
00054     video_reader.setInput(0);
00055     video_reader.setScale(1);
00056     video_reader.setFramerate(vpV4l2Grabber::framerate_25fps); //  25 fps
00057     video_reader.setPixelFormat(vpV4l2Grabber::V4L2_YUYV_FORMAT);
00058     video_reader.setWidth(640);
00059     video_reader.setHeight(480);
00060     video_reader.setNBuffers(3); // 3 ring buffers to ensure real-time acquisition
00061     video_reader.open(I);        // Open the grabber
00062   }else{
00063     std::string filenames((cmd.get_data_dir() + cmd.get_input_file_pattern()));
00064     if(cmd.get_verbose())
00065       std::cout << "Loading: " << filenames << std::endl;
00066     reader.setFileName( filenames.c_str() );
00067 
00068     reader.setFirstFrameIndex(2);
00069     reader.open(I);
00070   }
00071 
00072   //init display
00073   vpDisplayX* d = new vpDisplayX();
00074   d->init(I);
00075   //init hybrid tracker
00076   detectors::DetectorBase* detector = NULL;
00077   if (cmd.get_detector_type() == CmdLine::ZBAR)
00078     detector = new detectors::qrcode::Detector;
00079   else if(cmd.get_detector_type() == CmdLine::DTMX)
00080     detector = new detectors::datamatrix::Detector;
00081 
00082   if(cmd.get_tracker_type() == CmdLine::KLT)
00083     tracker = new vpMbKltTracker();
00084   else if(cmd.get_tracker_type() == CmdLine::KLT_MBT)
00085     tracker = new vpMbEdgeKltTracker();
00086   else if(cmd.get_tracker_type() == CmdLine::MBT)
00087     tracker = new vpMbEdgeTracker();
00088 
00089   tracking::Tracker t(cmd,detector,tracker);
00090   TrackerThread tt(t);
00091   boost::thread bt(tt);
00092 
00093 
00094   //when we're using a camera, we can have a meaningless video feed
00095   //until the user selects the first meaningful image
00096   //The first meaningful frame is selected with a click
00097   //In other cases, the first meaningful frame is selected by sending
00098   //the tracking::select_input event
00099   if(!cmd.using_video_camera())
00100     t.process_event(tracking::select_input(I));
00101 
00102 
00103   for(int iter=0;
00104       cmd.using_video_camera() ||
00105       cmd.using_single_image() ||
00106       (iter<reader.getLastFrameIndex()-1);
00107       iter++
00108       ){
00109     if(cmd.using_video_camera()){
00110       video_reader.acquire(I);
00111       vpDisplay::display(I);
00112       vpDisplay::flush(I);
00113     }
00114     else if(!cmd.using_single_image())
00115       reader.acquire(I);
00116     t.process_event(tracking::input_ready(I,cam,iter));
00117     d->getImage(logI);
00118     if(cmd.logging_video())
00119       writer.saveFrame(logI);
00120   }
00121 
00122   t.process_event(tracking::finished());
00123   writer.close();
00124 }


visp_auto_tracker
Author(s): Filip Novotny
autogenerated on Fri Aug 28 2015 13:36:44