1 #include <visp3/core/vpImageConvert.h>
3 #include <visp3/core/vpTime.h>
4 #include <visp3/gui/vpDisplayD3D.h>
5 #include <visp3/gui/vpDisplayGDI.h>
6 #include <visp3/gui/vpDisplayGTK.h>
7 #include <visp3/gui/vpDisplayOpenCV.h>
8 #include <visp3/gui/vpDisplayX.h>
9 #include <visp3/io/vpVideoReader.h>
10 #include <visp3/io/vpVideoWriter.h>
12 void usage(
const char *argv[],
int error)
14 std::cout <<
"Synopsis" << std::endl
15 <<
" " << argv[0] <<
" [--in <video name>]"
16 <<
" [--display-fps <framerate>]"
17 <<
" [--out <video name>]"
18 <<
" [--out-first-frame <index>]"
20 <<
" [--out-stride <value>]"
21 <<
" [--verbose] [-v]"
22 <<
" [--help] [-h]" << std::endl
24 std::cout <<
"Description" << std::endl
25 <<
" --in <video name> " << std::endl
26 <<
" Input video to manipulate. " << std::endl
27 <<
" Supported image formats: pgm,ppm,jpg,jpeg,png,tiff,bmp,ras,jp2" << std::endl
28 <<
" Example: " << std::endl
29 <<
" - I%03d.jpg : to read a sequence of images (I008.jpg, I009.jpg, I010.jpg) " << std::endl
31 <<
" --display-fps <framerate>" << std::endl
32 <<
" Framerate used to display the video. When set to -1 display video as fast as possible." << std::endl
33 <<
" Default: 30 (fps)" << std::endl
35 <<
" --out <video name>" << std::endl
36 <<
" Renamed video." << std::endl
38 <<
" --out-first-frame <index>" << std::endl
39 <<
" Renamed video first image index." << std::endl
40 <<
" When set to -1, use same image numbering as input video." << std::endl
41 <<
" Default: -1" << std::endl
43 <<
" --out-gray" << std::endl
44 <<
" Associated to --out option, convert input images to Y8 gray level image." << std::endl
46 <<
" --out-stride <value>" << std::endl
47 <<
" Associated to --out option, allows to subsample the resulting output video" << std::endl
48 <<
" keeping one over <value> images. For example, when set to 2, the ouput video" << std::endl
49 <<
" has two times less images than the input video." << std::endl
50 <<
" Default: 1." << std::endl
52 <<
" --select, -s" << std::endl
53 <<
" Associated to --out option, allows the user to select by mouse" << std::endl
54 <<
" click which images will be saved in the output video." << std::endl
56 <<
" --verbose, -v" << std::endl
57 <<
" Display extra messages." << std::endl
59 <<
" --help, -h" << std::endl
60 <<
" Print this helper message." << std::endl
63 std::cout <<
"Error" << std::endl
65 <<
"Unsupported parameter " << argv[error] << std::endl;
69 int main(
int argc,
const char *argv[])
76 std::string opt_video_in =
"";
77 double opt_display_fps = 30;
78 std::string opt_video_out =
"";
79 int opt_video_out_first_frame = -1;
80 bool opt_video_out_gray =
false;
81 int opt_video_out_stride = 1;
83 bool opt_verbose =
false;
84 bool opt_select_frame =
false;
86 for (
int i = 1; i < argc; i++) {
87 if (std::string(argv[i]) ==
"--in" && i + 1 < argc) {
88 opt_video_in = std::string(argv[i + 1]);
90 }
else if (std::string(argv[i]) ==
"--display-fps" && i + 1 < argc) {
91 opt_display_fps = std::atof(argv[i + 1]);
93 }
else if (std::string(argv[i]) ==
"--out" && i + 1 < argc) {
94 opt_video_out = std::string(argv[i + 1]);
96 }
else if (std::string(argv[i]) ==
"--out-first-frame" && i + 1 < argc) {
97 opt_video_out_first_frame = std::atoi(argv[i + 1]);
99 }
else if (std::string(argv[i]) ==
"--out-gray") {
100 opt_video_out_gray =
true;
101 }
else if (std::string(argv[i]) ==
"--out-stride" && i + 1 < argc) {
102 opt_video_out_stride = std::atoi(argv[i + 1]);
104 }
else if (std::string(argv[i]) ==
"--verbose" || std::string(argv[i]) ==
"-v") {
106 }
else if (std::string(argv[i]) ==
"--select" || std::string(argv[i]) ==
"-s") {
107 opt_select_frame =
true;
108 }
else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
118 if (opt_video_in.empty()) {
120 std::cout <<
"Error: " << std::endl <<
" No input video set using --in <video name> option." << std::endl;
123 if (opt_select_frame && opt_video_out.empty()) {
125 std::cout <<
"Error: " << std::endl
126 <<
" --select option is enabled but no output video name is specified using --out <video> option."
130 if (opt_video_out_gray && opt_video_out.empty()) {
132 std::cout <<
"Error: " << std::endl
133 <<
" --out-gray option is enabled but no output video name is specified using --out <video> option."
137 if ((opt_video_out_stride > 1) && opt_video_out.empty()) {
139 std::cout <<
"Error: " << std::endl
140 <<
" --out-stride option is enabled but no output video name is specified using --out <video> option."
144 if ((opt_video_out_stride > 1) && opt_select_frame && !opt_video_out.empty()) {
146 std::cout <<
"Error: " << std::endl
147 <<
" --out-stride option is enabled but this option doesn't make sense with --select option."
157 std::cout <<
"Input video" << std::endl;
158 std::cout <<
" Video name : " << opt_video_in << std::endl;
159 std::cout <<
" Video dimension: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
162 std::cout <<
" Framerate (fps): " << opt_display_fps << std::endl;
165 if (!opt_video_out.empty()) {
168 (opt_video_out_first_frame < 0 ? static_cast<int>(g.
getFirstFrameIndex()) : opt_video_out_first_frame);
170 if (opt_video_out_gray) {
176 std::cout <<
"Output video" << std::endl;
177 std::cout <<
" Video name : " << opt_video_out << std::endl;
178 std::cout <<
" First image : " << first_frame << std::endl;
179 std::cout <<
" Stride : " << opt_video_out_stride << std::endl;
180 std::cout <<
" Y8 gray images : " << (opt_video_out_gray ?
"yes" :
"no (same as input)") << std::endl;
183 std::cout <<
"Other settings" << std::endl;
184 std::cout <<
" Verbose : " << (opt_verbose ?
"enabled" :
"disabled") << std::endl;
185 std::cout <<
" Select frames : " << (opt_select_frame ?
"enabled" :
"disabled") << std::endl;
189 #if defined(VISP_HAVE_X11)
191 #elif defined(VISP_HAVE_GDI)
193 #elif defined(HAVE_OPENCV_HIGHGUI)
195 #elif defined(VISP_HAVE_GTK)
197 #elif defined(VISP_HAVE_D3D9)
200 std::cout <<
"No image viewer is available..." << std::endl;
209 std::stringstream ss;
214 if (opt_select_frame) {
219 bool selected_frame = (opt_select_frame ? false :
true);
223 selected_frame =
true;
229 if (!opt_video_out.empty() && selected_frame) {
230 if (cpt_stride == opt_video_out_stride) {
232 if (opt_video_out_gray) {
239 std::cout <<
"Save " << writer.
getFrameName() << std::endl;
246 if (opt_display_fps > 0) {
251 std::cout <<
"Catch an exception: " << e << std::endl;
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
unsigned int getDownScalingFactor()
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
unsigned int getWidth() const
unsigned int getHeight() const
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
long getFirstFrameIndex()
long getFrameIndex() const
Class that enables to write easily a video file or a sequence of images.
void saveFrame(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void open(vpImage< vpRGBa > &I)
void setFirstFrameIndex(int first_frame)
std::string getFrameName() const
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()