]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Merge branch 'master' into rotation
authorShanigen <32431880+Shanigen@users.noreply.github.com>
Thu, 13 Sep 2018 19:02:50 +0000 (21:02 +0200)
committerGitHub <noreply@github.com>
Thu, 13 Sep 2018 19:02:50 +0000 (21:02 +0200)
1  2 
main_vot.cpp
src/CMakeLists.txt
src/kcf.cpp

diff --cc main_vot.cpp
index 528d263e678a3fc3110856a1ae5bd53c13cc1530,38aa35d28818aae3560f644ff335f80e0cd6e16e..711a00045065ae9060ca9e9a55135ef315777246
@@@ -171,49 -173,35 +175,49 @@@ int main(int argc, char *argv[]
          std::cout << std::endl;
  
          if (visualize_delay >= 0) {
 -            cv::rectangle(image, bb_rect, CV_RGB(0,255,0), 2);
 +            cv::Point pt(bb.cx, bb.cy);
 +            cv::Size size(bb.w, bb.h);
 +            cv::RotatedRect rotatedRectangle(pt, size, bb.a);
 +
 +            cv::Point2f vertices[4];
 +            rotatedRectangle.points(vertices);
 +
 +            for (int i = 0; i < 4; i++)
 +                cv::line(image, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 255, 0), 2);
 +            //             cv::rectangle(image, cv::Rect(bb.cx - bb.w/2., bb.cy - bb.h/2., bb.w, bb.h), CV_RGB(0,255,0),
 +            //             2);
 +            std::string angle = std::to_string(bb.a);
 +            angle.erase(angle.find_last_not_of('0') + 1, std::string::npos);
 +            angle.erase(angle.find_last_not_of('.') + 1, std::string::npos);
 +            cv::putText(image, "Frame: " + std::to_string(frames) + " " + angle + " angle",
 +                        cv::Point(0, image.rows - 1), cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(0, 255, 0), 2);
              cv::imshow("output", image);
              int ret = cv::waitKey(visualize_delay);
 -            if (visualize_delay > 0 && ret != -1 && ret != 255)
 -                break;
 +            if (visualize_delay > 0 && ret != -1 && ret != 255) break;
          }
  
 -//        std::stringstream s;
 -//        std::string ss;
 -//        int countTmp = frames;
 -//        s << "imgs" << "/img" << (countTmp/10000);
 -//        countTmp = countTmp%10000;
 -//        s << (countTmp/1000);
 -//        countTmp = countTmp%1000;
 -//        s << (countTmp/100);
 -//        countTmp = countTmp%100;
 -//        s << (countTmp/10);
 -//        countTmp = countTmp%10;
 -//        s << (countTmp);
 -//        s << ".jpg";
 -//        s >> ss;
 -//        //set image output parameters
 -//        std::vector<int> compression_params;
 -//        compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
 -//        compression_params.push_back(90);
 -//        cv::imwrite(ss.c_str(), image, compression_params);
 +        //        std::stringstream s;
 +        //        std::string ss;
 +        //        int countTmp = frames;
 +        //        s << "imgs" << "/img" << (countTmp/10000);
 +        //        countTmp = countTmp%10000;
 +        //        s << (countTmp/1000);
 +        //        countTmp = countTmp%1000;
 +        //        s << (countTmp/100);
 +        //        countTmp = countTmp%100;
 +        //        s << (countTmp/10);
 +        //        countTmp = countTmp%10;
 +        //        s << (countTmp);
 +        //        s << ".jpg";
 +        //        s >> ss;
 +        //        //set image output parameters
 +        //        std::vector<int> compression_params;
 +        //        compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
 +        //        compression_params.push_back(90);
 +        //        cv::imwrite(ss.c_str(), image, compression_params);
      }
  
-     std::cout << "Average processing speed: " << avg_time/frames <<  "ms (" << 1./(avg_time/frames)*1000 << " fps)";
+     std::cout << "Average processing speed: " << avg_time / frames << "ms (" << 1. / (avg_time / frames) * 1000 << " fps)";
      if (groundtruth_stream.is_open()) {
          std::cout << "; Average accuracy: " << sum_accuracy/frames << std::endl;
          groundtruth_stream.close();
Simple merge
diff --cc src/kcf.cpp
index b32532766901e76e536e9d7d7ca5f08e10518c03,fa2aa5c1c6f9518f7dfb602e4d1c3480a2b9ac31..57a7447410463b449d8b70eb314953a0c5310b16
@@@ -789,53 -726,10 +790,49 @@@ cv::Mat KCF_Tracker::get_subwindow(cons
      return patch;
  }
  
 -void KCF_Tracker::gaussian_correlation(struct ThreadCtx &vars, const ComplexMat &xf, const ComplexMat &yf,
 -                                       double sigma, bool auto_correlation)
 +void KCF_Tracker::geometric_transformations(cv::Mat &patch, int size_x, int size_y, int angle, bool allow_debug)
 +{
 +    if (m_use_angle) {
 +        cv::Point2f center((patch.cols - 1) / 2., (patch.rows - 1) / 2.);
 +        cv::Mat r = cv::getRotationMatrix2D(center, angle, 1.0);
 +
 +        cv::warpAffine(patch, patch, r, cv::Size(patch.cols, patch.rows), cv::INTER_LINEAR, cv::BORDER_REPLICATE);
 +    }
 +
 +    // resize to default size
 +    if (patch.channels() != 3) {
 +        if (patch.cols / size_x > 1.) {
 +            // if we downsample use  INTER_AREA interpolation
 +            cv::resize(patch, patch, cv::Size(size_x, size_y), 0., 0., cv::INTER_AREA);
 +        } else {
 +            cv::resize(patch, patch, cv::Size(size_x, size_y), 0., 0., cv::INTER_LINEAR);
 +        }
 +    } else {
 +        if (patch.cols / size_x > 1.) {
 +            // if we downsample use  INTER_AREA interpolation
 +            cv::resize(patch, patch, cv::Size(size_x / p_cell_size, size_y / p_cell_size), 0., 0., cv::INTER_AREA);
 +        } else {
 +            cv::resize(patch, patch, cv::Size(size_x / p_cell_size, size_y / p_cell_size), 0., 0., cv::INTER_LINEAR);
 +        }
 +        if (m_visual_debug && allow_debug) {
 +            cv::Mat input_clone = patch.clone();
 +            cv::resize(input_clone, input_clone, cv::Size(p_debug_image_size, p_debug_image_size), 0., 0.,
 +                       cv::INTER_LINEAR);
 +
 +            std::string angle_string = std::to_string(p_current_angle + angle);
 +
 +            cv::putText(input_clone, angle_string, cv::Point(1, input_clone.rows - 5), cv::FONT_HERSHEY_COMPLEX_SMALL,
 +                        0.5, cv::Scalar(0, 255, 0), 1);
 +
 +            p_debug_subwindows.push_back(input_clone);
 +        }
 +    }
 +}
 +
 +void KCF_Tracker::gaussian_correlation(struct ThreadCtx &vars, const ComplexMat &xf, const ComplexMat &yf, double sigma,
 +                                       bool auto_correlation)
  {
- #ifdef CUFFT
-     xf.sqr_norm(vars.xf_sqr_norm.deviceMem());
-     if (!auto_correlation) yf.sqr_norm(vars.yf_sqr_norm.deviceMem());
- #else
-     xf.sqr_norm(vars.xf_sqr_norm.hostMem());
+     xf.sqr_norm(vars.xf_sqr_norm);
      if (auto_correlation) {
          vars.yf_sqr_norm.hostMem()[0] = vars.xf_sqr_norm.hostMem()[0];
      } else {