env.ParseConfig("python-config --cflags --libs")
env.Append(LIBS = ['pthread', 'boost_python'])
env['CCFLAGS'].remove('-Wstrict-prototypes') # invalid in C++
-env['CCFLAGS'].remove('-g') # invalid in C++
+env['CCFLAGS'].remove('-g')
env.Append(LIBPATH=['#.'])
class PredictorWrapper
{
public:
- static PredictorWrapperPtr create(const std::string& fname);
+ static PredictorWrapperPtr create(const std::string& python_dir, const std::string& model_dir); // model.pkl file
~PredictorWrapper(){}
void dump();
double predict(int index, const std::vector<double>& f);
private:
- PredictorWrapper(const std::string& fname);
+ PredictorWrapper(const std::string& py_dir, const std::string& fname);
static PredictorWrapperWPtr instance;
PY_FUN dump_func;
#include "Metrics.h"
#include "SharedPtr.h"
#include "MultiTracker.h"
+#include "Detector.h"
namespace suanzi {
void addPatch(PatchPtr p);
TrackerStatus status;
std::vector<PatchPtr> patches;
+ Detection detection;
private:
TrackerStatus preStatus;
static const std::string TAG = "MultiTracker";
static const cv::Size PREFERRED_SIZE = Size(64, 128);
-#define MaxCost 100000
+static const double MaxCost = 100000;
+static const int MaxPath = 5;
MultiTracker::MultiTracker(EngineWPtr e)
: engine(e)
{
LOG_DEBUG(TAG, "init - loading model.pkl");
- predictor = PredictorWrapper::create("./python/model.pkl");
+ predictor = PredictorWrapper::create("./python", "./python/model.pkl");
predictor->dump();
this->descriptor = {Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9};
-
- std::vector<double> ff (40, 1);
- double prob = predictor->predict(4, ff);
}
MultiTracker::~MultiTracker()
return feature;
}
-
double MultiTracker::distance(TrackerPtr tracker, const cv::Mat& image, const Detection& d)
{
PatchPtr patch = createPatch(image, d);
return prob;
}
-static long cc = 0;
+static float calc_iou_ratio(const Detection& d1, const Detection& d2)
+{
+ return calc_iou_ratio(getRectInDetection(d1), getRectInDetection(d2));
+}
void MultiTracker::update(unsigned int total, const Detection* detections, const Mat& image)
{
- //////
- if ((cc % 50) == 0){
- if (EnginePtr e = engine.lock()){
- e->onStatusChanged();
- }
- }
- cc++;
-
- //////
int row = trackers.size();
int col = total;
Eigen::MatrixXi cost_matrix = Eigen::MatrixXi::Zero(row, col);
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++){
- //if (calc_iou_ratio(trackers[i], detections[j]) < -0.1)
- // cost_matrix(i, j) = MaxCost;
- //else
+ if (calc_iou_ratio(trackers[i]->detection, detections[j]) < -0.1)
+ cost_matrix(i, j) = MaxCost;
+ else
cost_matrix(i, j) = distance(trackers[i], image, detections[j]);
}
}
PredictorWrapperWPtr PredictorWrapper::instance;
-const static std::string PREDICTOR_PY_DIR = "./python";
const static std::string TAG = "PredictorWrapper";
static std::string parse_python_exception();
return list;
}
-PredictorWrapperPtr PredictorWrapper::create(const std::string& fname)
+PredictorWrapperPtr PredictorWrapper::create(const std::string& python_dir, const std::string& model_path)
{
if (instance.lock()){
return PredictorWrapperPtr();
}
- PredictorWrapperPtr ins (new PredictorWrapper(fname));
+ PredictorWrapperPtr ins (new PredictorWrapper(python_dir, model_path));
instance = ins;
return ins;
}
void PredictorWrapper::dump()
{
LOG_DEBUG(TAG, "dump");
+ cout << "dump" << endl;
std::string ss = "";
try{
+ cout << "==== before" << endl;
py::object ret = this->dump_func();
ss = py::extract<std::string>(ret);
} catch (boost::python::error_already_set const &){
return rr;
}
-PredictorWrapper::PredictorWrapper(const std::string& fname)
+PredictorWrapper::PredictorWrapper(const std::string& py_dir, const std::string& model_path)
{
Py_Initialize();
try{
py::object main_module = py::import("__main__");
py::object main_namespace = main_module.attr("__dict__");
py::exec("import sys", main_namespace);
- std::string cmd = "sys.path.insert(0, '" + PREDICTOR_PY_DIR + "')";
+ std::string cmd = "sys.path.insert(0, '" + py_dir + "')";
py::exec(cmd.c_str(), main_namespace);
py::exec("import signal", main_namespace);
py::exec("signal.signal(signal.SIGINT, signal.SIG_DFL)", main_namespace);
py::object predictor_init = predictor_mod.attr("init");
dump_func = predictor_mod.attr("dump");
predict_func = predictor_mod.attr("predict");
- predictor_init(fname.c_str());
+ predictor_init(model_path.c_str());
} catch (boost::python::error_already_set const &){
std::string perror_str = parse_python_exception();
LOG_ERROR(TAG, "Error in Python: " + perror_str)
using namespace suanzi;
using namespace cv;
+using namespace std;
static const int MaxLost = 5;
else:
env1.Append(LIBPATH = ['#third_party/googletest/lib'])
-env1['LIBS'] = ['tracker', 'gtest', 'pthread']
-env1.ParseConfig("pkg-config --libs opencv")
+env1.Append(LIBS = ['gtest'])
+#env1['LIBS'] = ['tracker', 'gtest', 'pthread']
+#env1.ParseConfig("pkg-config --libs opencv")
+#env.ParseConfig("pkg-config --libs opencv log4cpp")
+#env.ParseConfig("python-config --cflags --libs")
obj = env1.Object(Glob("*.cpp"))
#include "gtest/gtest.h"
+#include "Logger.h"
int main(int argc, char** argv) {
// Disables elapsed time by default.
// This allows the user to override the flag on the command line.
::testing::InitGoogleTest(&argc, argv);
+ initLogger("../config/log4cpp.properties");
return RUN_ALL_TESTS();
}
--- /dev/null
+#include "gtest/gtest.h"
+#include "PredictorWrapper.h"
+
+using namespace suanzi;
+
+TEST(Predictor, load)
+{
+ PredictorWrapperPtr predictor = PredictorWrapper::create("../python", "../python/model.pkl");
+ predictor->dump();
+ std::vector<double> ff (40, 1);
+ double prob = predictor->predict(4, ff);
+}