/*! Sets all the parameters needed to read the video or the image sequence. Grab the first frame and stores it in the image \f$ I \f$. \param I : The image where the frame is stored. */ void vpVideoReader::open(vpImage< vpRGBa > &I) { if (!initFileName) { vpERROR_TRACE("The generic filename has to be set"); throw (vpImageException(vpImageException::noFileNameError,"filename empty")); } if (formatType == FORMAT_PGM || formatType == FORMAT_PPM || formatType == FORMAT_JPEG || formatType == FORMAT_PNG) { imSequence = new vpDiskGrabber; imSequence->setGenericName(fileName); imSequence->setImageNumber((int)firstFrame); } #ifdef VISP_HAVE_FFMPEG else if (formatType == FORMAT_AVI || formatType == FORMAT_MPEG || formatType == FORMAT_MOV || formatType == FORMAT_OGV) { ffmpeg = new vpFFMPEG; if(!ffmpeg->openStream(fileName, vpFFMPEG::COLORED)) throw (vpException(vpException::ioError ,"Could not open the video")); ffmpeg->initStream(); } #else else if (formatType == FORMAT_AVI || formatType == FORMAT_MPEG || formatType == FORMAT_MOV || formatType == FORMAT_OGV) { vpERROR_TRACE("To read video files the FFmpeg library has to be installed"); throw (vpException(vpException::fatalError ,"the FFmpeg library is required")); } #endif else if (formatType == FORMAT_UNKNOWN) { vpERROR_TRACE("The format of the file does not correpsond to a readable format."); throw (vpException(vpException::fatalError ,"The format of the file does not correpsond to a readable format.")); } frameCount = firstFrame; if(!getFrame(I,firstFrame)) { vpERROR_TRACE("Could not read the first frame"); throw (vpException(vpException::ioError ,"Could not read the first frame")); } height = I.getHeight(); width = I.getWidth(); isOpen = true; findLastFrameIndex(); }
/*! Sets all the parameters needed to read the video or the image sequence. Grab the first frame and stores it in the image \f$ I \f$. \param I : The image where the frame is stored. */ void vpVideoReader::open(vpImage<unsigned char> &I) { if (!initFileName) { vpERROR_TRACE("The generic filename has to be set"); throw (vpImageException(vpImageException::noFileNameError,"filename empty")); } if (isImageExtensionSupported()) { imSequence = new vpDiskGrabber; imSequence->setGenericName(fileName); if (firstFrameIndexIsSet) imSequence->setImageNumber(firstFrame); } else if (isVideoExtensionSupported()) { #ifdef VISP_HAVE_FFMPEG ffmpeg = new vpFFMPEG; if (!ffmpeg->openStream(fileName, vpFFMPEG::GRAY_SCALED)) throw (vpException(vpException::ioError ,"Could not open the video with ffmpeg")); ffmpeg->initStream(); #elif VISP_HAVE_OPENCV_VERSION >= 0x020100 capture.open(fileName); if(!capture.isOpened()) { throw (vpException(vpException::ioError ,"Could not open the video with opencv")); } #else //vpERROR_TRACE("To read video files ViSP should be build with ffmpeg or opencv 3rd party libraries."); throw (vpException(vpException::fatalError ,"To read video files ViSP should be build with ffmpeg or opencv >= 2.1.0 3rd party libraries.")); #endif } else if (formatType == FORMAT_UNKNOWN) { //vpERROR_TRACE("The format of the file does not correspond to a readable format."); throw (vpException(vpException::fatalError ,"The format of the file does not correspond to a readable format supported by ViSP.")); } findFirstFrameIndex(); frameCount = firstFrame; if(!getFrame(I,firstFrame)) { //vpERROR_TRACE("Could not read the video first frame"); throw (vpException(vpException::ioError ,"Could not read the video first frame")); } height = I.getHeight(); width = I.getWidth(); isOpen = true; findLastFrameIndex(); frameCount = firstFrame; // open() should not increase the frame counter }