hog.h
Go to the documentation of this file.
1 #pragma once
2 //#define DEMO_IMAGE "../../../Hiwi/Database/Ventil/Valve5.bmp"
3 #define DEMO_IMAGE "../../../../bmp/frame0206.bmp"
4 //#define DEMO_IMAGE "../../../../bmp/frame0285.bmp"
5 //#define DEMO_IMAGE "../../../../bmp/frame0205.bmp"
6 //#define DEMO_IMAGE "../../../../bmp/frame0259.bmp"
7 //#define DEMO_IMAGE "../../../../bmp/frame0267.bmp"
8 //#define DEMO_IMAGE "../../../../bmp/frame0279.bmp"
9 
10 //#define DEMO_IMAGE "../../../../bmp/frame0022.bmp"
11 //#define DEMO_IMAGE "../../../../bmp/frame0082.bmp"
12 
13 
14 // ****************************************************************************
15 // Includes
16 // ****************************************************************************
17 #include <math.h>
18 #include <stdio.h>
19 
20 #include <iostream>
21 #include <limits>
22 #include <utility>
23 #include <vector>
24 
25 #include <unistd.h>
26 
27 #include <opencv2/core/core.hpp>
28 #include <opencv2/highgui/highgui.hpp>
29 #include <opencv2/imgproc/imgproc.hpp>
30 
31 #include <Classification/NearestNeighbor.h>
32 #include <Helpers/helpers.h>
33 #include <Image/ByteImage.h>
34 #include <Image/FloatImage.h>
35 #include <Image/ImageProcessor.h>
36 #include <Image/IntImage.h>
37 #include <Image/PrimitivesDrawer.h>
38 #include <Image/ShortImage.h>
39 #include <Interfaces/MainWindowEventInterface.h>
40 #include <Interfaces/MainWindowInterface.h>
41 #include <Math/Vecd.h>
42 #include <VideoCapture/BitmapCapture.h>
43 
44 //calculate the HoG descriptor for training Data & test data
45 //build the classifier
46 //find the ventil in an image
47 class HoG
48 {
49 
50 public:
51  HoG(int numOfBing = 16,
52  int sampleTime = 500,
53  int numOfHistory = 2,
54  int minRandomWindow = 20,
55  int randomWindowScaleFloor = 1,
56  int randomWindowScaleCeil = 2);
57  void loadTrainingData(std::string path);
58  void findSalientRegions(const CByteImage* origin, CFloatImage* saliencyImage);
59  void setParameters(bool useHough, bool useHoG);
60 
61 private:
62  bool hogDescriptor(CByteImage* origin, CFloatImage* outImage, CFloatImage* amplitude);
63  void calculateHist(int range,
64  int bin,
65  CFloatImage* inputImg,
66  std::vector<float>* output,
67  CFloatImage* amplitude);
68  void histogramNorm(std::vector<float>* input, std::vector<float>* normOutput);
69  float distanceBetweenPoints(std::vector<float> firstPoint,
70  std::vector<float> secondPoint,
71  int metrics);
72  //void findThreeNearstNeighbors(std::vector<float> testWindow, std::vector<std::vector<float> > trainingHistTable, int lable, std::pair <std::vector<float>, int>* nearstNeighbor, std::pair <std::vector<float>, int>* secondNeighbor, std::pair <std::vector<float>, int>* thirdNeighbor, float* nearstDistance, float* secondDistance, float* thirdDistance);
73  void findThreeNearstNeighbors(std::vector<float> testWindow,
74  std::vector<std::vector<float>> trainingHistTable,
75  int lable,
76  std::pair<std::vector<float>*, int>* nearstNeighbor,
77  std::pair<std::vector<float>*, int>* secondNeighbor,
78  std::pair<std::vector<float>*, int>* thirdNeighbor,
79  float* nearstDistance,
80  float* secondDistance,
81  float* thirdDistance);
82  bool knn(std::vector<std::vector<float>> trainingHistTable,
83  std::vector<std::vector<float>> trainingHistTableNegative,
84  std::vector<float> testWindow);
85  void preprocess(const CByteImage* origin, CByteImage* outImage);
86  void histogramRotationInvariant(std::vector<float>* inputHist, std::vector<float>* outputHist);
87 
88 
89  void
90  doLoadTrainingData(std::string path, std::vector<std::vector<float>>& histTable, int scaling);
91 
92  std::vector<std::vector<float>> trainingHistTable;
93  std::vector<std::vector<float>> trainingHistTableNegative;
94  std::vector<std::vector<float>> samplHistTable;
95  int numberOfBins;
96  int sampleTimes;
97  int numberOfHistory;
98  int minimumRandomWindow;
99  int randomWindowScaleRateFloor;
100  int randomWindowScaleRateCeil;
101  // int scaleRateFloor;
102  // int scaleRateCeil;
103 
104 
105  bool useHoughDetector;
106  bool useHoGDetector;
107 };
HoG
Definition: hog.h:47
HoG::HoG
HoG(int numOfBing=16, int sampleTime=500, int numOfHistory=2, int minRandomWindow=20, int randomWindowScaleFloor=1, int randomWindowScaleCeil=2)
Definition: hog.cpp:7
HoG::findSalientRegions
void findSalientRegions(const CByteImage *origin, CFloatImage *saliencyImage)
Definition: hog.cpp:93
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
HoG::setParameters
void setParameters(bool useHough, bool useHoG)
Definition: hog.cpp:527
HoG::loadTrainingData
void loadTrainingData(std::string path)
Definition: hog.cpp:24