complex.cpp
Go to the documentation of this file.
1 //command line parameters
2 #include "cmd_line/cmd_line.h"
3 
4 //detectors
7 
8 //tracking
11 #include "libauto_tracker/events.h"
12 
13 //visp includes
14 #include <visp/vpImageIo.h>
15 #include <visp/vpVideoReader.h>
16 #include <visp/vpVideoWriter.h>
17 #include <visp/vpV4l2Grabber.h>
18 #include <visp/vpMbEdgeKltTracker.h>
19 #include <visp/vpMbKltTracker.h>
20 #include <visp/vpMbEdgeTracker.h>
21 #include <visp/vpDisplayX.h>
22 
23 int main(int argc, char**argv)
24 {
25  //Parse command line arguments
26  CmdLine cmd(argc,argv);
27 
28  if(cmd.should_exit()) return 0; //exit if needed
29 
30  //Read video from a set of images, a single image or a camera
31  vpImage<vpRGBa> I;
32  vpVideoReader reader;
33  vpV4l2Grabber video_reader;
34  vpVideoWriter writer;
35  vpImage<vpRGBa> logI;
36  vpMbTracker* tracker;
37 
38  vpCameraParameters cam = cmd.get_cam_calib_params();
39  if(cmd.get_verbose())
40  std::cout << "loaded camera parameters:" << cam << std::endl;
41 
42 
43  if(cmd.logging_video()){
44  writer.setFileName((cmd.get_data_dir() + cmd.get_log_file_pattern()).c_str());
45  writer.open(logI);
46  }
47 
48  if(cmd.using_single_image()){
49  if(cmd.get_verbose())
50  std::cout << "Loading: " << cmd.get_single_image_path() << std::endl;
51  vpImageIo::read(I,cmd.get_single_image_path());
52  }else if(cmd.using_video_camera()){
53  video_reader.setDevice(cmd.get_video_channel().c_str());
54  video_reader.setInput(0);
55  video_reader.setScale(1);
56  video_reader.setFramerate(vpV4l2Grabber::framerate_25fps); // 25 fps
57  video_reader.setPixelFormat(vpV4l2Grabber::V4L2_YUYV_FORMAT);
58  video_reader.setWidth(640);
59  video_reader.setHeight(480);
60  video_reader.setNBuffers(3); // 3 ring buffers to ensure real-time acquisition
61  video_reader.open(I); // Open the grabber
62  }else{
63  std::string filenames((cmd.get_data_dir() + cmd.get_input_file_pattern()));
64  if(cmd.get_verbose())
65  std::cout << "Loading: " << filenames << std::endl;
66  reader.setFileName( filenames.c_str() );
67 
68  reader.setFirstFrameIndex(2);
69  reader.open(I);
70  }
71 
72  //init display
73  vpDisplayX* d = new vpDisplayX();
74  d->init(I);
75  //init hybrid tracker
76  detectors::DetectorBase* detector = NULL;
77  if (cmd.get_detector_type() == CmdLine::ZBAR)
78  detector = new detectors::qrcode::Detector;
79  else if(cmd.get_detector_type() == CmdLine::DTMX)
80  detector = new detectors::datamatrix::Detector;
81 
82  if(cmd.get_tracker_type() == CmdLine::KLT)
83  tracker = new vpMbKltTracker();
84  else if(cmd.get_tracker_type() == CmdLine::KLT_MBT)
85  tracker = new vpMbEdgeKltTracker();
86  else if(cmd.get_tracker_type() == CmdLine::MBT)
87  tracker = new vpMbEdgeTracker();
88 
89  tracking::Tracker t(cmd,detector,tracker);
90  TrackerThread tt(t);
91  boost::thread bt(tt);
92 
93 
94  //when we're using a camera, we can have a meaningless video feed
95  //until the user selects the first meaningful image
96  //The first meaningful frame is selected with a click
97  //In other cases, the first meaningful frame is selected by sending
98  //the tracking::select_input event
99  if(!cmd.using_video_camera())
100  t.process_event(tracking::select_input(I));
101 
102 
103  for(int iter=0;
104  cmd.using_video_camera() ||
105  cmd.using_single_image() ||
106  (iter<reader.getLastFrameIndex()-1);
107  iter++
108  ){
109  if(cmd.using_video_camera()){
110  video_reader.acquire(I);
111  vpDisplay::display(I);
112  vpDisplay::flush(I);
113  }
114  else if(!cmd.using_single_image())
115  reader.acquire(I);
116  t.process_event(tracking::input_ready(I,cam,iter));
117  d->getImage(logI);
118  if(cmd.logging_video())
119  writer.saveFrame(logI);
120  }
121 
122  t.process_event(tracking::finished());
123  writer.close();
124 }
d
string cmd
bool get_verbose() const
Definition: cmd_line.cpp:238
std::string get_input_file_pattern() const
Definition: cmd_line.cpp:166
msm::back::state_machine< Tracker_ > Tracker
Definition: tracking.h:182
bool should_exit() const
Definition: cmd_line.cpp:226
bool logging_video() const
Definition: cmd_line.cpp:218
std::string get_video_channel() const
Definition: cmd_line.cpp:230
int main(int argc, char **argv)
Definition: complex.cpp:23
std::string get_single_image_path() const
Definition: cmd_line.cpp:291
vpCameraParameters get_cam_calib_params() const
Definition: cmd_line.cpp:154
std::string get_data_dir() const
Definition: cmd_line.cpp:262
std::string get_log_file_pattern() const
Definition: cmd_line.cpp:162
TRACKER_TYPE get_tracker_type() const
Definition: cmd_line.cpp:314
bool using_video_camera() const
Definition: cmd_line.cpp:258
DETECTOR_TYPE get_detector_type() const
Definition: cmd_line.cpp:307
bool using_single_image() const
Definition: cmd_line.cpp:287


visp_auto_tracker
Author(s): Filip Novotny
autogenerated on Sat Mar 13 2021 03:20:08