findArrow.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 
48 #ifndef FIND_ARROW_H
49 #define FIND_ARROW_H
50 
51 #include <opencv2/features2d/features2d.hpp>//opencv
52 #include <opencv2/highgui/highgui.hpp>
53 #include <opencv2/imgproc/imgproc.hpp>
54 #include <opencv2/calib3d/calib3d.hpp>
55 #include <opencv2/nonfree/nonfree.hpp>
56 #include <opencv2/core/core.hpp>
57 #include <opencv2/opencv.hpp>
58 #include <stdlib.h>//boost/cpp
59 #include <iostream>
60 #include <stdio.h>
61 #include <string>
62 #include <math.h>
63 #include <vector>
64 #include <map>
65 
66 // my files
67 #include "rotateImage.h"
68 
69 /* assert */ // http://www.cplusplus.com/reference/cassert/assert/
70 #include <assert.h>
71 
72 using namespace cv;
73 using namespace std;
74 
75 class findArrow
76 {
77 public:
78 
79 //global vars
80  //static unsigned int src_centre_x;
81  //static unsigned int src_centre_y;
82  //static cv::Point src_centre;
83  static bool found_new_point;
84 
85 // Const variables
86 
87  static const unsigned int EROSION_SIZE;
88  static const unsigned int EROSION_SIZE_MIN;
89  static const unsigned int THRESH;
90  static const unsigned int MAX_THRESH;//Trackbar
91  static const unsigned int LINE_THICKNESS;
92 
93  // For validate_lengths function
94  static const unsigned short VAL_MAX_LENGTH;
95  static const unsigned short VAL_MIN_LENGTH;
96  static const float VAL_MIN_RELATION_LENGTH;
97  static const float VAL_MAX_RELATION_LENGTH;
98 
99  // Variables for validate_contour_Area_Length function
100  static const double BBCA_MIN;
101  static const double BBCA_MAX;
102  static const double BBCL_MIN;
103  static const double BBCL_MAX;
104  static const double CACL_MIN;
105  static const double CACL_MAX;
106  static const double AREA_MIN;
107 
108  // Variable for validate_convexHull
109  static const unsigned short CONVEX_HULL_CORNERS;
110 
111  // Variable for validate_corners_arrow
112  static const unsigned short CONVEX_ARROW_CORNERS;
113 
114 //functions
116  static void boundig_box(Mat & src_tresh, Mat & dst);
117 
119  static vector<RotatedRect> boundig_box_small( Mat & src_tresh, Mat & threshold_output,vector<vector<Point> > contours,
120  cv::Point & src_centre);
121 
123  static void Opening(Mat & src, Mat & dest,unsigned int erosion_size);
124 
126  static void closing(Mat & src, Mat & dest,unsigned int erosion_size);
127 
129  static vector<vector<Point> > find_contours(Mat & src, Mat & dest,const unsigned int & line_thinckness);
130 
133  //static int find_arrow(Mat img_scene);
134  static int find_arrow(cv::Mat frame,cv::Point & center_point);
135 
136  static void ProcessMyImage(Mat & src, Mat & dest);
137 
139  static void ProcessEdges(Mat & src, Mat & dest);
140 
141  static void multiplymatrixbool(Mat & src, Mat & matbol);
142 
144  static void descritor( Mat & img_object, Mat & img_scene);
145 
146  static bool validate_lengths(Point2f rect_points[],
147  const unsigned short max_length= VAL_MAX_LENGTH,
148  const unsigned short min_length = VAL_MIN_LENGTH,
149  const float min_relation_length = VAL_MIN_RELATION_LENGTH ,
150  const float max_relation_length = VAL_MAX_RELATION_LENGTH
151  );
152 
153  static Point calculate_center_contour(Point2f contour[],unsigned int size_contour);
154 
155  static bool validate_contour_Area_Length(vector<Point> contours,vector<double> bbox_points,
156  const double bbca_min = BBCA_MIN,
157  const double bbca_max = BBCA_MAX,const double bbcl_min = BBCL_MIN, const double bbcl_max = BBCL_MAX,
158  const double cacl_min = CACL_MIN,const double cacl_max = CACL_MAX);
160  static vector<double> sort_points(Point2f rect_points[]);
161 
162  static bool validate_corners_arrow(vector<Point> contours,
163  const unsigned short convex_arrow_corners = CONVEX_ARROW_CORNERS);
164  //check number of corners of convexhull
165  static bool validate_convexHull(vector<Point> contours,
166  const unsigned short convex_hull_corners = CONVEX_HULL_CORNERS);
167 
168 
169 protected:
170  static void setLabel(cv::Mat& im, const std::string label, std::vector<cv::Point>& contour);
171 
172  static float innerAngle(float px1, float py1, float px2, float py2, float cx1, float cy1);
173 
174  static double angle(cv::Point pt1, cv::Point pt2, cv::Point pt0);
175 
176 };
177 #endif
static const float VAL_MIN_RELATION_LENGTH
Definition: findArrow.h:96
const unsigned short VAL_MAX_LENGTH
For validate_lengths function.
static const unsigned int LINE_THICKNESS
Definition: findArrow.h:91
static const double AREA_MIN
Definition: findArrow.h:106
const double BBCL_MIN
static const double BBCA_MAX
Definition: findArrow.h:101
static const unsigned int EROSION_SIZE_MIN
Definition: findArrow.h:88
static const double BBCL_MIN
Definition: findArrow.h:102
const unsigned short VAL_MIN_LENGTH
static const double BBCA_MIN
Definition: findArrow.h:100
const unsigned short CONVEX_HULL_CORNERS
Variable for validate_convexHull.
static const unsigned short VAL_MAX_LENGTH
Definition: findArrow.h:94
const float VAL_MIN_RELATION_LENGTH
static const float VAL_MAX_RELATION_LENGTH
Definition: findArrow.h:97
const double BBCA_MIN
Variables for validate_contour_Area_Length function.
void Opening(Mat &src, Mat &dest, unsigned int erosion_size)
Morphological operation OPENING.
static const unsigned int MAX_THRESH
Definition: findArrow.h:90
static const unsigned short CONVEX_HULL_CORNERS
Definition: findArrow.h:109
void ProcessMyImage(Mat &src, Mat &dest)
Canny.
static const unsigned short CONVEX_ARROW_CORNERS
Definition: findArrow.h:112
const double BBCL_MAX
static const unsigned short VAL_MIN_LENGTH
Definition: findArrow.h:95
void ProcessEdges(Mat &src, Mat &dest)
Boundig box BW.
cv::Point find_arrow(void)
static const double BBCL_MAX
Definition: findArrow.h:103
const unsigned short CONVEX_ARROW_CORNERS
Variable for validate_corners_arrow.
void multiplymatrixbool(Mat &src, Mat &matbol)
const double BBCA_MAX
const float VAL_MAX_RELATION_LENGTH
static const double CACL_MAX
Definition: findArrow.h:105
static const double CACL_MIN
Definition: findArrow.h:104
static bool found_new_point
Definition: findArrow.h:83
helper function to rotate an image.
static const unsigned int THRESH
Definition: findArrow.h:89
void closing(Mat &src, Mat &dest, unsigned int erosion_size)
Morphological operation Closing.
static bool validate_lengths(cv::Point2f rect_points[], const unsigned short max_length=VAL_MAX_LENGTH, const unsigned short min_length=VAL_MIN_LENGTH, const float min_relation_length=VAL_MIN_RELATION_LENGTH, const float max_relation_length=VAL_MAX_RELATION_LENGTH)
cv::Point calculate_center_contour(cv::Point2f contour[], unsigned int size_contour)
static const unsigned int EROSION_SIZE
Definition: findArrow.h:87
const double CACL_MAX
void descritor(Mat &img_object, Mat &img_scene)
Find discriptors (Match points)
vector< RotatedRect > boundig_box_small(Mat &src_tresh, Mat &threshold_output, vector< vector< cv::Point > > contours, cv::Point &src_centre, bool &havepoint)
FIND THE SMALLEST BOUNDING BOX.
void boundig_box(Mat &src_tresh, Mat &dst)
FIND THE BOUDING BOX.
const double CACL_MIN
vector< vector< cv::Point > > find_contours(Mat &src, Mat &dest, const unsigned int &line_thinckness, const unsigned int &erosion_size_min)
See if the contour have neighbors! (arrow dont have!)


arrow_detection
Author(s): César Sousa
autogenerated on Mon Mar 2 2015 01:31:21