Visual Servoing Platform  version 3.6.1 under development (2024-12-03)
vpVideoWriter.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 VP_VIDEO_WRITER_H
40 #define VP_VIDEO_WRITER_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 
51 BEGIN_VISP_NAMESPACE
52 
163 class VISP_EXPORT vpVideoWriter
164 {
165 private:
166 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
167  cv::VideoWriter m_writer;
168  int m_fourcc;
169  double m_framerate;
170 #endif
172  typedef enum
173  {
174  FORMAT_PGM,
175  FORMAT_PPM,
176  FORMAT_JPEG,
177  FORMAT_PNG,
178  FORMAT_AVI,
179  FORMAT_MPEG,
180  FORMAT_MPEG4,
181  FORMAT_MOV,
182  FORMAT_UNKNOWN
183  } vpVideoFormatType;
184 
186  vpVideoFormatType m_formatType;
187 
189  std::string m_videoName;
190  std::string m_frameName;
191 
193  bool m_initFileName;
194 
196  bool m_isOpen;
197 
199  int m_frameCount;
200 
202  int m_firstFrame;
203 
205  unsigned int m_width;
206  unsigned int m_height;
207 
208  int m_frameStep;
209 
210 public:
211  vpVideoWriter();
212  virtual ~vpVideoWriter();
213 
214  void close();
215 
221  inline unsigned int getCurrentFrameIndex() const { return m_frameCount; }
225  inline std::string getFrameName() const { return m_frameName; }
226 
227  void open(vpImage<vpRGBa> &I);
228  void open(vpImage<unsigned char> &I);
234  inline void resetFrameCounter() { m_frameCount = m_firstFrame; }
235 
236  void saveFrame(vpImage<vpRGBa> &I);
237  void saveFrame(vpImage<unsigned char> &I);
238 
239 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
240  inline void setCodec(const int fourcc_codec) { m_fourcc = fourcc_codec; }
241 #endif
242 
243  void setFileName(const std::string &filename);
244  void setFirstFrameIndex(int first_frame);
245 
255 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO)
256  inline void setFramerate(const double framerate) { m_framerate = framerate; }
257 #else
258  inline void setFramerate(const double dummy) { (void)dummy; }
259 #endif
264  inline void setFrameStep(const int frame_step) { m_frameStep = frame_step; }
265 
266 private:
267  vpVideoFormatType getFormat(const std::string &filename);
268  static std::string getExtension(const std::string &filename);
269 };
270 
271 END_VISP_NAMESPACE
272 
273 #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()