Visual Servoing Platform  version 3.6.1 under development (2024-06-15)
vpVideoWriter.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Write videos and sequences of images.
32  */
33 
39 #ifndef _vpVideoWriter_h_
40 #define _vpVideoWriter_h_
41 
42 #include <string>
43 
44 #include <visp3/io/vpImageIo.h>
45 
46 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI)
47 #include <opencv2/videoio/videoio.hpp>
48 #include <opencv2/highgui/highgui.hpp>
49 #endif
50 
52 
155 class VISP_EXPORT vpVideoWriter
156 {
157 private:
158 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
159  cv::VideoWriter m_writer;
160  int m_fourcc;
161  double m_framerate;
162 #endif
164  typedef enum
165  {
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 m_formatType;
179 
181  std::string m_videoName;
182  std::string m_frameName;
183 
185  bool m_initFileName;
186 
188  bool m_isOpen;
189 
191  int m_frameCount;
192 
194  int m_firstFrame;
195 
197  unsigned int m_width;
198  unsigned int m_height;
199 
200  int m_frameStep;
201 
202 public:
203  vpVideoWriter();
204  virtual ~vpVideoWriter();
205 
206  void close();
207 
213  inline unsigned int getCurrentFrameIndex() const { return m_frameCount; }
217  inline std::string getFrameName() const { return m_frameName; }
218 
219  void open(vpImage<vpRGBa> &I);
220  void open(vpImage<unsigned char> &I);
226  inline void resetFrameCounter() { m_frameCount = m_firstFrame; }
227 
228  void saveFrame(vpImage<vpRGBa> &I);
229  void saveFrame(vpImage<unsigned char> &I);
230 
231 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
232  inline void setCodec(const int fourcc_codec) { m_fourcc = fourcc_codec; }
233 #endif
234 
235  void setFileName(const std::string &filename);
236  void setFirstFrameIndex(int first_frame);
237 
247 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
248  inline void setFramerate(const double framerate) { m_framerate = framerate; }
249 #else
250  inline void setFramerate(const double dummy) { (void)dummy; }
251 #endif
256  inline void setFrameStep(const int frame_step) { m_frameStep = frame_step; }
257 
258 private:
259  vpVideoFormatType getFormat(const std::string &filename);
260  static std::string getExtension(const std::string &filename);
261 };
262 
264 
265 #endif
Class that enables to write easily a video file or a sequence of images.
void setFrameStep(const int frame_step)
void setFramerate(const double framerate)
void setCodec(const int fourcc_codec)
std::string getFrameName() const
unsigned int getCurrentFrameIndex() const
void resetFrameCounter()