]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/cn/cnfeat.hpp
added color name features
[hercules2020/kcf.git] / src / cn / cnfeat.hpp
1 //
2 // Created by vojirtom on 8/9/16.
3 //
4
5 #ifndef KCF_TRACKER_CNFEAT_H
6 #define KCF_TRACKER_CNFEAT_H
7
8 #include <opencv2/opencv.hpp>
9
10 class CNFeat
11 {
12 public:
13     static std::vector<cv::Mat> extract(const cv::Mat & patch_rgb)
14     {
15         std::vector<cv::Mat> cn_feat(p_cn_channels);
16         for (int i = 0; i < p_cn_channels; ++i) {
17             cn_feat[i].create(patch_rgb.size(), CV_32FC1);
18         }
19
20         float * ch_ptr[p_cn_channels];
21         for (int y = 0; y < patch_rgb.rows; ++y) {
22             for (int i = 0; i < p_cn_channels; ++i)
23                 ch_ptr[i] = cn_feat[i].ptr<float>(y);
24             for (int x = 0; x < patch_rgb.cols; ++x) {
25                 //images in opencv stored in BGR order
26                 cv::Vec3b bgr_val = patch_rgb.at<cv::Vec3b>(y,x);
27                 for (int i = 0; i < p_cn_channels; ++i)
28                     ch_ptr[i][x] = p_id2feat[rgb2id(bgr_val[2], bgr_val[1], bgr_val[0])][i];
29             }
30         }
31         return cn_feat;
32     }
33
34 private:
35     inline static int rgb2id(int r, int g, int b)
36     {   return (r >> 3) + 32*(g >> 3) + 32*32*(b >> 3);     }
37     static const int p_cn_channels = 10;
38     static float p_id2feat[32768][10];
39 };
40
41
42 #endif //KCF_TRACKER_CNFEAT_H