### Run
`./main`
+
+
+## Build with `scons`
+install scons tool `apt-get install scons`
+
+- Run `scons` to build the `src/` and `main`. It will generate a library
+`libtracker.a` and an executable file `main` under current folder.
+
+- Run `scons --all` to build source and `test` file. A executable file `TestMain`,
+which is used to run the unit test, will be generated under `test`
+
+- Run `scons --all -c` to clean.
import sys
+import os
-env = Environment(CC="g++")
-env.Append(CPPFLAGS = '-Wall -std=c++11')
+# using -j4 by default
+SetOption('num_jobs', 4)
+AddOption('--all', dest='all', action='store_true', help='Build all include test')
+
+env = Environment(CXX="g++",
+ CPPPATH=['#include'],
+ ALL=GetOption('all'))
+
+env.Append(CCFLAGS = ['-Wall', '-std=c++11'])
env.ParseConfig("pkg-config --libs opencv log4cpp")
-#env.Append(LIBS=['-llog4cpp', '-lpthread'])
-obj = env.Object(Glob("src/*.cpp")) + env.Object("main.cpp")
+#obj = env.Object(Glob("src/*.cpp")) + env.Object("main.cpp")
+obj = env.Object('main.cpp')
+env.StaticLibrary('tracker', Glob('src/*.cpp'))
+
+#print env['LINKFLAGS']
+#print env['LIBS']
+env.Append(LIBS = ['tracker'])
+env.Append(LIBPATH=['#.'])
+#env.Program("main", 'main.cpp', LIBS=['tracker'], LIBPATH=['.'])
env.Program("main", list(obj))
+if GetOption('all'):
+ SConscript('test/SConscript', exports='env')
--- /dev/null
+#ifndef _DETECTOR_H_
+#define _DETECTOR_H_
+
+#include "VideoReader.h"
+#include "SharedPtr.h"
+
+namespace suanzi {
+
+ struct Detection;
+
+ TK_DECLARE_PTR(Detector);
+ class Detector
+ {
+ public:
+ Detector();
+ virtual ~Detector();
+ unsigned int detect(cv::Mat& frame, Detection* detections){return 1;}
+ };
+
+ struct Detection
+ {
+ // 检测目标的类型,目前只有一个类human,默认等于0。为以后可以检测的更多类别预留
+ unsigned int object_type;
+ // 检测目标的分数,可以不填
+ float score;
+ // 检测目标的坐标,包括物体中心的x、y坐标,物体的高和宽
+ unsigned int center_x;
+ unsigned int center_y;
+ unsigned int height;
+ unsigned int width;
+ // 检测目标的特征向量
+ unsigned int feature_size;
+ float * feature;
+ };
+
+}
+
+
+#endif /* _DETECTOR_H_ */
+
+
--- /dev/null
+#ifndef _ENGINE_H_
+#define _ENGINE_H_
+
+#include<string>
+#include<sstream>
+#include<set>
+#include "Tracker.h"
+#include "Detector.h"
+#include "MultiTracker.h"
+#include "VideoReader.h"
+#include "SharedPtr.h"
+
+namespace suanzi{
+
+class EngineObserver;
+
+TK_DECLARE_PTR(Engine);
+
+class Engine
+{
+public:
+ static EnginePtr create();
+ void destroy();
+ virtual ~Engine();
+
+ virtual void start();
+ void addObserver(EngineObserver* o);
+ void setVideoSrc(VideoSrcType type, const std::string& url);
+
+private:
+ Engine();
+ void run();
+ DetectorPtr detector;
+ MultiTrackerPtr multiTracker;
+ std::set<EngineObserver *> observer_list;
+ //std::string videoSrc;
+ VideoReaderPtr reader;
+};
+
+struct Person
+{
+ typedef enum {
+ Male,
+ Female
+ } Gender;
+
+ typedef enum {
+ Kid, // < 10
+ Teenager, // 12 ~ 19
+ Adult_2, // 20 - 30
+ Adult_3, // 30 - 40
+ Adult_4, // 40 - 50
+ Adult_5, // 50 - 60
+ Elder // > 60
+ } Ages;
+
+ unsigned long id = 0x001;
+ Gender gender = Female;
+ Ages age = Kid;
+
+ std::string ageToString (Ages age){
+ switch (age){
+ case Kid: return "Kid";
+ case Teenager: return "Teenager";
+ default: return "no";
+ }
+ }
+
+ std::string toString(){
+ std::stringstream ss;
+ ss << "Person: id=" << id << ". Gender:" << (gender == Gender::Male ? "Male" : "Female" ) <<
+ ". Age: " << ageToString(age);
+ return ss.str();
+ }
+};
+
+class EngineObserver
+{
+public:
+ //virtual void onPersonIn(std::set<Person> persons) = 0;
+ virtual void onPersonIn(Person& p) = 0;
+ virtual void onPersonOut(Person& p) = 0;
+};
+
+} // namespace suanzi
+
+#endif /* _ENGINE_H_ */
--- /dev/null
+#ifndef _LOGGER_H_
+#define _LOGGER_H_
+
+#include <log4cpp/Category.hh>
+#include <log4cpp/PropertyConfigurator.hh>
+
+extern log4cpp::Category * gLogger;
+
+#define LOG_DEBUG(TAG, msg) LOG4CPP_DEBUG_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
+#define LOG_INFO(TAG, msg) LOG4CPP_INFO_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
+#define LOG_WARN(TAG, msg) LOG4CPP_WARN_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
+#define LOG_ERROR(TAG, msg) LOG4CPP_ERROR_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
+#define LOG_FATAL(TAG, msg) LOG4CPP_FATAL_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
+
+void initLogger(const char* fname);
+
+#endif /* _LOGGER_H_ */
--- /dev/null
+#ifndef _METRICS_H_
+#define _METRICS_H_
+
+#include <string>
+#include <opencv2/opencv.hpp>
+#include "SharedPtr.h"
+
+namespace suanzi {
+
+ TK_DECLARE_PTR(Metrics);
+ TK_DECLARE_PTR(Patch);
+ class Metrics
+ {
+ public:
+ Metrics(const std::string& cl_path = "");
+ ~Metrics(){}
+ const static long int MaxCost = 100000;
+ const static int MaxPatch = 5;
+
+ private:
+ cv::HOGDescriptor descriptor = {cv::Size(64, 128), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 9};
+ };
+
+ class Patch
+ {
+ public:
+ Patch(){};
+ ~Patch(){};
+ };
+
+}
+
+#endif /* _METRICS_H_ */
--- /dev/null
+#ifndef _MULTI_TRACKER_H_
+#define _MULTI_TRACKER_H_
+
+#include "Tracker.h"
+#include "Detector.h"
+#include "Metrics.h"
+#include "SharedPtr.h"
+#include <opencv2/opencv.hpp>
+
+namespace suanzi {
+
+ TK_DECLARE_PTR(MultiTracker);
+
+ class MultiTracker
+ {
+ public:
+ MultiTracker(MetricsPtr m);
+ virtual ~MultiTracker();
+ void update(unsigned int total, const Detection* d, const cv::Mat& image);
+
+ private:
+ MetricsPtr metrics;
+ std::set<TrackerPtr> trackers;
+ int max_id = 0;
+ void addTracker(TrackerPtr t);
+ TrackerPtr createTracker(int id = 0);
+ void removeTracker(TrackerPtr t);
+ void correctTrackers(MetricsPtr m, cv::Mat& image);
+ void initNewTrackers(cv::Mat& iamge);
+ };
+
+
+}
+
+#endif /* _MULTI_TRACKER_H_ */
--- /dev/null
+#ifndef _SHARED_PTR_H_
+#define _SHARED_PTR_H_
+
+#include <memory>
+#ifndef TK_DECLARE_PTR
+#define TK_DECLARE_PTR(className) \
+ class className; \
+ typedef std::shared_ptr<className> className##Ptr; \
+ typedef std::weak_ptr<className> className##WPtr;
+#endif
+
+#endif /* _SHARED_PTR_H_ */
--- /dev/null
+#ifndef _TRACKER_H_
+#define _TRACKER_H_
+
+#include <opencv2/opencv.hpp>
+#include <string>
+#include <vector>
+#include "Metrics.h"
+#include "SharedPtr.h"
+
+namespace suanzi {
+
+ typedef enum
+ {
+ Fire = -1,
+ Active = 2,
+ Lost,
+ Delete
+ } TrackerStatus;
+
+ TK_DECLARE_PTR(Tracker);
+// TK_DECLARE_PTR(KalmanFilter);
+ class Tracker
+ {
+ public:
+ Tracker(int id);
+ virtual ~Tracker();
+ void updateState(const cv::Mat& image);
+ void addPatch(Patch* p);
+ TrackerStatus status;
+
+ private:
+ TrackerStatus preStatus;
+ int id;
+ int age;
+ int last_active;
+ std::vector<Patch *> patches;
+ cv::KalmanFilter kf = {4,2};
+ };
+
+// class KalmanFilter
+// {
+// public:
+// KalmanFilter();
+// ~KalmanFilter();
+// private:
+// cv::KalmanFilter
+//
+// };
+
+
+}
+
+#endif /* _TRACKER_H_ */
--- /dev/null
+#ifndef _IVIDEO_READER_H_
+#define _IVIDEO_READER_H_
+
+#include "SharedPtr.h"
+#include <string>
+#include <opencv2/opencv.hpp>
+
+namespace suanzi {
+
+ typedef enum {
+ URL,
+ File,
+ USB
+ } VideoSrcType;
+
+ TK_DECLARE_PTR(VideoReaderFactory);
+ TK_DECLARE_PTR(VideoReader);
+ TK_DECLARE_PTR(URLReader);
+
+ class VideoReaderFactory
+ {
+ public:
+ static VideoReaderPtr createVideoReader(VideoSrcType type, const std::string& url);
+ };
+
+ class VideoReader
+ {
+ public:
+ VideoReader(VideoSrcType type, const std::string& url) : type(type), url(url){}
+
+ virtual ~VideoReader();
+ virtual bool read(cv::Mat& mat){return true;}
+
+ private:
+ VideoSrcType type;
+
+ protected:
+ std::string url;
+ };
+
+ class UrlReader : public VideoReader
+ {
+ public:
+ UrlReader(VideoSrcType type, const std::string& url);
+ virtual ~UrlReader();
+ bool read(cv::Mat& mat);
+ private:
+ cv::VideoCapture vcap;
+ };
+
+ class FileReader : public VideoReader
+ {
+ public:
+ FileReader(VideoSrcType type, const std::string& url):VideoReader(type, url){}
+ // void read(){};
+ };
+
+ class UsbReader : public VideoReader
+ {
+ public:
+ UsbReader(VideoSrcType type, const std::string& url):VideoReader(type, url){}
+ // void read(){};
+ };
+
+}
+
+
+#endif /* _IVIDEO_READER_H_ */
--- /dev/null
+#ifndef __TEST_H__
+#define __TEST_H__
+
+int sum(int a, int b);
+
+#endif // __TEST_H__
#include<iostream>
-#include "src/Engine.h"
+#include "Engine.h"
#include <string>
-#include "src/Logger.h"
+#include "Logger.h"
#define TAG "Main"
+++ /dev/null
-#ifndef _DETECTOR_H_
-#define _DETECTOR_H_
-
-#include "VideoReader.h"
-#include "SharedPtr.h"
-
-namespace suanzi {
-
- struct Detection;
-
- TK_DECLARE_PTR(Detector);
- class Detector
- {
- public:
- Detector();
- virtual ~Detector();
- unsigned int detect(cv::Mat& frame, Detection* detections){return 1;}
- };
-
- struct Detection
- {
- // 检测目标的类型,目前只有一个类human,默认等于0。为以后可以检测的更多类别预留
- unsigned int object_type;
- // 检测目标的分数,可以不填
- float score;
- // 检测目标的坐标,包括物体中心的x、y坐标,物体的高和宽
- unsigned int center_x;
- unsigned int center_y;
- unsigned int height;
- unsigned int width;
- // 检测目标的特征向量
- unsigned int feature_size;
- float * feature;
- };
-
-}
-
-
-#endif /* _DETECTOR_H_ */
-
-
+++ /dev/null
-#ifndef _ENGINE_H_
-#define _ENGINE_H_
-
-#include<string>
-#include<sstream>
-#include<set>
-#include "Tracker.h"
-#include "Detector.h"
-#include "MultiTracker.h"
-#include "VideoReader.h"
-#include "SharedPtr.h"
-
-namespace suanzi{
-
-class EngineObserver;
-
-TK_DECLARE_PTR(Engine);
-
-class Engine
-{
-public:
- static EnginePtr create();
- void destroy();
- virtual ~Engine();
-
- virtual void start();
- void addObserver(EngineObserver* o);
- void setVideoSrc(VideoSrcType type, const std::string& url);
-
-private:
- Engine();
- void run();
- DetectorPtr detector;
- MultiTrackerPtr multiTracker;
- std::set<EngineObserver *> observer_list;
- //std::string videoSrc;
- VideoReaderPtr reader;
-};
-
-struct Person
-{
- typedef enum {
- Male,
- Female
- } Gender;
-
- typedef enum {
- Kid, // < 10
- Teenager, // 12 ~ 19
- Adult_2, // 20 - 30
- Adult_3, // 30 - 40
- Adult_4, // 40 - 50
- Adult_5, // 50 - 60
- Elder // > 60
- } Ages;
-
- unsigned long id = 0x001;
- Gender gender = Female;
- Ages age = Kid;
-
- std::string ageToString (Ages age){
- switch (age){
- case Kid: return "Kid";
- case Teenager: return "Teenager";
- default: return "no";
- }
- }
-
- std::string toString(){
- std::stringstream ss;
- ss << "Person: id=" << id << ". Gender:" << (gender == Gender::Male ? "Male" : "Female" ) <<
- ". Age: " << ageToString(age);
- return ss.str();
- }
-};
-
-class EngineObserver
-{
-public:
- //virtual void onPersonIn(std::set<Person> persons) = 0;
- virtual void onPersonIn(Person& p) = 0;
- virtual void onPersonOut(Person& p) = 0;
-};
-
-} // namespace suanzi
-
-#endif /* _ENGINE_H_ */
+++ /dev/null
-#ifndef _LOGGER_H_
-#define _LOGGER_H_
-
-#include <log4cpp/Category.hh>
-#include <log4cpp/PropertyConfigurator.hh>
-
-extern log4cpp::Category * gLogger;
-
-#define LOG_DEBUG(TAG, msg) LOG4CPP_DEBUG_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
-#define LOG_INFO(TAG, msg) LOG4CPP_INFO_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
-#define LOG_WARN(TAG, msg) LOG4CPP_WARN_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
-#define LOG_ERROR(TAG, msg) LOG4CPP_ERROR_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
-#define LOG_FATAL(TAG, msg) LOG4CPP_FATAL_S((*gLogger)) << '[' << TAG << ']' <<" ("<<__FILE__<<":"<<__LINE__<<") - " << msg;
-
-void initLogger(const char* fname);
-
-#endif /* _LOGGER_H_ */
+++ /dev/null
-#ifndef _METRICS_H_
-#define _METRICS_H_
-
-#include <string>
-#include <opencv2/opencv.hpp>
-#include "SharedPtr.h"
-
-namespace suanzi {
-
- TK_DECLARE_PTR(Metrics);
- TK_DECLARE_PTR(Patch);
- class Metrics
- {
- public:
- Metrics(const std::string& cl_path = "");
- ~Metrics(){}
- const static long int MaxCost = 100000;
- const static int MaxPatch = 5;
-
- private:
- cv::HOGDescriptor descriptor = {cv::Size(64, 128), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 9};
- };
-
- class Patch
- {
- public:
- Patch(){};
- ~Patch(){};
- };
-
-}
-
-#endif /* _METRICS_H_ */
+++ /dev/null
-#ifndef _MULTI_TRACKER_H_
-#define _MULTI_TRACKER_H_
-
-#include "Tracker.h"
-#include "Detector.h"
-#include "Metrics.h"
-#include "SharedPtr.h"
-#include <opencv2/opencv.hpp>
-
-namespace suanzi {
-
- TK_DECLARE_PTR(MultiTracker);
-
- class MultiTracker
- {
- public:
- MultiTracker(MetricsPtr m);
- virtual ~MultiTracker();
- void update(unsigned int total, const Detection* d, const cv::Mat& image);
-
- private:
- MetricsPtr metrics;
- std::set<TrackerPtr> trackers;
- int max_id = 0;
- void addTracker(TrackerPtr t);
- TrackerPtr createTracker(int id = 0);
- void removeTracker(TrackerPtr t);
- void correctTrackers(MetricsPtr m, cv::Mat& image);
- void initNewTrackers(cv::Mat& iamge);
- };
-
-
-}
-
-#endif /* _MULTI_TRACKER_H_ */
+++ /dev/null
-#ifndef _SHARED_PTR_H_
-#define _SHARED_PTR_H_
-
-#include <memory>
-#ifndef TK_DECLARE_PTR
-#define TK_DECLARE_PTR(className) \
- class className; \
- typedef std::shared_ptr<className> className##Ptr; \
- typedef std::weak_ptr<className> className##WPtr;
-#endif
-
-#endif /* _SHARED_PTR_H_ */
+++ /dev/null
-#ifndef _TRACKER_H_
-#define _TRACKER_H_
-
-#include <opencv2/opencv.hpp>
-#include <string>
-#include <vector>
-#include "Metrics.h"
-#include "SharedPtr.h"
-
-namespace suanzi {
-
- typedef enum
- {
- Fire = -1,
- Active = 2,
- Lost,
- Delete
- } TrackerStatus;
-
- TK_DECLARE_PTR(Tracker);
-// TK_DECLARE_PTR(KalmanFilter);
- class Tracker
- {
- public:
- Tracker(int id);
- virtual ~Tracker();
- void updateState(const cv::Mat& image);
- void addPatch(Patch* p);
- TrackerStatus status;
-
- private:
- TrackerStatus preStatus;
- int id;
- int age;
- int last_active;
- std::vector<Patch *> patches;
- cv::KalmanFilter kf = {4,2};
- };
-
-// class KalmanFilter
-// {
-// public:
-// KalmanFilter();
-// ~KalmanFilter();
-// private:
-// cv::KalmanFilter
-//
-// };
-
-
-}
-
-#endif /* _TRACKER_H_ */
+++ /dev/null
-#ifndef _IVIDEO_READER_H_
-#define _IVIDEO_READER_H_
-
-#include "SharedPtr.h"
-#include <string>
-#include <opencv2/opencv.hpp>
-
-namespace suanzi {
-
- typedef enum {
- URL,
- File,
- USB
- } VideoSrcType;
-
- TK_DECLARE_PTR(VideoReaderFactory);
- TK_DECLARE_PTR(VideoReader);
- TK_DECLARE_PTR(URLReader);
-
- class VideoReaderFactory
- {
- public:
- static VideoReaderPtr createVideoReader(VideoSrcType type, const std::string& url);
- };
-
- class VideoReader
- {
- public:
- VideoReader(VideoSrcType type, const std::string& url) : type(type), url(url){}
-
- virtual ~VideoReader();
- virtual bool read(cv::Mat& mat){return true;}
-
- private:
- VideoSrcType type;
-
- protected:
- std::string url;
- };
-
- class UrlReader : public VideoReader
- {
- public:
- UrlReader(VideoSrcType type, const std::string& url);
- virtual ~UrlReader();
- bool read(cv::Mat& mat);
- private:
- cv::VideoCapture vcap;
- };
-
- class FileReader : public VideoReader
- {
- public:
- FileReader(VideoSrcType type, const std::string& url):VideoReader(type, url){}
- // void read(){};
- };
-
- class UsbReader : public VideoReader
- {
- public:
- UsbReader(VideoSrcType type, const std::string& url):VideoReader(type, url){}
- // void read(){};
- };
-
-}
-
-
-#endif /* _IVIDEO_READER_H_ */
--- /dev/null
+#include "test.h"
+
+#include <iostream>
+
+int sum(int a, int b)
+{
+ return a + b;
+}
--- /dev/null
+import sys, os
+
+Import('env')
+
+env1 = env.Clone()
+
+env1.Append(CPPPATH = ['#third_party/googletest/include'])
+env1.Append(LIBPATH = ['#third_party/googletest/lib'])
+env1['LIBS'] = ['tracker', 'gtest', 'pthread']
+
+obj = env1.Object(Glob("*.cpp"))
+
+env1.Program("TestMain", list(obj))
--- /dev/null
+#include "test.h"
+#include "gtest/gtest.h"
+
+TEST(FactorialTest, Negative) {
+ // This test is named "Negative", and belongs to the "FactorialTest"
+ // test case.
+ EXPECT_EQ(2, sum(1, 2));
+ //EXPECT_GT(Factorial(-10), 0);
+
+}
+
+