45 #include <visp3/core/vpDebug.h> 46 #include <visp3/io/vpVideoWriter.h> 48 #if VISP_HAVE_OPENCV_VERSION >= 0x020200 49 #include <opencv2/imgproc/imgproc.hpp> 57 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
58 writer(), fourcc(0), framerate(0.),
60 formatType(FORMAT_UNKNOWN), initFileName(false), isOpen(false), frameCount(0), firstFrame(0), width(0), height(0)
67 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 69 fourcc = cv::VideoWriter::fourcc(
'P',
'I',
'M',
'1');
70 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100 72 fourcc = CV_FOURCC(
'P',
'I',
'M',
'1');
94 if (!filename || *filename ==
'\0') {
99 if (strlen(filename) >= FILENAME_MAX) {
103 strcpy(this->fileName, filename);
105 formatType = getFormat(fileName);
107 if (formatType == FORMAT_UNKNOWN) {
139 if (formatType == FORMAT_PGM || formatType == FORMAT_PPM || formatType == FORMAT_JPEG || formatType == FORMAT_PNG) {
142 }
else if (formatType == FORMAT_AVI || formatType == FORMAT_MPEG || formatType == FORMAT_MPEG4 ||
143 formatType == FORMAT_MOV) {
144 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 145 writer = cv::VideoWriter(fileName, fourcc, framerate, cv::Size((
int)I.
getWidth(), (int)I.
getHeight()));
147 if (!writer.isOpened()) {
153 "opencv 3rd >= 2.1.0 party libraries."));
157 frameCount = firstFrame;
174 if (formatType == FORMAT_PGM || formatType == FORMAT_PPM || formatType == FORMAT_JPEG || formatType == FORMAT_PNG) {
177 }
else if (formatType == FORMAT_AVI || formatType == FORMAT_MPEG || formatType == FORMAT_MPEG4 ||
178 formatType == FORMAT_MOV) {
179 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 180 writer = cv::VideoWriter(fileName, fourcc, framerate, cv::Size((
int)I.
getWidth(), (int)I.
getHeight()));
182 if (!writer.isOpened()) {
188 "opencv 3rd >= 2.1.0 party libraries."));
192 frameCount = firstFrame;
209 vpERROR_TRACE(
"The video has to be open first with the open method");
213 if (formatType == FORMAT_PGM || formatType == FORMAT_PPM || formatType == FORMAT_JPEG || formatType == FORMAT_PNG) {
214 char name[FILENAME_MAX];
216 sprintf(name, fileName, frameCount);
220 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 242 vpERROR_TRACE(
"The video has to be open first with the open method");
246 if (formatType == FORMAT_PGM || formatType == FORMAT_PPM || formatType == FORMAT_JPEG || formatType == FORMAT_PNG) {
247 char name[FILENAME_MAX];
249 sprintf(name, fileName, frameCount);
253 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 254 cv::Mat matFrame, rgbMatFrame;
256 cv::cvtColor(matFrame, rgbMatFrame, cv::COLOR_GRAY2BGR);
257 writer << rgbMatFrame;
258 #elif VISP_HAVE_OPENCV_VERSION >= 0x020100 259 cv::Mat matFrame, rgbMatFrame;
261 cv::cvtColor(matFrame, rgbMatFrame, CV_GRAY2BGR);
262 writer << rgbMatFrame;
275 vpERROR_TRACE(
"The video has to be open first with the open method");
285 vpVideoWriter::vpVideoFormatType vpVideoWriter::getFormat(
const char *filename)
287 std::string sfilename(filename);
289 std::string ext = vpVideoWriter::getExtension(sfilename);
291 if (ext.compare(
".PGM") == 0)
293 else if (ext.compare(
".pgm") == 0)
295 else if (ext.compare(
".PPM") == 0)
297 else if (ext.compare(
".ppm") == 0)
299 else if (ext.compare(
".JPG") == 0)
301 else if (ext.compare(
".jpg") == 0)
303 else if (ext.compare(
".JPEG") == 0)
305 else if (ext.compare(
".jpeg") == 0)
307 else if (ext.compare(
".PNG") == 0)
309 else if (ext.compare(
".png") == 0)
311 else if (ext.compare(
".AVI") == 0)
313 else if (ext.compare(
".avi") == 0)
315 else if (ext.compare(
".MPEG") == 0)
317 else if (ext.compare(
".mpeg") == 0)
319 else if (ext.compare(
".MPG") == 0)
321 else if (ext.compare(
".mpg") == 0)
323 else if (ext.compare(
".MPEG4") == 0)
325 else if (ext.compare(
".mpeg4") == 0)
327 else if (ext.compare(
".MP4") == 0)
329 else if (ext.compare(
".mp4") == 0)
331 else if (ext.compare(
".MOV") == 0)
333 else if (ext.compare(
".mov") == 0)
336 return FORMAT_UNKNOWN;
340 std::string vpVideoWriter::getExtension(
const std::string &filename)
343 size_t dot = filename.find_last_of(
".");
344 std::string ext = filename.substr(dot, filename.size() - 1);
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
error that can be emited by ViSP classes.
Error that can be emited by the vpImage class and its derivates.
static void write(const vpImage< unsigned char > &I, const std::string &filename)
void saveFrame(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
unsigned int getHeight() const
unsigned int getWidth() const