Ejemplo n.º 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);
    }
}
Ejemplo n.º 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);
    }
}
Ejemplo n.º 3
0
ImageAnnotation getFlipedAnnotation(const ImageAnnotation & ann,
                                    const SourcesMap & sources)
{
    ImageAnnotation flipedAnn;
    for (size_t i = 0; i < ann.bboxes.size(); ++i)
    {
        if (ann.labels[i] == 0)
        {
            continue;
        }
        flipedAnn.labels.push_back(ann.labels[i]);
        flipedAnn.scores.push_back(ann.scores[i]);
        Rect bbox = ann.bboxes[i];
        Size imageSize = sources.at(DataTypeTime("image", 0)).size();
        bbox.x = imageSize.width - bbox.x - bbox.width;
        flipedAnn.bboxes.push_back(bbox);
    }
    return flipedAnn;
}