void DisparityProvider::saveDisparityMap() const noexcept
{
    cv::FileStorage fileStorage(DISPARITY_MAP_OUTPUT_FILE,
                                cv::FileStorage::WRITE);
    fileStorage << DISPARITY_MAP_TITLE << _disparityBlackWhite;
    fileStorage.release();
}
//--------------------------------------------------------------------------------------------------
std::vector<std::string> LoadConfig(std::string fileAddress,
    cv::Size* pBoardSizeOut, cv::Size* pBoardSizeMmOut,
    std::string* pCameraNameOut, bool* pbUseDotPatternOut )
{
    cv::FileStorage fileStorage( fileAddress, cv::FileStorage::READ );

    if ( !fileStorage.isOpened() )
    {
        throw std::runtime_error( "Unable to open config file" );
    }

    // Read out BoardSize
    cv::FileNode boardSizeNode = fileStorage[ "BoardSize" ];
    if ( boardSizeNode.size() != 2 || !boardSizeNode[ 0 ].isInt() || !boardSizeNode[ 1 ].isInt() )
    {
        throw std::runtime_error( "Unable to read BoardSize" );
    }
    pBoardSizeOut->width = (int)(boardSizeNode[ 0 ]);
    pBoardSizeOut->height = (int)(boardSizeNode[ 1 ]);

    // Read out BoardSizeMM
    cv::FileNode boardSizeMMNode = fileStorage[ "BoardSizeMM" ];
    if ( boardSizeMMNode.size() != 2 || !boardSizeMMNode[ 0 ].isInt() || !boardSizeMMNode[ 1 ].isInt() )
    {
        throw std::runtime_error( "Unable to read BoardSizeMM" );
    }
    pBoardSizeMmOut->width = (int)(boardSizeMMNode[ 0 ]);
    pBoardSizeMmOut->height = (int)(boardSizeMMNode[ 1 ]);

    // Read out CameraName
    cv::FileNode cameraNameNode = fileStorage[ "CameraName" ];
    if ( !cameraNameNode.isString() )
    {
        throw std::runtime_error( "Unable to read CameraName" );
    }
    *pCameraNameOut = (std::string)cameraNameNode;

    // Read out UseDotPattern
    *pbUseDotPatternOut = false;
    cv::FileNode useDotPatternNode = fileStorage[ "UseDotPattern" ];
    if ( useDotPatternNode.isInt() )
    {
        *pbUseDotPatternOut = ((int)useDotPatternNode != 0);
    }

    // Read in the image file names
    std::vector<std::string> imageFilenames;

    cv::FileNode imageFilesNode = fileStorage[ "ImageFiles" ];
    for ( uint32_t fileIdx = 0; fileIdx < imageFilesNode.size(); fileIdx++ )
    {
        imageFilenames.push_back( Utilities::decodeRelativeFilename(
			Utilities::makeFilenameAbsoluteFromCWD( fileAddress ), (std::string)(imageFilesNode[ fileIdx ]) ) );
    }

    fileStorage.release();

	return imageFilenames;
}
Beispiel #3
0
void CalSettings::loadSpecial(const QUrl& url, const QColor& color)
{
    if (url.isEmpty())
    {
        qCDebug(DIGIKAM_GENERAL_LOG) << "Loading calendar from file failed: No valid url provided!";
        return;
    }

    KCalCore::MemoryCalendar::Ptr memCal(new KCalCore::MemoryCalendar(QString::fromLatin1("UTC")));
    KCalCore::FileStorage::Ptr fileStorage(new KCalCore::FileStorage(memCal, url.toLocalFile(), new KCalCore::ICalFormat));

    qCDebug(DIGIKAM_GENERAL_LOG) << "Loading calendar from file " << url.toLocalFile();

    if (!fileStorage->load())
    {
        qCDebug(DIGIKAM_GENERAL_LOG) << "Failed!";
    }
    else
    {
        CalSystem calSys;
        QDate     qFirst, qLast;

        qFirst = calSys.date(params.year, 1, 1);
        qLast  = calSys.date(params.year + 1, 1, 1);
        qLast  = qLast.addDays(-1);

        KDateTime dtFirst(qFirst);
        KDateTime dtLast(qLast);
        KDateTime dtCurrent;

        int counter                = 0;
        KCalCore::Event::List list = memCal->rawEvents(qFirst, qLast);

        foreach(const KCalCore::Event::Ptr event, list)
        {
            qCDebug(DIGIKAM_GENERAL_LOG) << event->summary() << endl << "--------";
            counter++;

            if (event->recurs())
            {
                KCalCore::Recurrence* const recur = event->recurrence();

                for (dtCurrent = recur->getNextDateTime(dtFirst.addDays(-1));
                     (dtCurrent <= dtLast) && dtCurrent.isValid();
                     dtCurrent = recur->getNextDateTime(dtCurrent))
                {
                    addSpecial(dtCurrent.date(), Day(color, event->summary()));
                }
            }
            else
            {
                addSpecial(event->dtStart().date(), Day(color, event->summary()));
            }
        }

        qCDebug(DIGIKAM_GENERAL_LOG) << "Loaded " << counter << " events";
        memCal->close();
        fileStorage->close();
    }
//------------------------------------------------------------------------------
opencvWebcam::opencvWebcam(): cameraId(0)
{
   cv::FileStorage fileStorage(PKGDATADIR "/config.xml", cv::FileStorage::READ);
   if (fileStorage.isOpened() ) {
      cameraId = (int)fileStorage["CAMERA_INDEX"];
   }

   VideoCapture(cameraId);
}
void DisparityProvider::loadRectifyMaps(std::string& pathToRectifyMaps) noexcept
{
    cv::FileStorage fileStorage(pathToRectifyMaps, cv::FileStorage::READ);
    fileStorage[RECTIFY_MAP_X1_TITLE] >> _rectifyMapXLeft;
    fileStorage[RECTIFY_MAP_Y1_TITLE] >> _rectifyMapYLeft;
    fileStorage[RECTIFY_MAP_X2_TITLE] >> _rectifyMapXRight;
    fileStorage[RECTIFY_MAP_Y2_TITLE] >> _rectifyMapYRight;
    fileStorage.release();
}
bool OpenCvDetector::saveModel(const std::string& filename)
{
    cv::FileStorage fileStorage(filename, cv::FileStorage::WRITE);

    fileStorage << "detector_type" << getName();
    fileStorage << "used_feature_dimensions" << "[";

    for(size_t i = 0; i < m_featureDimensions.size(); i++) {
        fileStorage << m_featureDimensions[i];
    }

    fileStorage << "]";

    getStatModel()->write(*fileStorage, "classifier");
    return true; // FIXME: How to check success?
}
bool OpenCvDetector::loadModel(const std::string& filename)
{  
    std::string theFilename = filename;

    if(theFilename.empty()) m_privateNodeHandle.getParam("model", theFilename);

    if(theFilename.empty()) {
        ROS_WARN("No model to load has been specified, detector will not be initialized");
        return false;
    }

    cv::FileStorage fileStorage(theFilename, cv::FileStorage::READ);

    // Check type of detector that was used to train the model
    cv::FileNode detectorTypeNode = fileStorage["detector_type"];
    std::string detectorType = (std::string) detectorTypeNode[0];
    if(detectorType != getName()) {
        ROS_ERROR_STREAM("Detector of type '" << getName() << "' cannot load a model learned for detector of type '" << detectorType << "'!");
        return false;
    }

    // Check feature dimensions that were used to train the model
    const std::vector<FeatureDimension> allFeatureDimensions = FeatureRegistry::getAllFeatureDimensions();
    std::vector<FeatureDimension> featureDimensions;

    cv::FileNode featureDimensionsNode = fileStorage["used_feature_dimensions"];
    for(int i = 0; i < featureDimensionsNode.size(); i++) {
        FeatureDimension currentDimension = (FeatureDimension) featureDimensionsNode[i];

        if(std::find(allFeatureDimensions.begin(), allFeatureDimensions.end(), currentDimension) == allFeatureDimensions.end()) {
            ROS_ERROR_STREAM("Unknown feature dimension: " << currentDimension);
            return false;
        }
        featureDimensions.push_back( currentDimension );
    }
    m_featureDimensions = featureDimensions;
    ROS_INFO("Trained model uses %zu feature dimension(s)", featureDimensions.size());

    cv::FileNode classifierNode = fileStorage["classifier"];
    getStatModel()->read(*fileStorage, *classifierNode);
    return true; // FIXME: How to check success? Does load() throw an exception if it fails?
}
// ---------------------------------------------------------------------------
// FileStorageL
// ---------------------------------------------------------------------------
//        
MNcdFileStorage& CNcdPreviewManager::FileStorageL(
    const CNcdNodeIdentifier& aId )
    {
    DLTRACEIN(( _L("Namespace: %S"), &aId.NodeNameSpace() ));        
    
    MNcdStorage& storage = iStorageManager.CreateOrGetStorageL( 
        iGeneralManager.FamilyName(), 
        NcdProviderDefines::KPreviewStorageNamespace ); 
        
    // Get rid of invalid characters in the namespace since it'll be
    // used as a directory name
    HBufC* id = EncodeFilenameLC( 
        aId.NodeNameSpace(), 
        iStorageManager.FileSession() );
    
    MNcdFileStorage& fileStorage( storage.FileStorageL( *id ) );
    
    CleanupStack::PopAndDestroy( id );
    return fileStorage;        
    }