upgrade opencv to 3.3.1, complete patch similarity
[trackerpp.git] / src / PredictorWrapper.cpp
index 20fefc3..2dc7eb4 100644 (file)
@@ -18,11 +18,11 @@ const static std::string TAG = "PredictorWrapper";
 static std::string parse_python_exception();
 
 template <class T>
-boost::python::list toPythonList(std::vector<T> vector) {
+boost::python::list toPythonList(const std::vector<T>& v) {
     typename std::vector<T>::iterator iter;
     boost::python::list list;
-    for (iter = vector.begin(); iter != vector.end(); ++iter) {
-        list.append(*iter);
+    for(const auto& vv : v){
+        list.append(vv);
     }
     return list;
 }
@@ -51,16 +51,19 @@ void PredictorWrapper::dump()
     LOG_DEBUG(TAG, ss);
 }
 
-double PredictorWrapper::predict(int index, std::vector<double> ff)
+double PredictorWrapper::predict(int index, const std::vector<double>& ff)
 {
     LOG_DEBUG(TAG, "predict");
+    py::object ret;
     try{
-        this->predict_func(index, toPythonList(ff));
+        ret = this->predict_func(index, toPythonList(ff));
     } catch (boost::python::error_already_set const &){
         std::string perror_str = parse_python_exception();
         LOG_ERROR(TAG, "Error in Python: " + perror_str)
     }
-    return 0.1;
+    double rr = py::extract<double>(ret);
+    LOG_DEBUG(TAG, "return: " + std::to_string(rr));
+    return rr; 
 }
 
 PredictorWrapper::PredictorWrapper(const std::string& fname)