Visual Servoing Platform  version 3.4.0
vpVideoWriter.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 
159 class VISP_EXPORT vpVideoWriter
160 {
161 private:
162 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
163  cv::VideoWriter writer;
164  int fourcc;
165  double framerate;
166 #endif
167  typedef enum {
169  FORMAT_PGM,
170  FORMAT_PPM,
171  FORMAT_JPEG,
172  FORMAT_PNG,
173  FORMAT_AVI,
174  FORMAT_MPEG,
175  FORMAT_MPEG4,
176  FORMAT_MOV,
177  FORMAT_UNKNOWN
178  } vpVideoFormatType;
179 
181  vpVideoFormatType formatType;
182 
184  char fileName[FILENAME_MAX];
185 
187  bool initFileName;
188 
190  bool isOpen;
191 
193  unsigned int frameCount;
194 
196  unsigned int firstFrame;
197 
199  unsigned int width;
200  unsigned int height;
201 
202 public:
203  vpVideoWriter();
204  virtual ~vpVideoWriter();
205 
206  void close();
207 
213  inline unsigned int getCurrentFrameIndex() const { return frameCount; }
214 
215  void open(vpImage<vpRGBa> &I);
216  void open(vpImage<unsigned char> &I);
222  inline void resetFrameCounter() { frameCount = firstFrame; }
223 
224  void saveFrame(vpImage<vpRGBa> &I);
225  void saveFrame(vpImage<unsigned char> &I);
226 
227 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
228  inline void setCodec(const int fourcc_codec) { this->fourcc = fourcc_codec; }
229 #endif
230 
231  void setFileName(const char *filename);
232  void setFileName(const std::string &filename);
238  inline void setFirstFrameIndex(unsigned int first_frame) { this->firstFrame = first_frame; }
239 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
240 
247  inline void setFramerate(const double frame_rate) { this->framerate = frame_rate; }
248 #endif
249 
250 private:
251  vpVideoFormatType getFormat(const char *filename);
252  static std::string getExtension(const std::string &filename);
253 };
254 
255 #endif
unsigned int getCurrentFrameIndex() const
void resetFrameCounter()
Class that enables to write easily a video file or a sequence of images.
void setFirstFrameIndex(unsigned int first_frame)
void setCodec(const int fourcc_codec)
void setFramerate(const double frame_rate)