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 <Interfaces/MainWindowInterface.h>
18 #include <Interfaces/MainWindowEventInterface.h>
19 #include <VideoCapture/BitmapCapture.h>
20 #include <Helpers/helpers.h>
21 
22 #include <Image/ByteImage.h>
23 #include <Image/FloatImage.h>
24 #include <Image/IntImage.h>
25 #include <Image/ShortImage.h>
26 #include <Image/ImageProcessor.h>
27 #include <Image/PrimitivesDrawer.h>
28 #include <Math/Vecd.h>
29 #include <Classification/NearestNeighbor.h>
30 
31 
32 
33 #include <opencv2/core/core.hpp>
34 #include <opencv2/highgui/highgui.hpp>
35 #include <opencv2/imgproc/imgproc.hpp>
36 
37 #include <stdio.h>
38 #include <iostream>
39 #include <math.h>
40 #include <vector>
41 #include <unistd.h>
42 #include <utility>
43 #include <limits>
44 
45 //calculate the HoG descriptor for training Data & test data
46 //build the classifier
47 //find the ventil in an image
48 class HoG
49 {
50 
51 public:
52  HoG(int numOfBing = 16, int sampleTime = 500, int numOfHistory = 2, int minRandomWindow = 20, int randomWindowScaleFloor = 1, int randomWindowScaleCeil = 2);
53  void loadTrainingData(std::string path);
54  void findSalientRegions(const CByteImage* origin, CFloatImage* saliencyImage);
55  void setParameters(bool useHough, bool useHoG);
56 
57 private:
58 
59 
60  bool hogDescriptor(CByteImage* origin, CFloatImage* outImage, CFloatImage* amplitude);
61  void calculateHist(int range, int bin, CFloatImage* inputImg, std::vector<float>* output, CFloatImage* amplitude);
62  void histogramNorm(std::vector<float>* input, std::vector<float>* normOutput);
63  float distanceBetweenPoints(std::vector<float> firstPoint, std::vector<float> secondPoint, int metrics);
64  //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);
65  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);
66  bool knn(std::vector<std::vector<float> > trainingHistTable, std::vector<std::vector<float> > trainingHistTableNegative, std::vector<float> testWindow);
67  void preprocess(const CByteImage* origin, CByteImage* outImage);
68  void histogramRotationInvariant(std::vector<float>* inputHist, std::vector<float>* outputHist);
69 
70 
71  void doLoadTrainingData(std::string path, std::vector<std::vector<float> >& histTable, int scaling);
72 
73  std::vector<std::vector<float> > trainingHistTable;
74  std::vector<std::vector<float> > trainingHistTableNegative;
75  std::vector<std::vector<float> > samplHistTable;
76  int numberOfBins;
77  int sampleTimes;
78  int numberOfHistory;
79  int minimumRandomWindow;
80  int randomWindowScaleRateFloor;
81  int randomWindowScaleRateCeil;
82  // int scaleRateFloor;
83  // int scaleRateCeil;
84 
85 
86  bool useHoughDetector;
87  bool useHoGDetector;
88 };
89 
HoG
Definition: hog.h:48
HoG::HoG
HoG(int numOfBing=16, int sampleTime=500, int numOfHistory=2, int minRandomWindow=20, int randomWindowScaleFloor=1, int randomWindowScaleCeil=2)
Definition: hog.cpp:8
HoG::findSalientRegions
void findSalientRegions(const CByteImage *origin, CFloatImage *saliencyImage)
Definition: hog.cpp:92
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
HoG::setParameters
void setParameters(bool useHough, bool useHoG)
Definition: hog.cpp:467
HoG::loadTrainingData
void loadTrainingData(std::string path)
Definition: hog.cpp:19