vision
TravisLib.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __TRAVIS_LIB_HPP__
4 #define __TRAVIS_LIB_HPP__
5 
6 #include <vector>
7 
8 #include "opencv2/core/mat.hpp"
9 #include "opencv2/core/types.hpp"
10 
16 namespace roboticslab
17 {
18 
23 class Travis
24 {
25 public:
31  Travis(bool quiet=true, bool overwrite=true) : _quiet(quiet), _overwrite(overwrite) {}
32 
38  bool setCvMat(const cv::Mat& image);
39 
45  bool setBinCvMat(const cv::Mat& image);
46 
51  bool binarize(const char* algorithm);
52 
58  bool binarize(const char* algorithm, const double& threshold);
59 
66  bool binarize(const char* algorithm, const double& min, const double& max);
67 
72  void morphClosing(const int& closure);
73 
78  void morphOpening(const int& opening);
79 
85  int blobize(const int& maxNumBlobs);
86 
91  void pushContour(const std::vector<cv::Point>& contour);
92 
97  bool getBlobsXY(std::vector<cv::Point2d> &locations);
98 
103  bool getBlobsArea(std::vector<double>& areas);
104 
109  bool getBlobsSolidity(std::vector<double>& solidities);
110 
111  bool getBlobsRect(std::vector<cv::Rect>& rects);
112 
118  bool getBlobsAngle(const int& method, std::vector<double>& angles);
119 
126  bool getBlobsAspectRatio(std::vector<double>& aspectRatios, std::vector<double>& axisFirsts, std::vector<double>& axisSeconds);
127 
128  bool getBlobsPerimeter(std::vector<double>& perimeters);
129 
134  bool getBlobsRectangularity(std::vector<double>& rectangularities);
135 
145  bool getBlobsHSV(std::vector<double>& hues, std::vector<double>& vals, std::vector<double>& sats,
146  std::vector<double>& hueStdDevs, std::vector<double>& valStdDevs, std::vector<double>& satStdDevs);
147 
154  cv::Mat& getCvMat(const int& image, const int& vizualization);
155 
159  void release();
160 
161 protected:
163  bool _quiet;
164 
167 
169  cv::Mat _img;
170 
172  cv::Mat _imgHsv;
173 
175  cv::Mat _imgBin;
176 
178  cv::Mat _imgBin3;
179 
181  std::vector<std::vector<cv::Point> > _contours;
182 
184  std::vector<cv::RotatedRect> _minRotatedRects;
185 
186 };
187 
192 bool compareContourAreas (std::vector<cv::Point> contour1, std::vector<cv::Point> contour2 );
193 
199 bool travisCrop(const int x, const int y, const int width, const int height, cv::Mat& img);
200 
205 std::vector<cv::Point> getBiggestContour(const cv::Mat image);
206 
211 void calcLocationXY(float& locX, float& locY, const std::vector<cv::Point> biggestCont);
212 
217 void calcMask(cv::Mat& mask, const std::vector<cv::Point> biggestCont);
218 
223 void calcArea(float& area, const std::vector<cv::Point> biggestCont);
224 
229 void calcRectangularity(float& rectangularity, const std::vector<cv::Point> biggestCont);
230 
235 void calcAngle(float& angle, const std::vector<cv::Point> biggestCont);
236 
241 void calcMassCenter(float& massCenterLocX, float& massCenterLocY , const std::vector<cv::Point> biggestCont);
242 
247 void calcAspectRatio(float& aspectRatio, float& axisFirst, float& axisSecond ,const std::vector<cv::Point> biggestCont);
248 
253 void calcSolidity(float& solidity, const std::vector<cv::Point> biggestCont);
254 
259 void calcHSVMeanStdDev(const cv::Mat image, const cv::Mat mask, float& hue_mean, float& hue_stddev,
260  float& saturation_mean, float& saturation_stddev,
261  float& value_mean, float& value_stddev);
262 
267 void calcHSVPeakColor(const cv::Mat image, const cv::Mat mask, float& hue_mode, float& hue_peak,
268  float& value_mode, float& value_peak);
269 
274 void calcMoments(cv::Mat& theHuMoments, const std::vector<cv::Point> biggestCont );
275 
280 void calcArcLength(float& arc, const std::vector<cv::Point> biggestCont );
281 
286 void calcCircle(float& radius, const std::vector<cv::Point> biggestCont );
287 
288 } // namespace roboticslab
289 
290 #endif // __TRAVIS_LIB_HPP__
The Travis class implements all the algorithms on a single image.
Definition: TravisLib.hpp:24
void release()
Definition: TravisLib.cpp:539
cv::Mat _imgBin3
Definition: TravisLib.hpp:178
bool setCvMat(const cv::Mat &image)
Definition: TravisLib.cpp:20
cv::Mat _img
Definition: TravisLib.hpp:169
bool getBlobsAspectRatio(std::vector< double > &aspectRatios, std::vector< double > &axisFirsts, std::vector< double > &axisSeconds)
Definition: TravisLib.cpp:410
void morphClosing(const int &closure)
Definition: TravisLib.cpp:210
bool _overwrite
Definition: TravisLib.hpp:166
bool binarize(const char *algorithm)
Definition: TravisLib.cpp:74
std::vector< std::vector< cv::Point > > _contours
Definition: TravisLib.hpp:181
void pushContour(const std::vector< cv::Point > &contour)
Definition: TravisLib.cpp:258
void morphOpening(const int &opening)
Definition: TravisLib.cpp:221
bool getBlobsRectangularity(std::vector< double > &rectangularities)
Definition: TravisLib.cpp:429
bool setBinCvMat(const cv::Mat &image)
Definition: TravisLib.cpp:43
cv::Mat _imgHsv
Definition: TravisLib.hpp:172
cv::Mat & getCvMat(const int &image, const int &vizualization)
Definition: TravisLib.cpp:498
cv::Mat _imgBin
Definition: TravisLib.hpp:175
int blobize(const int &maxNumBlobs)
Definition: TravisLib.cpp:232
Travis(bool quiet=true, bool overwrite=true)
Definition: TravisLib.hpp:31
bool _quiet
Definition: TravisLib.hpp:163
std::vector< cv::RotatedRect > _minRotatedRects
Definition: TravisLib.hpp:184
bool getBlobsHSV(std::vector< double > &hues, std::vector< double > &vals, std::vector< double > &sats, std::vector< double > &hueStdDevs, std::vector< double > &valStdDevs, std::vector< double > &satStdDevs)
Definition: TravisLib.cpp:451
bool getBlobsArea(std::vector< double > &areas)
Definition: TravisLib.cpp:303
bool getBlobsSolidity(std::vector< double > &solidities)
Definition: TravisLib.cpp:331
bool getBlobsAngle(const int &method, std::vector< double > &angles)
Definition: TravisLib.cpp:363
bool getBlobsXY(std::vector< cv::Point2d > &locations)
Definition: TravisLib.cpp:268
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:5
void calcSolidity(float &solidity, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:706
std::vector< cv::Point > getBiggestContour(const cv::Mat image)
Definition: TravisLib.cpp:574
void calcArcLength(float &arc, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:858
void calcAspectRatio(float &aspectRatio, float &axisFirst, float &axisSecond, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:685
void calcMassCenter(float &massCenterLocX, float &massCenterLocY, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:670
void calcArea(float &area, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:633
bool travisCrop(const int x, const int y, const int width, const int height, cv::Mat &img)
Definition: TravisLib.cpp:561
void calcHSVPeakColor(const cv::Mat image, const cv::Mat mask, float &hue_mode, float &hue_peak, float &value_mode, float &value_peak)
Definition: TravisLib.cpp:750
void calcHSVMeanStdDev(const cv::Mat image, const cv::Mat mask, float &hue_mean, float &hue_stddev, float &saturation_mean, float &saturation_stddev, float &value_mean, float &value_stddev)
Definition: TravisLib.cpp:720
bool compareContourAreas(std::vector< cv::Point > contour1, std::vector< cv::Point > contour2)
Definition: TravisLib.cpp:552
void calcRectangularity(float &rectangularity, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:639
void calcAngle(float &angle, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:656
void calcMoments(cv::Mat &theHuMoments, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:851
void calcCircle(float &radius, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:864
void calcMask(cv::Mat &mask, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:620
void calcLocationXY(float &locX, float &locY, const std::vector< cv::Point > biggestCont)
Definition: TravisLib.cpp:608