QImage ImagesFrameSource_sV::frameAt(const uint frame, const FrameSize frameSize) { if (int(frame) < m_imagesList.size()) { return QImage(framePath(frame, frameSize)); } else { return QImage(); } }
QImage VideoFrameSource_sV::frameAt(const uint frame, const FrameSize frameSize) { // TODO: QString path = framePath(frame, frameSize); //qDebug() << "frameAt "<< frame; #if 0 if(frameCache.contains(path)) return *(frameCache.object(path)); #endif QImage _frame = QImage(path); #if 0 frameCache.insert(path, &_frame); #endif return _frame; }
/// \todo What if image missing? void ImagesFrameSource_sV::slotContinueInitialization() { emit signalNextTask("Creating preview images from the input images", m_imagesList.size()); for (; m_nextFrame < m_imagesList.size(); m_nextFrame++) { QString outputFile(framePath(m_nextFrame, FrameSize_Small)); if (QFile(outputFile).exists()) { emit signalTaskItemDescription("Resized image already exists for " + QFileInfo(m_imagesList.at(m_nextFrame)).fileName()); } else { emit signalTaskItemDescription(QString("Re-sizing image %1 to:\n%2") .arg(QFileInfo(m_imagesList.at(m_nextFrame)).fileName()) .arg(outputFile)); QImage small = QImage(m_imagesList.at(m_nextFrame)).scaled(m_sizeSmall, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); small.save(outputFile); } emit signalTaskProgress(m_nextFrame); if (m_stopInitialization) { break; } } m_initialized = true; emit signalAllTasksFinished(); }
QImage VideoFrameSource_sV::frameAt(const uint frame, const FrameSize frameSize) { return QImage(framePath(frame, frameSize)); }
/* images will be saved in the current directory by default */ std::vector<string> capture(int startFrame, int endFrame, bool output = false, const char* path = "", string filename = "") { /* total number of frames */ size_t total = endFrame - startFrame; /* dynamical array of images for storing all the frames */ /* store string rather than Image objects because those objects will eat all the memory */ std::vector<string> images; this->setFrames(startFrame, false); #ifdef FFMPEG /* use ffmpeg to improve speed */ string videoPath(this->path); string framePath(path); string cmd = "ffmpeg -r \"" + Common::doubleToStr(this->getVideo().get(CV_CAP_PROP_FPS)) + "\" -ss " + Common::doubleToStr(startFrame / this->getVideo().get(CV_CAP_PROP_FPS)) + " -i " + videoPath + " -vframes \"" + Common::intToStr(total + 1) + "\" \"" + framePath + "f" + filename + "_%1d.png\""; /* excute the command */ FILE* captureProcess = popen(cmd.c_str(), "w"); if (captureProcess == NULL) { ostringstream os; os << "Failed to capture frames from the video"; Common::errorPrint(os.str().c_str()); /* exit */ exit(-1); } pclose(captureProcess); size_t i = 1; for (; i <= total + 1; i++) { /* save the image when output is [true] */ if (output && i >= startFrame) { string num = Common::intToStr(i); string reserved(path); images.push_back(reserved + "f" + filename + "_" + num + ".png"); } } #endif #ifndef FFMPEG /* this loop will cost too much time */ size_t i = startFrame; for (; i <= endFrame; i++) { Mat reservedImg; this->vdo.read(reservedImg); /* save the image when output is [true] */ if (output && i >= startFrame) { string num = Common::intToStr(i); string reserved(path); imwrite((reserved + filename + num + ".png").c_str(), reservedImg); images.push_back(reserved + "f" + filename + "_" + num + ".png"); cout << "save image: " + num << endl; } } #endif return images; }
AnimationPtr AnimationLoader::load(const std::string& filename) { bfs::path animPath(filename); std::string animationFilename = animPath.string(); TiXmlDocument doc; AnimationPtr animation; try { RawData* data = m_vfs->open(animationFilename); if (data) { if (data->getDataLength() != 0) { doc.Parse(data->readString(data->getDataLength()).c_str()); if (doc.Error()) { return animation; } // done with data delete resource delete data; data = 0; } } } catch (NotFound& e) { FL_ERR(_log, e.what()); // TODO - should we abort here // or rethrow the exception // or just keep going return animation; } // if we get here then everything loaded properly // so we can just parse out the contents TiXmlElement* root = doc.RootElement(); if (root) { animation.reset(new Animation()); int animDelay = 0; root->QueryValueAttribute("delay", &animDelay); int animXoffset = 0; int animYoffset = 0; int action = -1; root->QueryValueAttribute("x_offset", &animXoffset); root->QueryValueAttribute("y_offset", &animYoffset); root->QueryValueAttribute("action", &action); for (TiXmlElement* frameElement = root->FirstChildElement("frame"); frameElement; frameElement = frameElement->NextSiblingElement("frame")) { if (animation) { animation->setActionFrame(action); const std::string* sourceId = frameElement->Attribute(std::string("source")); if (sourceId) { bfs::path framePath(filename); if (HasParentPath(framePath)) { framePath = GetParentPath(framePath) / *sourceId; } else { framePath = bfs::path(*sourceId); } ImagePtr imagePtr; if(!m_imageManager->exists(framePath.string())) { imagePtr = m_imageManager->create(framePath.string()); } else { imagePtr = m_imageManager->getPtr(framePath.string()); } if (imagePtr) { int frameXoffset = 0; int frameYoffset = 0; int success = root->QueryValueAttribute("x_offset", &frameXoffset); if (success == TIXML_SUCCESS) { imagePtr->setXShift(frameXoffset); } else { imagePtr->setXShift(animXoffset); } success = root->QueryValueAttribute("y_offset", &frameYoffset); if (success == TIXML_SUCCESS) { imagePtr->setYShift(frameYoffset); } else { imagePtr->setYShift(animYoffset); } int frameDelay = 0; success = root->QueryValueAttribute("delay", &frameDelay); if (success == TIXML_SUCCESS) { animation->addFrame(imagePtr, frameDelay); } else { animation->addFrame(imagePtr, animDelay); } } } } } } return animation; }