Пример #1
0
    // Prediction
    //  Accepts a single integral image/channel, thus only to be used for testing
    //  Assumes that predPtr is already allocated, of same size as imgPtr
    DLL_EXPORT
    void predictWithChannel( void *modelPtr, ImagePixelType *imgPtr,
                              IntegralImagePixelType *chImgPtr,
                              int width, int height, int depth,
                              PredictionPixelType *predPtr )
    {
        Matrix3D<PredictionPixelType> predMatrix;
        predMatrix.fromSharedData( predPtr, width, height, depth );

        // create roi for image, no GT available
        ROIData roi;
        roi.init( imgPtr, 0, 0, 0, width, height, depth );

        // get the precomputed integral images
        ROIData::IntegralImageType ii;
        ii.fromSharedData(chImgPtr, width, height, depth);
        roi.addII( ii.internalImage().data() );

        MultipleROIData allROIs;
        allROIs.add( shared_ptr_nodelete(ROIData, &roi) );

        Booster adaboost;
        adaboost.setModel( *((BoosterModel *) modelPtr) );

        adaboost.predict<false>( allROIs, &predMatrix );
    }
Пример #2
0
    // input: multiple imgPtr, gtPtr (arrays of pointers)
    //          multiple img sizes
    // returns a BoosterModel *
    // -- BEWARE: this function is a mix of dirty tricks right now
    DLL_EXPORT
    void * trainWithChannels( ImagePixelType **imgPtr, 
                             void **evecPtr,
                             GTPixelType **gtPtr,
                             int *width, int *height, int *depth,
                             int numStacks,
                             IntegralImagePixelType **chImgPtr,
                             int numChannels, double zAnisotropyFactor,
                             int numStumps,
                             int gtNegativeLabel, int gtPositiveLabel,
                             int debugOutput )
    {

        BoosterModel *modelPtr = 0;

        try
        {
            std::unique_ptr<ROIData[]> rois(new ROIData[numStacks]);  // TODO: remove
            MultipleROIData allROIs;
            std::unique_ptr<ROIData::IntegralImageType[]> ii(new ROIData::IntegralImageType[numStacks*numChannels]);  // TODO: remove

            for (int i=0; i < numStacks; i++)
            {
                rois[i].setGTNegativeSampleLabel(gtNegativeLabel);
                rois[i].setGTPositiveSampleLabel(gtPositiveLabel);
                rois[i].init( imgPtr[i], gtPtr[i], 0, 0, width[i], height[i], depth[i], 
                              zAnisotropyFactor, 0.0, (const ROIData::RotationMatrixType *) evecPtr[i] );

                for (int ch=0; ch < numChannels; ch++)
                {
                   ii[i*numChannels+ch].fromSharedData(chImgPtr[i*numChannels+ch], width[i], height[i], depth[i]);

                   rois[i].addII( ii[i*numChannels+ch].internalImage().data() );
                }

                allROIs.add( shared_ptr_nodelete(ROIData, &rois[i]) );
            }

            BoosterInputData bdata;
            bdata.init( shared_ptr_nodelete(MultipleROIData, &allROIs) );
            bdata.showInfo();

            Booster adaboost;
            adaboost.setShowDebugInfo( debugOutput != 0 );

            adaboost.train( bdata, numStumps );

            // create by copying
            modelPtr = new BoosterModel( adaboost.model() );
        }
        catch( std::exception &e )
        {
            printf("Error training: %s\n", e.what());
            delete modelPtr;

            return 0;
        }

        return modelPtr;
    }
