From 65ad5da72ca1e4ea276f9dd99d36521c2b46f558 Mon Sep 17 00:00:00 2001
From: Sebastian Gomez-Gonzalez <sebastian@robot-learning.de>
Date: Fri, 21 Jul 2017 10:49:34 +0200
Subject: [PATCH] Logistic regression now working

---
 examples/img_proc/log_reg_approach.cpp | 12 +++++++++---
 src/img_proc.cpp                       |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/examples/img_proc/log_reg_approach.cpp b/examples/img_proc/log_reg_approach.cpp
index d4a86b7..565e8fd 100644
--- a/examples/img_proc/log_reg_approach.cpp
+++ b/examples/img_proc/log_reg_approach.cpp
@@ -6,6 +6,7 @@
 #include <iostream>
 #include <boost/program_options.hpp>
 #include <json.hpp>
+#include <chrono>
 
 using namespace cv;
 using namespace std;
@@ -49,17 +50,22 @@ int main(int argc, char** argv) {
     imshow("Color", back);
     waitKey(0); 
     //Calculate the data with coefs
+    auto start_t = std::chrono::steady_clock::now();
     Mat im_proc = quadf_log_reg(img, back, model_coef);
-    cout << "pix data:" << im_proc.at<double>(340, 290) << endl 
+    auto end_t = std::chrono::steady_clock::now();
+    std::cout << "Computation took "
+              << std::chrono::duration_cast<std::chrono::milliseconds>(end_t - start_t).count() << 
+              " milliseconds" << endl;
+    /*cout << "pix data:" << im_proc.at<double>(340, 290) << endl 
       << im_proc.at<double>(342, 291) << endl 
       << im_proc.at<double>(290, 340) << endl
-      << im_proc.at<double>(2, 2)   << endl;
+      << im_proc.at<double>(2, 2)   << endl;*/
     MatIterator_<double> it_ans = im_proc.begin<double>(),end=im_proc.end<double>();
     //MatIterator_<Vec3b> it=im_proc.begin<Vec3b>(), end=im_proc.end<Vec3b>();
     while(it_ans != end){
       //cout << "pix data:" << *it_ans << endl;	
       double prob = 1.0 / (1.0 + exp(-*it_ans));
-      //*it_ans = 255*prob;
+     //*it_ans = 255*prob;
       *it_ans = (prob > 0.95) ? 255 : 0;
       it_ans++;
     }
diff --git a/src/img_proc.cpp b/src/img_proc.cpp
index b7a6d32..474871f 100644
--- a/src/img_proc.cpp
+++ b/src/img_proc.cpp
@@ -52,7 +52,7 @@ namespace ball_tracking {
         (*it_bkg)[0]/255.0, (*it_bkg)[1]/255.0, (*it_bkg)[2]/255.0, 1.0};
       double* wptr = w;
       for (unsigned int i=0; i<7; i++) {
-        for (unsigned int j=i; j<channels; j++, wptr++) {
+        for (unsigned int j=i; j<7; j++, wptr++) {
           sum += (*wptr) * lfeat[i] * lfeat[j];
         }
       }
-- 
GitLab