Object Detection  5.0
Image Processing Using Qt and Opencv
colordetectorcontroller.cpp
1 #include "colordetectorcontroller.h"
2 
3 #include <QDir>
4 #include <QPluginLoader>
5 #include <imageprocessorpluginiface.h>
6 #include "circledetectorpluginmodel.h"
7 #include <QDebug>
8 
9 ColorDetectorController::ColorDetectorController(QObject *parent) : QObject(parent)
10 {
11  pro = new ObjectDetection(this);
12  auto processor = pro;
13  connect(this , SIGNAL(dilationSizeChanged(int)), processor->getDiler(), SLOT(setDilationSize(int)));
14  connect(this , SIGNAL(maxColorChanged(cv::Scalar)), processor->getColDetector(), SLOT(setMaxColor(cv::Scalar)));
15  connect(this , SIGNAL(minColorChanged(cv::Scalar)), processor->getColDetector(), SLOT(setMinColor(cv::Scalar)));
16  connect(this , SIGNAL(param1Changed(int)), processor->getCirDetector(), SLOT(setParam1(int)));
17  connect(this , SIGNAL(param2Changed(int)), processor->getCirDetector(), SLOT(setParam2(int)));
18  connect(this , SIGNAL(minDistChanged(int)), processor->getCirDetector(), SLOT(setMinDist(int)));
19 
20 }
21 
22 
23 int ColorDetectorController::getMinDist() const
24 {
25  return minDist;
26 }
27 
28 void ColorDetectorController::setMinDist(int value)
29 {
30  minDist = value;
31  emit minDistChanged(value);
32 }
33 
34 ObjectDetection *ColorDetectorController::getPro() const
35 {
36  return pro;
37 }
38 
39 void ColorDetectorController::setPro(ObjectDetection *value)
40 {
41  pro = value;
42 }
43 
44 void ColorDetectorController::addFilter(PluginSharedPointer filter)
45 {
46 
47  pro->addFilter(filter);
48 }
49 
50 int ColorDetectorController::getThickness() const
51 {
52  return thickness;
53 }
54 
55 void ColorDetectorController::setThickness(int value)
56 {
57  thickness = std::max(std::max(1, value), std::min(value, 20));
58 }
59 
60 cv::Scalar ColorDetectorController::getCircleColor() const
61 {
62  return circleColor;
63 }
64 
65 void ColorDetectorController::setCircleColor(const cv::Scalar &value)
66 {
67  circleColor = value;
68 }
69 
70 
71 int ColorDetectorController::getParam2() const
72 {
73  return param2;
74 }
75 
76 void ColorDetectorController::setParam2(int value)
77 {
78  param2 = value;
79  emit param2Changed(value);
80 
81 }
82 
83 int ColorDetectorController::getParam1() const
84 {
85  return param1;
86 }
87 
88 void ColorDetectorController::setParam1(int value)
89 {
90  param1 = value;
91  emit param1Changed(value);
92 
93 }
94 
95 
96 
97 cv::Scalar ColorDetectorController::getMaxColor() const
98 {
99  return maxColor;
100 }
101 
102 void ColorDetectorController::setMaxColor(const cv::Scalar &value)
103 {
104  maxColor = value;
105  emit maxColorChanged(value);
106 
107 }
108 
109 QImage ColorDetectorController::detectObject(const cv::Mat &t)
110 {
111  auto v = qobject_cast<ObjectDetection*>(getPro());
112  v->setImg(t);
113  this->colored = v->getColDetector()->getDst();
114  this->dialted = v->getDiler()->getDst();
115  std::vector<cv::Vec3f> vec = v->processImage().value<std::vector<cv::Vec3f>>();
116  for(const cv::Vec3f& i : vec){
117  emit xyrChanged(i[0], i[1], i[2]);
118  cv::Point center(round(i[0]), round(i[1]));
119  int radius = round(i[2]);
120  cv::circle(t, center, radius, circleColor, thickness, 8, 0 );
121 
122  }
123  return Utilities::Utils::toImage(t);
124 }
125 
126 cv::Scalar ColorDetectorController::getMinColor() const
127 {
128  return minColor;
129 }
130 
131 void ColorDetectorController::setMinColor(const cv::Scalar &value)
132 {
133  minColor = value;
134  emit minColorChanged(value);
135 }
136 
137 
138 int ColorDetectorController::getDilationSize() const
139 {
140  return dilationSize;
141 }
142 
143 void ColorDetectorController::setDilationSize(int value)
144 {
145  dilationSize = value;
146  emit dilationSizeChanged(value);
147 }
this class is used to detect a a colored circle object(s)