bool ImageDataFloat2ndStageBinaryCombined::ReadImageData(unsigned int iImg)
{
    CImageCacheElement *pImgElem;
    unsigned int iFeature;
    char strPostfix[100];

    pImgElem = &(vectImageData[iImg]);

    if (pImgElem->bLoaded==true)
    {
        cout<<"Do not need to read feature images "<<iImg<<": already loaded"<<endl;
        return false;
    }

    if (pImgElem->vectFeatures.size()!=iNbLabels)
        pImgElem->vectFeatures.resize(iNbLabels);

    for (iFeature=0; iFeature<pImgElem->vectFeatures.size(); iFeature++)
    {
        pImgElem->vectFeatures[iFeature].create(iHeight, iWidth, CV_32F);
        sprintf(strPostfix, "_%03d.dat", iFeature);
        if (ReadImageIntOrFloat(pImgElem->vectFeatures[iFeature], (pImgElem->strFeatureImagesPath + strPostfix).c_str())==false)
        {
            cout<<"Cannot read feature image ("<<iImg<<","<<iFeature<<") to "<<pImgElem->strFeatureImagesPath + strPostfix<<endl;
            return false;
        }
    }

    if (bUseIntegralImages==true)
    {
        if (pImgElem->vectFeaturesIntegral.size()!=iNbLabels)
            pImgElem->vectFeaturesIntegral.resize(iNbLabels);

        for (iFeature=0; iFeature<pImgElem->vectFeaturesIntegral.size(); iFeature++)
        {
            pImgElem->vectFeaturesIntegral[iFeature].create(
                pImgElem->vectFeatures[iFeature].rows+1, pImgElem->vectFeatures[iFeature].cols+1, CV_32F);

            sprintf(strPostfix, "_%03d.dat", iFeature);
            if (ReadImageIntOrFloat(pImgElem->vectFeaturesIntegral[iFeature], (pImgElem->strFeatureImagesIntegralPath + strPostfix).c_str())==false)
            {
                cout<<"Cannot read feature image integral ("<<iImg<<","<<iFeature<<") to "<<pImgElem->strFeatureImagesIntegralPath + strPostfix<<endl;
                return false;
            }
        }
    }

    pImgElem->imgLabel = cv::imread(pImgElem->strLabelImagePath, cv::IMREAD_GRAYSCALE);
    if (pImgElem->imgLabel.data==NULL)
    {
        pImgElem->vectFeatures.clear();
        cout<<"Cannot read label image "<<iImg<<pImgElem->strLabelImagePath<<endl;
        return false;
    }

    return true;
}
コード例 #2
0
bool ImageDataFloat2ndStageCombined::ReadImageData(unsigned int iImg)
{
    CImageCacheElement *pImgElem;
    unsigned int iLabel, iIntegral;
    char strLabel[10];
    const char strPostfixes[6][10] = {"_one.dat", "_x.dat", "_y.dat", "_xx.dat", "_yy.dat", "_xy.dat"};
    string strFilename;

    pImgElem = &(vectImageData[iImg]);

    if (pImgElem->bLoaded==true)
    {
        cout<<"ImageDataFloat2ndStageCombined: Do not need to read feature images "<<iImg<<": already loaded"<<endl;
        return false;
    }

    if (pImgElem->vectFeaturesIntegral.size()!=6*NO_LABELS)
        pImgElem->vectFeaturesIntegral.resize(6*NO_LABELS);

    for (iLabel=0; iLabel<NO_LABELS; iLabel++)
    {
        sprintf(strLabel, "_%02d", iLabel);
        for (iIntegral=0; iIntegral<6; iIntegral++)
        {
            strFilename = pImgElem->strFeatureImagesIntegralPath + strLabel + strPostfixes[iIntegral];

            pImgElem->vectFeaturesIntegral[iLabel*6 + iIntegral].create(iHeight, iWidth, CV_32F);
            if (ReadImageIntOrFloat(pImgElem->vectFeaturesIntegral[iLabel*6 + iIntegral],
                strFilename.c_str())==false)
            {
                cout<<"ERROR in ImageDataFloat2ndStageCombined::ReadImageData(...):";
                cout<<" failed to load label integral image "<<strFilename<<endl;
                return false;
            }
        }
    }

    return true;
}