05Robot 3.0

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

Processor_ObjectExtraction.h
Go to the documentation of this file.
1
7 #ifndef PROCESSOR_OBJECTEXTRACTION_H
8 #define PROCESSOR_OBJECTEXTRACTION_H
9
10 #include "Processor.h"
11
12 #include <opencv2/opencv.hpp>
13 #include <opencv2/highgui/highgui.hpp>
14 #include <opencv2/imgproc/imgproc.hpp>
15 #include <opencv2/calib3d/calib3d.hpp>
16
17 #include <QDebug>
18 #include <QVector3D>
19
20 #include <sstream>
24 #ifndef M_PI
25 #define M_PI 3.14159265358979323846
26 #endif
27 using namespace std;
28
29
35 struct sObject {
36 sObject() {
37
38 }
39 sObject(std::string str) {
40 std::stringstream ss;
41 ss.str(str);
42 double rz_temp;
43 std::string token;
44 int i = 0;
45 bool cont = true;
46 while(cont && std::getline(ss, token, ',')) {
47 switch(i) {
48 case 0:
49 break;
50 case 1:
51 image_x = QString::fromStdString(token).toDouble();
52 break;
53 case 2:
54 image_y = QString::fromStdString(token).toDouble();
55 break;
56 case 3:
57 image_area = QString::fromStdString(token).toDouble();
58 break;
59 case 4:
60 workspace_x = QString::fromStdString(token).toDouble();
61 break;
62 case 5:
63 workspace_y = QString::fromStdString(token).toDouble();
64 break;
65 case 6:
66 workspace_z = QString::fromStdString(token).toDouble();
67 break;
68 case 7:
69 size_x = QString::fromStdString(token).toDouble();
70 break;
71 case 8:
72 size_y = QString::fromStdString(token).toDouble();
73 break;
74 case 9:
75 size_z = QString::fromStdString(token).toDouble();
76 break;
77 case 10:
78 bounding_box.center.x = QString::fromStdString(token).toDouble();
79 break;
80 case 11:
81 bounding_box.center.y = QString::fromStdString(token).toDouble();
82 break;
83 case 12:
84 bounding_box.size.width = QString::fromStdString(token).toDouble();
85 break;
86 case 13:
87 bounding_box.size.height = QString::fromStdString(token).toDouble();
88 break;
89 case 14:
90 rz_temp = QString::fromStdString(token).toDouble();
91 bounding_box.angle = rz_temp * 180.0 / M_PI;
92 break;
93 default:
94 cont = false;
95 break;
96 }
97 i++;
98 }
99 }
100 double image_x;
101 double image_y;
102 double image_area;
103 double workspace_x;
104 double workspace_y;
105 double workspace_z;
106 double size_x;
107 double size_y;
108 double size_z;
109 double rz() {
110 return bounding_box.angle / 180.0 * M_PI;
111 }
112 cv::RotatedRect bounding_box;
113 cv::Mat mask;
114
115 std::string to_string() {
116 std::stringstream ss;
117 ss << image_x << ", " << image_y << ", " << image_area << ", " << workspace_x << ", " << workspace_y << ", " << workspace_z << ", " << size_x << ", " << size_y << ", " << size_z << ", " << bounding_box.center.x << ", " << bounding_box.center.y << ", " << bounding_box.size.width << ", " << bounding_box.size.height << ", " << rz();
118 return ss.str();
119 }
120 };
121
122 Q_DECLARE_METATYPE(QVector<sObject>)
123 Q_DECLARE_METATYPE(cv::Mat)
124
125
126
136 class Processor_ObjectExtraction: public Processor
137 {
138 Q_OBJECT
142 ADD_PROPERTY(median_khalfsize, int)
143
144
147 ADD_PROPERTY(workspace_x_offset, double)
151 ADD_PROPERTY(workspace_y_offset, double)
155 ADD_PROPERTY(workspace_z_offset, double)
159 ADD_PROPERTY(workspace_x_size, double)
163 ADD_PROPERTY(workspace_y_size, double)
167 ADD_PROPERTY(object_height, double)
171 ADD_PROPERTY(minimum_object_area, int)
175 ADD_PROPERTY(maximum_object_area, int)
179 ADD_PROPERTY(background_filename, QString)
180 public:
184 Processor_ObjectExtraction();
188 void screenshot(const QString& filename);
189
190 signals:
198 void pickObject(QVector3D pointInMeters, float object_height, float angle, int bin);
199 void object_data(cv::Mat image, QVector<sObject> objects);
200
201 private:
202 cv::Point2d pixel_to_meters(cv::Point2d pixel, cv::Size img_size);
203
204 enum Processor_ObjectExtraction_Mode {Processor_ObjectExtraction_Mode_GetBackground, Processor_ObjectExtraction_Mode_Normal, Processor_ObjectExtraction_Mode_Object_Selected};
205 Processor_ObjectExtraction_Mode mode;
206
207 cv::Ptr<cv::BackgroundSubtractor> pMOG2_;
208 cv::Mat labels_, stats_, centroids_;
209 int x_, y_;
210 int timeout_ = 0;
211 QString screenshotFilename_;
212 bool screenshot_ = false; // TODO REMOVE
213
214 public:
220 int start();
228 int process(int t1, int t2);
241 int processSpecial(string s);
247 int stop();
253 virtual void writeXml(QXmlStreamWriter& stream);
259 virtual void readXml(QXmlStreamReader& stream);
260
261 };
263 #endif
sObject::workspace_z
double workspace_z
Definition: Processor_ObjectExtraction.h:105
ADD_PROPERTY
#define ADD_PROPERTY(member, _type)
Definition: common.h:14
sObject::sObject
sObject()
Definition: Processor_ObjectExtraction.h:36
Processor
Image processor base class.
Definition: Processor.h:28
sObject::to_string
std::string to_string()
Definition: Processor_ObjectExtraction.h:115
sObject::size_y
double size_y
Definition: Processor_ObjectExtraction.h:107
std
sObject::sObject
sObject(std::string str)
Definition: Processor_ObjectExtraction.h:39
M_PI
#define M_PI
Definition: Processor_ObjectExtraction.h:25
Processor.h
sObject::size_x
double size_x
Definition: Processor_ObjectExtraction.h:106
sObject::workspace_y
double workspace_y
Definition: Processor_ObjectExtraction.h:104
sObject::image_area
double image_area
Definition: Processor_ObjectExtraction.h:102
sObject::bounding_box
cv::RotatedRect bounding_box
Definition: Processor_ObjectExtraction.h:112
sObject::image_x
double image_x
Definition: Processor_ObjectExtraction.h:100
sObject::mask
cv::Mat mask
Definition: Processor_ObjectExtraction.h:113
Processor_ObjectExtraction
Object extraction image processor.
Definition: Processor_ObjectExtraction.h:136
sObject::image_y
double image_y
Definition: Processor_ObjectExtraction.h:101
sObject::size_z
double size_z
Definition: Processor_ObjectExtraction.h:108
sObject::rz
double rz()
Definition: Processor_ObjectExtraction.h:109
sObject
Detected object.
Definition: Processor_ObjectExtraction.h:35
sObject::workspace_x
double workspace_x
Definition: Processor_ObjectExtraction.h:103