Example #1
0
void HOF::getROIDescription(Mat & featureDescription,
                            const SourcesMap & sources,
                            const vector<Rect> & roi)
{
    bool hasOpticalFlowAsSource = (0 < sources.count(SOURCE_OPTICAL_FLOW));
    bool hasImagesPairAsSource = (0 < sources.count(SOURCE_FIRST_IMAGE) &&
                                  0 < sources.count(SOURCE_SECOND_IMAGE));
    CV_Assert(hasImagesPairAsSource || hasOpticalFlowAsSource);
    
    Mat opticalFlow;
    if (hasOpticalFlowAsSource)
    {
        opticalFlow = sources.at(SOURCE_OPTICAL_FLOW);
    }
    else // if (hasImagesPairAsSource)
    {
        Mat image1, image2;
        cvtColor(sources.at(SOURCE_FIRST_IMAGE), image1, CV_BGR2GRAY);
        cvtColor(sources.at(SOURCE_SECOND_IMAGE), image2, CV_BGR2GRAY);
        opticalFlowComputer->calc(image1, image2, opticalFlow);
    }

    featureDescription.create(roi.size(), featureVectorLength, CV_32F);

    for (size_t t = 0; t < roi.size(); ++t)
    {
        const Rect & r = roi[t];
        CV_Assert(0 < r.width);
        CV_Assert(0 < r.height);
        Mat opticalFlowROI;
        getROI(opticalFlow, opticalFlowROI, r);
        resize(opticalFlowROI, opticalFlowROI,
               Size(params.winSizeW, params.winSizeH));

        SourcesMap imageSource;
        imageSource[SOURCE_OPTICAL_FLOW] = opticalFlowROI;
        computeOnNewImage(imageSource);
        computeOnNewScale(1.0f);
        Mat featureDescriptionRow = featureDescription.row(t);
        getFeatureVector(0, 0, featureDescriptionRow);
    }
}
Example #2
0
void HOF::computeOnNewImage(const SourcesMap & sources)
{
    bool hasOpticalFlowAsSource = (0 < sources.count(SOURCE_OPTICAL_FLOW));
    bool hasImagesPairAsSource = (0 < sources.count(SOURCE_FIRST_IMAGE) &&
                                  0 < sources.count(SOURCE_SECOND_IMAGE));

    CV_Assert(hasOpticalFlowAsSource || hasImagesPairAsSource);
    if (hasOpticalFlowAsSource)
    {
        sources.at(SOURCE_OPTICAL_FLOW).copyTo(flow);
    }
    else if (hasImagesPairAsSource)
    {
        Mat firstImage;
        cvtColor(sources.at(SOURCE_FIRST_IMAGE), firstImage, CV_BGR2GRAY);
        cvtColor(sources.at(SOURCE_SECOND_IMAGE), secondImage, CV_BGR2GRAY);
        CV_Assert(firstImage.size == secondImage.size);
        opticalFlowComputer->calc(firstImage, secondImage, flow);
    }
}