Visual Servoing Platform  version 3.1.0
vpVideoWriter.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Write videos and sequences of images.
33  *
34  * Authors:
35  * Nicolas Melchior
36  *
37  *****************************************************************************/
38 
44 #ifndef vpVideoWriter_H
45 #define vpVideoWriter_H
46 
47 #include <string>
48 
49 #include <visp3/io/vpImageIo.h>
50 
51 #if VISP_HAVE_OPENCV_VERSION >= 0x020200
52 #include <opencv2/highgui/highgui.hpp>
53 #elif VISP_HAVE_OPENCV_VERSION >= 0x020000
54 #include <opencv/highgui.h>
55 #endif
56 
156 class VISP_EXPORT vpVideoWriter
157 {
158 private:
159 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
160  cv::VideoWriter writer;
161  int fourcc;
162  double framerate;
163 #endif
164  typedef enum {
166  FORMAT_PGM,
167  FORMAT_PPM,
168  FORMAT_JPEG,
169  FORMAT_PNG,
170  FORMAT_AVI,
171  FORMAT_MPEG,
172  FORMAT_MPEG4,
173  FORMAT_MOV,
174  FORMAT_UNKNOWN
175  } vpVideoFormatType;
176 
178  vpVideoFormatType formatType;
179 
181  char fileName[FILENAME_MAX];
182 
184  bool initFileName;
185 
187  bool isOpen;
188 
190  unsigned int frameCount;
191 
193  unsigned int firstFrame;
194 
196  unsigned int width;
197  unsigned int height;
198 
199 public:
200  vpVideoWriter();
201  ~vpVideoWriter();
202 
203  void close();
204 
210  inline unsigned int getCurrentFrameIndex() const { return frameCount; }
211 
212  void open(vpImage<vpRGBa> &I);
213  void open(vpImage<unsigned char> &I);
219  inline void resetFrameCounter() { frameCount = firstFrame; }
220 
221  void saveFrame(vpImage<vpRGBa> &I);
222  void saveFrame(vpImage<unsigned char> &I);
223 
224 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
225  inline void setCodec(const int fourcc_codec) { this->fourcc = fourcc_codec; }
226 #endif
227 
228  void setFileName(const char *filename);
229  void setFileName(const std::string &filename);
235  inline void setFirstFrameIndex(const unsigned int first_frame) { this->firstFrame = first_frame; }
236 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
237 
244  inline void setFramerate(const double frame_rate) { this->framerate = frame_rate; }
245 #endif
246 
247 private:
248  vpVideoFormatType getFormat(const char *filename);
249  static std::string getExtension(const std::string &filename);
250 };
251 
252 #endif
unsigned int getCurrentFrameIndex() const
void setFirstFrameIndex(const unsigned int first_frame)
void resetFrameCounter()
Class that enables to write easily a video file or a sequence of images.
void setCodec(const int fourcc_codec)
void setFramerate(const double frame_rate)