Пример #3
0
    // Prediction for a single ROI
    //  Accepts an arbitrary number of integral images/channels.
    //  Assumes that predPtr is already allocated, of same size as imgPtr
    //  Returns 0 if ok
    DLL_EXPORT
    int predictWithChannels( void *modelPtr, ImagePixelType *imgPtr,
                              void *eigVecImgPtr,
                              int width, int height, int depth,
                              IntegralImagePixelType **chImgPtr,
                              int numChannels, double zAnisotropyFactor,
                              int useEarlyStopping,
                              int useROI, int x1, int y1, int z1, int x2, int y2, int z2, // used only if useROI != 0
                              PredictionPixelType *predPtr )
    {
        Matrix3D<PredictionPixelType> predMatrix;
        predMatrix.fromSharedData( predPtr, width, height, depth );

        // create roi for image, no GT available
        ROIData roi;
        roi.init( imgPtr, 0, 0, 0, width, height, depth, zAnisotropyFactor, 0.0, (const ROIData::RotationMatrixType *) eigVecImgPtr );
        std::unique_ptr<ROIData::IntegralImageType[]> ii(new ROIData::IntegralImageType[numChannels]);  // TODO: remove

        for (int ch=0; ch < numChannels; ch++)
        {
           ii[ch].fromSharedData(chImgPtr[ch], width, height, depth);

           roi.addII( ii[ch].internalImage().data() );
        }

        MultipleROIData allROIs;
        allROIs.add( shared_ptr_nodelete(ROIData, &roi) );

        try
        {
            Booster adaboost;
            adaboost.setModel( *((BoosterModel *) modelPtr) );
            if(useEarlyStopping != 0)
            {
                if (useROI)
                {
                    ROICoordinates subROI;
                    subROI.x1 = x1; subROI.y1 = y1; subROI.z1 = z1;
                    subROI.x2 = x2; subROI.y2 = y2; subROI.z2 = z2;
                    
                    adaboost.predictWithFeatureOrdering<true>( allROIs, &predMatrix, 0, IIBOOST_NUM_THREADS, &subROI );
                }
                else
                    adaboost.predictWithFeatureOrdering<true>( allROIs, &predMatrix );
            }
            else
                adaboost.predictWithFeatureOrdering<false>( allROIs, &predMatrix );
        }
        catch( std::exception &e )
        {
            printf("Error in prediction: %s\n", e.what());
            return -1;
        }

        return 0;
    }
Пример #4
0
    // input: multiple imgPtr, gtPtr (arrays of pointers)
    //        multiple img sizes
    // returns a BoosterModel *
    // -- BEWARE: this function is a mix of dirty tricks right now
    DLL_EXPORT
    void * train( ImagePixelType **imgPtr, GTPixelType **gtPtr, 
                  int *width, int *height, int *depth,
                  int numStacks,
                  int numStumps, int debugOutput )
    {
        BoosterModel *modelPtr = 0;

        try
        {
            std::unique_ptr<ROIData[]> rois(new ROIData[numStacks]);  // TODO: remove
            std::unique_ptr<ROIData::IntegralImageType[]> ii(new ROIData::IntegralImageType[numStacks]);  // TODO: remove
            MultipleROIData allROIs;

            for (int i=0; i < numStacks; i++)
            {
                rois[i].init( imgPtr[i], gtPtr[i], 0, 0, width[i], height[i], depth[i] );

                // raw image to integral image
                // TODO: this should be removed and passed directly to train()
                ii[i].compute( rois[i].rawImage );
                rois[i].addII( ii[i].internalImage().data() );

                allROIs.add( shared_ptr_nodelete(ROIData, &rois[i]) );
            }

            BoosterInputData bdata;
            bdata.init( shared_ptr_nodelete(MultipleROIData, &allROIs) );
            bdata.showInfo();

            Booster adaboost;
            adaboost.setShowDebugInfo( debugOutput != 0 );

            adaboost.train( bdata, numStumps );

            // create by copying
            modelPtr = new BoosterModel( adaboost.model() );
        }
        catch( std::exception &e )
        {
            printf("Error training: %s\n", e.what());
            delete modelPtr;
            
            return 0;
        }

        return modelPtr;
    }
Пример #5
0
    DLL_EXPORT
    int predictIndividualWeakLearnersWithChannels( void *modelPtr, ImagePixelType *imgPtr,
                                                   void *eigVecImgPtr,
                                                   int width, int height, int depth,
                                                   IntegralImagePixelType **chImgPtr,
                                                   int numChannels, double zAnisotropyFactor,
                                                   WLPredictionPixelType **predPtr)
    {
        BoosterModel* model = static_cast<BoosterModel*>(modelPtr);
        
        int numWL = model->size();
        Matrix3D<WLPredictionPixelType> predMatrix[numWL]; // TODO: remove
        for(int i=0; i < numWL; ++i)
            predMatrix[i].fromSharedData(predPtr[i], width, height, depth);
        
        // create roi for image, no GT available
        ROIData roi;
        roi.init( imgPtr, 0, 0, 0, width, height, depth, zAnisotropyFactor, 0.0, (const ROIData::RotationMatrixType *) eigVecImgPtr );
        ROIData::IntegralImageType ii[numChannels];  // TODO: remove

        for (int ch=0; ch < numChannels; ch++)
        {
           ii[ch].fromSharedData(chImgPtr[ch], width, height, depth);

           roi.addII( ii[ch].internalImage().data() );
        }

        MultipleROIData allROIs;
        allROIs.add( shared_ptr_nodelete(ROIData, &roi) );

        try
        {
            Booster adaboost;
            adaboost.setModel(*model);
            adaboost.predictIndividualWeakLearners(allROIs, predMatrix);
        }
        catch( std::exception &e )
        {
            printf("Error in prediction: %s\n", e.what());
            return -1;
        }

        return 0;
    }