Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 预期内存不足OpenCV C++;_C++_Opencv_Out Of Memory - Fatal编程技术网

C++ 预期内存不足OpenCV C++;

C++ 预期内存不足OpenCV C++;,c++,opencv,out-of-memory,C++,Opencv,Out Of Memory,实际上,我遇到了这个问题: OpenCV Error: Insufficient memory (Failed to allocate 225792004 bytes) in OutOfMemoryError, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/alloc.cpp, line 52 terminate called after throwing an instance of 'cv::Exception' what(

实际上,我遇到了这个问题:

OpenCV Error: Insufficient memory (Failed to allocate 225792004 bytes) in OutOfMemoryError, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/alloc.cpp, line 52
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/alloc.cpp:52: error: (-4) Failed to allocate 225792004 bytes in function OutOfMemoryError
当我从
main
调用以下方法时。。我在
listOfImages

void MainHelper::startProcessingDataSampleForROCCurve(bool downSampleData)
{
    /*Step 5: Load test data*/
    vector <Mat> imagesToTest;

    ///Looping over the segmented to validate the method we did
    Diagnostics diagnoLearningAndTesting;
    WindowsDataSet windowsDataSetInstance;
    map <int , vector < double > > areaCalculatedPerImageForEachK;
    for (int indexImage = 0; indexImage < listOfImages.size(); indexImage++)
    {
        Mat imageTestForIteration = listOfImages[indexImage];
        imagesToTest.push_back(imageTestForIteration);
        Mat imageTestBinaryForIteration = listOfBinaryImages[indexImage];

        //Prepare the learning image list by removing only the image for testing
        vector<Mat> listOfLearningImages(listOfImages.begin(),listOfImages.end());
        listOfLearningImages.erase(listOfLearningImages.begin() + indexImage);
        vector<Mat> listOfBinaryLearningImages(listOfBinaryImages.begin(),listOfBinaryImages.end());
        listOfBinaryLearningImages.erase(listOfBinaryLearningImages.begin() + indexImage);

        /*Step 7: Processing the images by having a vector of descriptor for every window in the image*/
        ImageProcessingManager imageManager;
        map <int , vector< vector<double> > > dictWindowPerFeaturesPerTile;
//        map <int , vector< vector<Mat> > > dictTilesPerLearningImage;
        map <int , vector< int > > dictAnnotationPerTile;


        diagnoLearningAndTesting.startMethod(StringUtils::stringFormat("Learning Part.. %d",(indexImage + 1)));
        for (int indexWindowLength = 0; indexWindowLength < Constants::windowsSize.size(); indexWindowLength ++)
        {
            int windowLength = Constants::windowsSize[indexWindowLength];
            vector < int > annotationPerTile;
            //TODO: It won't be filled for now for memory reasons
            vector < vector <Mat> > tilesPerLearningImage;
            vector < vector <double> > featuresPerTile = imageManager.processImagesInWindowsWithFeatures(listOfLearningImages, listOfBinaryLearningImages, tilesPerLearningImage, annotationPerTile, windowLength, Constants::percentageOfWhiteToConsiderIntrumentWindow);
            dictWindowPerFeaturesPerTile[windowLength] = featuresPerTile;
//            dictTilesPerLearningImage[windowLength] = tilesPerLearningImage;
            dictAnnotationPerTile[windowLength] = annotationPerTile;
        }
        diagnoLearningAndTesting.endMethod();
        MemoryUtils::displayMemoryUsage();


        diagnoLearningAndTesting.startMethod(StringUtils::stringFormat("Testing Part.. %d",(indexImage + 1)));
        //TODO: Change the value of the param here..
        for (int kNearestNeighbor = 2; kNearestNeighbor <= Constants::kNearestNeighbor; kNearestNeighbor ++)
        {
            Diagnostics::LogWithTime(StringUtils::stringFormat("*** Running annotations with K = %d", kNearestNeighbor));

            if (Constants::hierarchyWindowLevel == Multiple)
            {
                for (int indexOfImage = 0; indexOfImage < imagesToTest.size(); indexOfImage ++)
                {
                    Mat image = imagesToTest[indexOfImage];
                    vector <Mat> testImagesInVect = boost::assign::list_of(image);

                    Mat binaryResultOfImageTest(image.rows, image.cols, CV_8UC1, Scalar(0.));
                    vector <Mat> binaryTestImagesInVect = boost::assign::list_of(binaryResultOfImageTest);

                    for (int indexWindowLength = 0; indexWindowLength < Constants::windowsSize.size(); indexWindowLength ++)
                    {
                        int windowLength = Constants::windowsSize[indexWindowLength];
                        Diagnostics::LogWithTime(StringUtils::stringFormat("Running annotations with windowLength = %d", windowLength));

                        /*Step 7-1: Learning vectors already loaded */
                        vector < int > annotationPerTile = dictAnnotationPerTile[windowLength];
//                        vector < vector <Mat> > tilesPerLearningImage = dictTilesPerLearningImage[windowLength];
                        vector < vector <double> > featuresPerTile = dictWindowPerFeaturesPerTile[windowLength];

                        /*Step 8: Processing the samples on which we need to make our tests by having a vector of descriptor for every window in the image*/
                        //TODO: GET THE BINARY VERSION OF THE IMAGES******
                        vector< vector <int> > annotationPerImageForTiles;
                        vector < vector <Mat> > tilesPerTestImage;
                        vector < vector < vector <double> > > featuresPerTiles = imageManager.processSetOfImages(testImagesInVect, vector<Mat>(), tilesPerTestImage, windowLength, Constants::percentageOfWhiteToConsiderIntrumentWindow, annotationPerImageForTiles);
                        vector < vector <Mat> > binaryTiles = imageManager.divideBinaryImagesInTiles(binaryTestImagesInVect, windowLength);

                        /*Step 9: Knn Classifier train data */
                        Mat trainData = VectorUtility <double>::toMat(featuresPerTile);
                        Mat dataClasses = VectorUtility <int>::toMat(annotationPerTile);
                        ClassifierManager classifier(trainData, dataClasses, kNearestNeighbor);

                        /*Step 10: Annotation Step*/
                        vector < vector <int> > resultsForEachTilePerImage = classifier.annotateTheTilesInImages(featuresPerTiles);

                        /*Step 10-1: Annotation Step with window hierarchy: Extract tiles which have probability > 0*/
                        vector <Mat> instrumentTiles;
                        vector <Mat> instrumentBinaryTiles;
                        for (int resultIndex = 0; resultIndex < resultsForEachTilePerImage.size(); resultIndex ++)
                        {
                            vector <int> resultsForTilePerImage = resultsForEachTilePerImage[resultIndex];
                            vector <Mat> tilesPerImage = tilesPerTestImage[resultIndex];
                            vector <Mat> tilesPerBinaryImage = binaryTiles[resultIndex];
                            for (int resultIndex = 0; resultIndex < resultsForTilePerImage.size(); resultIndex ++)
                            {
                                int result = resultsForTilePerImage[resultIndex];
                                if (result > 0)
                                {
                                    Mat tile = tilesPerImage[resultIndex];
                                    instrumentTiles.push_back(tile);
                                    Mat binaryTile = tilesPerBinaryImage[resultIndex];
                                    instrumentBinaryTiles.push_back(binaryTile);

                                    if (indexWindowLength == Constants::windowsSize.size() - 1)
                                    {
                                        int valueOfPixel = (result * 255) / 100;
                                        //This region should be set to valueOfPixel..
                                        binaryTile.setTo(valueOfPixel);
                                    }
                                }
                            }
                        }
                        testImagesInVect = instrumentTiles;
                        binaryTestImagesInVect = instrumentBinaryTiles;

                        //Release objects for memory reasons..
                        resultsForEachTilePerImage.clear();
                        tilesPerTestImage.clear();binaryTiles.clear();
                        trainData.release();dataClasses.release();
                        featuresPerTiles.clear();
                    }

                    /*Step 11: Draw images with the regions of interest we want*/
                    string imagePrefix = StringUtils::stringFormat("%sM-ImageResult%d-k%d-WL", Constants::pathOfResultImages.c_str(), indexImage,kNearestNeighbor);
                    for (int indexWindowLength = 0; indexWindowLength < Constants::windowsSize.size(); indexWindowLength ++)
                    {
                        imagePrefix = StringUtils::concat(imagePrefix, numberToString(Constants::windowsSize[indexWindowLength]));
                    }
                    string imageName = StringUtils::stringFormat("%s.png", imagePrefix.c_str());
                    imwrite(imageName, binaryResultOfImageTest);

                    if (Constants::generateROCCurve)
                    {
                        /*Step 12: Validation steps by showing the percentage of accuracy of this method (ROC courbe)*/
                        double areaOfAZ = windowsDataSetInstance.ROCCurveFor(imageTestBinaryForIteration, binaryResultOfImageTest, image, Constants::pathOfResultImages, StringUtils::stringFormat("%d-k%d.txt",indexImage, kNearestNeighbor), kNearestNeighbor);
                        vector <double> listOfAreasCalculated = areaCalculatedPerImageForEachK[kNearestNeighbor];
                        listOfAreasCalculated.push_back(areaOfAZ);
                        areaCalculatedPerImageForEachK[kNearestNeighbor] = listOfAreasCalculated;
                    }

                }

            }
        }

        //Clear Objects for memory reasons
        dictAnnotationPerTile.clear();dictWindowPerFeaturesPerTile.clear();
        listOfLearningImages.clear();listOfBinaryLearningImages.clear();

        diagnoLearningAndTesting.endMethod();

        //Clear all elements of imagesToTest
        imagesToTest.clear();
        MemoryUtils::displayMemoryUsage();

    }


    //Step #12: Additional step to display the mean and standard variation of the list of Areas calculated for each value of K
    for (std::map<int, vector <double> >::iterator it = areaCalculatedPerImageForEachK.begin(); it != areaCalculatedPerImageForEachK.end(); ++it)
    {
        vector < double> areas = it->second;
        double mean = VectorUtility<double>::mean(areas);
        double std = VectorUtility<double>::standardDeviation(areas, mean);

        Diagnostics::LogWithTime(StringUtils::stringFormat("******* For K = %d : Mean(Az) = %f, Std(Az) = %f",it->first, mean, std));
    }
}
void main helper::startProcessingDataSampleForROCCurve(bool downSampleData)
{
/*步骤5:负载测试数据*/
向量成像测试;
///在分段上循环以验证我们所做的方法
诊断、诊断和测试;
WindowsDataSet windowsDataSetInstance;
地图>面积计算PerimageForeachk;
对于(int indexImage=0;indexImagedictWindowPerFeaturesPerTile;
//地图>dictTilesPerLearningImage;
map>dictannotationperfile;
诊断学习和测试.startMethod(StringUtils::stringFormat(“学习部分..%d),(索引+1));
对于(int indexWindowLength=0;indexWindowLength注释属性文件;
//TODO:由于内存原因,暂时不会填充
向量<向量>TileSperLearning图像;
vectorFeaturesPartile=imageManager.ProcessImagesInWindowWithFeatures(学习图像列表、二元学习图像列表、tilesPerLearningImage、注释属性文件、窗口长度、常量::whiteToConsiderIntrumentWindow的百分比);
dictWindowPerFeaturesPerTile[windowLength]=功能部件;
//dictTilesPerLearningImage[窗口长度]=tilesPerLearningImage;
dictAnnotationPerTile[windowLength]=注释性PERTILE;
}
诊断学习和测试。endMethod();
MemoryUtils::displayMemoryUsage();
诊断学习和测试.startMethod(StringUtils::stringFormat(“测试部分..%d”,(索引+1));
//TODO:在此处更改参数的值。。
for(int-kNearestNeighbor=2;kNearestNeighbor-annotationPerTile=dictAnnotationPerTile[windowLength];
//vectortilesPerLearningImage=dictTilesPerLearningImage[windowLength];
vectorfeaturesPerTile=dictWindowPerFeaturesPerTile[windowLength];
/*步骤8:通过为图像中的每个窗口提供描述符向量来处理需要进行测试的样本*/
//TODO:获取图像的二进制版本******
矢量注释PerimageFortiles;
向量tilesPerTestImage;
vector>FeaturesPartiles=imageManager.processSetOfImages(testImagesInVect,vector(),TilesPertTestImages,windowLength,Constants::WhiteToConsiderIntrumentWindow的百分比,annotationPerImageForTiles);
vectorbinaryTiles=imageManager.divideBinaryImagesInTiles(binaryTestImagesInVect,windowLength);
/*步骤9:Knn分类器序列数据*/
Mat trainData=矢量实用程序::toMat(功能部件);
Mat dataClasses=VectorUtility::toMat(annotationperfile);
分类器管理器分类器(列车数据、数据类、kNearestNeighbor);
/*步骤10:注释步骤*/
vectorresultsForEachTilePerImage=分类器。注释文档图像(FeaturesParties);
/*步骤10-1:窗口层次结构的注释步骤:提取概率大于0的分幅*/
矢量仪器;
向量二值化;
对于(int-resultIndex=0;resultIndex0)
{
Mat tile=tilesPerImage[结果索引];
仪器瓷砖。推回(瓷砖);
Mat binaryTile=tilesPerBinaryImage[resultIndex];
instrumentBinaryTiles.向后推(binaryTile);
如果(indexWindowLength==常数::windowsSize.size()-1)
{
像素的int值=(结果*255)/100;
//此区域应设置为valueOfPixel。。
设置为(像素值);
}
Mat image = imagesToTest[indexOfImage];
Mat a;
{
    Mat b;
    // ... do some stuff
} // Mat b won't exists any more after here
// Mat a still exists