- Main Page
- Modules
- Namespaces
- Classes
- Files

- Search for |

- File List
- File Members

# samples/11_camera_object_identification/opencv_consumer_lib/Classifier.h

Go to the documentation of this file.

    00001 /*
    00002 COPYRIGHT
    00003
    00004 All contributions by the University of California:
    00005 Copyright (c) 2014, 2015, The Regents of the University of California (Regents)
    00006 All rights reserved.
    00007
    00008 All other contributions:
    00009 Copyright (c) 2014, 2015, the respective contributors
    00010 All rights reserved.
    00011
    00012 Caffe uses a shared copyright model: each contributor holds copyright over
    00013 their contributions to Caffe. The project versioning records all such
    00014 contribution and copyright details. If a contributor wants to further mark
    00015 their specific copyright on a particular contribution, they should indicate
    00016 their copyright solely in the commit message of the change when it is
    00017 committed.
    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;  // NOLINT(build/namespaces)
    00027
    00028 /* Pair (label, confidence) representing a prediction. */
    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 };