00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <caffe/caffe.hpp>
00021
00022 #include <opencv2/core/core.hpp>
00023 #include <opencv2/highgui/highgui.hpp>
00024 #include <opencv2/imgproc/imgproc.hpp>
00025
00026 using namespace caffe;
00027
00028
00029 typedef std::pair<string, float> Prediction;
00030
00031 class Classifier {
00032 public:
00033 Classifier(const string& model_file,
00034 const string& trained_file,
00035 const string& mean_file,
00036 const string& label_file);
00037
00038 std::vector<Prediction> Classify(const cv::Mat& img, int N = 5);
00039
00040 private:
00041 void SetMean(const string& mean_file);
00042
00043 std::vector<float> Predict(const cv::Mat& img);
00044
00045 void WrapInputLayer(std::vector<cv::Mat>* input_channels);
00046
00047 void Preprocess(const cv::Mat& img,
00048 std::vector<cv::Mat>* input_channels);
00049
00050 private:
00051 shared_ptr<Net<float> > net_;
00052 cv::Size input_geometry_;
00053 int num_channels_;
00054 cv::Mat mean_;
00055 std::vector<string> labels_;
00056 };