-
Notifications
You must be signed in to change notification settings - Fork 2
/
edge_detector.h
173 lines (115 loc) · 4.68 KB
/
edge_detector.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifndef EDGE_DETECTOR
#define EDGE_DETECTOR
#include <string>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/image_viewer.h>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/console/parse.h>
#include "plane_segmenter.h"
#include "SimpleConfig.h"
//mouse click callback- currently prints out location of mouse click
//on viewer
void mouseClick(const pcl::visualization::MouseEvent &event, void* detector);
//keyboard event handler callback
void keyboardEventOccurred (const pcl::visualization::KeyboardEvent
&event, void* detector );
class EdgeDetector
{
public:
typedef pcl::PointXYZRGBA Point;
typedef pcl::PointCloud<Point> PointCloud;
typedef std::vector< cv::Vec4i > LineArray;
typedef pcl::visualization::PointCloudColorHandlerRGBField<Point>
ColorHandler;
typedef std::vector< pcl::PointXYZ > LinePosArray;
std::string filename;
const float deviceFocalLength;
const float pixel_size;
bool viewerIsInitialized, doWrite;
bool showImage;
double radius, minDistOffPlane, maxDistOffPlane;
float fx, fy, u0, v0;
bool waiting;
int current_grasp_index;
Eigen::Vector3f handlePos;
Eigen::Vector3f handleAxis;
double handleRadius;
Eigen::Vector2i handle0, handle1;
//these hold information on the current plane
//segmented picture.
PointCloud::ConstPtr curr_cloud;
std::vector<plane_data> planes;
int frame_index; //the index of the plane currently
//being viewed
//the xyz points of the corners of the doors in 3D space
std::vector< pcl::PointXYZ > doorPoints;
pcl::IndicesPtr handleIndices;
pcl::ModelCoefficients handleCoeffs;
//the u, v points of the corners of the doors in
//the picture plane
std::vector< Eigen::Vector2i > drawPoints;
//a simple constructor using a config file.
EdgeDetector ( const std::string & configFile );
//this function will run until the reader throws an error about
//a non-existant file.
void runWithInputFile();
//run with input from the camera
void run ();
//the doorPos is the position of the center of the door,
void getDoorInfo(double & height, double & width,
Eigen::Vector3f & doorPos,
Eigen::Vector3f & doorRot );
//the length is how long the door hangle is, the
//upward thickness of the door handle.
//The offset is an (x,y,z) vector offset from the center of the door.
//Or maybe
void getHandleInfo( double & length, double & height,
Eigen::Vector3f & center );
//add a u, v point to the set of points,
int addDoorPoint ( int u, int v);
//draw the lines that the segmenter found
void drawLines ();
void drawHandle();
pcl::PointXYZ projectPoint( int u, int v, int p );
//if the points do not follow a counter clockwise ordering,
//reorder them so that they do.
void orderPoints();
void getHandlePoints();
double distanceFromPlane( const pcl::PointXYZRGBA & point,
const pcl::ModelCoefficients & coeffs);
private:
SimpleConfig config;
//this holds a set of colors for visualization
std::vector< cv::Vec3i > colors;
int view1, view2;
pcl::visualization::PCLVisualizer * line_viewer;
pcl::visualization::ImageViewer * image_viewer;
pcl::visualization::ImageViewer * plane_viewer;
PlaneSegmenter segmenter;
//create a viewer that holds lines and a point cloud.
void updateViewer( const PointCloud::ConstPtr &cloud,
const std::vector< LinePosArray > & planarLines );
void initViewer( const PointCloud::ConstPtr & cloud );
//this implements a left of test, and switches any
//points that fail the left-of test.
void left_of_switch( const int index1, const int index2, const int index3 );
//point cloud callback function gets new pointcloud and runs segmentation
//algorithm
void cloud_cb_ (const PointCloud::ConstPtr &cloud);
//This is the main door specifying event loop.
void waitAndDisplay();
//clear the plane viewer of the lines.
void removeAllDoorLines();
//saves pcd files from grabbed pointclouds
void savePointCloud(const PointCloud & cloud);
//reads existing pcd files
void readPointCloud(PointCloud::Ptr & cloud);
//a utility function to change the color of a point cloud.
//this is currently unused.
inline void convertColor( PointCloud::Ptr & cloud,
cv::Mat & mat,
pcl::PointIndices::Ptr inliers);
};
#endif