-
Notifications
You must be signed in to change notification settings - Fork 0
/
linefinder.hpp
95 lines (76 loc) · 3.09 KB
/
linefinder.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef LINEFINDER_H
#define LINEFINDER_H
#include <opencv2/opencv.hpp>
#include <fstream>
#include <vector>
class LineFinder
{
private:
cv::Mat img;
// this vector contains the end points
// of detected lines
std::vector<cv::Vec4i> lines;
// resolution parameters for accumulator
double deltaRho;
double deltaTheta;
int minVote;
double minLength;
double maxGap;
public:
LineFinder();
void setAccResolution(double dRho,
double dTheta);
void setMinVote(int minv);
void setLineLengthAndGap(double length,
double gap);
cv::Mat & getImage();
/*!
* \brief Access the detected lines.
* \return lines
*/
std::vector<cv::Vec4i>& getLines();
int setImage(std::string filePath);
int setImage(cv::Mat image);
std::vector<cv::Vec4i> findLines();
void drawDetectedLines(cv::Scalar color = cv::Scalar(255, 255, 255));
/*! \author zemann
*
* \brief Creates a refined image by removing outer pixels of the structures in the image.
*
* The function makes sure that the image is grayscale, then applies a inverted threshold on it to obtain a binary image.
* In a loop, which ends when all pixels of the image are zero, the image is opened to remove unneccessary pixels,
* then this opened image is subtracted from the original image, which is in return copied to skeleton.
* At last, the image is eroded. This then is the starting image for the next iteration. The skeleton is returned.
* The function is based on this blog entry:
* http://felix.abecassis.me/2011/09/opencv-morphological-skeleton
*
* \param threshold[in]: optional parameter for specifing the threshold limit. The mode is always THRESH_BINARY.
*
* @return The created skeleton image.
*/
void createSkeleton(int threshold = 127);
/*! \author zemann
*
* \brief Stores the image in a format SFML can read for further processing.
*
* Firstly the function resizes a copy of the image (same size) and the lines depending on their size:
* < 512px: no rescale
* up to 1024: scale 2
* up to 2048: scale 4
* > 2048: scale 6
* NOTE: These limits and scales were chosen quite randomly and may change in the next revision.
* Then the lines are drawn on the (grayscale) copy and a sort of a 'threshold' is performed:
* If the pixel value is unequal 0, the corresponding value in a vector of a vector of int (represents the image)
* is set to 1 (line), otherwise to 0.
* This may change in the future because a certain number could be used for certain terrain objects (walls, obstacles, etc.).
*
* @return vector of a vector of int containing the line information.
*/
std::vector<std::vector<int> > saveToVec();
/*!
* \brief Draws the beginning and the ending of a detected line on the original image. For debugging purposes.
*/
void drawLinePoints();
void refineLines();
};
#endif // LINEFINDER_H