Fix nan issue in features
[trackerpp.git] / src / Utils.cpp
index c174e28..df6802b 100644 (file)
@@ -1,10 +1,16 @@
 #include "Utils.h"
+#include <iostream>
+#include <stdexcept>
 
 using namespace suanzi;
 using namespace cv;
+using namespace std;
 
 double distance_cosine(const Eigen::VectorXd& u, const Eigen::VectorXd& v)
 {
+    if (u.dot(u) * v.dot(v) == 0){
+        throw overflow_error("zero vector for cosine distance");
+    }
     return (1 - u.dot(v) / std::sqrt(u.dot(u) * v.dot(v)));
 }