void FeatureTrackerKLTCv::addPointsFromRegion(const cv::Mat &img,const cv::Rect& roi)
{
    cv::Mat imgGray;
    cv::cvtColor(img, imgGray, CV_BGR2GRAY);

    double qualityLevel = 0.05;
    double minDistance = 5.0;
    int maxCorners = 20;
    std::vector<cv::Point2f> points;
    goodFeaturesToTrack(imgGray(roi),points,maxCorners,qualityLevel,minDistance);
    //the points are wrt roi axis. Convert to img axis.
    for(cv::Point2f& p : points){
        p.x+=roi.x;
        p.y+=roi.y;
        this->addPointToTrack(p);
    }


}
void NormalizedPatchModel::addAppearance(cv::Mat& img, const cv::Rect &detBox)
{
    cv::Mat imgGray;
    if ( img.channels() == 3 ) //BGR image?
        cv::cvtColor( img, imgGray, CV_BGR2GRAY );
    else if ( img.channels() == 1 )
        imgGray = img.clone();
    else
        throw std::runtime_error("Error in NormalizedPatchModel::extract: image type not supported");

    cv::Mat roi;
    if ( detBox == cv::Rect() )
        roi = imgGray;
    else
        roi = imgGray(detBox);

    cv::Mat patch;

//  std::cout << "input image size w: " << img.size().width << " h: " << img.size().height << std::endl;
//  std::cout << "roi         size w: " << detBox.width << " h: " << detBox.height << std::endl;
//  std::cout << "image crop  size w: " << roi.size().width << " h: " << roi.size().height << std::endl;

    cv::resize(roi, patch, cv::Size(_normalizedWidth, _normalizedHeight));

//  cv::namedWindow("patch");
//  cv::imshow("patch", patch);
//  cv::waitKey(0);

    //std::cout << "patch  size w: " << patch.size().width << " h: " << patch.size().height << std::endl;

    patchVector patchVector;
    imgToVector(patch, patchVector);

    //float m = mean(patchVector);
    //float s = stdDev(patchVector, m);

    normalize(patchVector, patchVector);

    _appearances.push_back(patchVector);

}