60 #include <qcheckbox.h>
61 #include <qradiobutton.h>
62 #include <qbuttongroup.h>
63 #include <qpushbutton.h>
64 #include <qlineedit.h>
67 #include <qfiledialog.h>
79 this->height = height;
85 m_pLineEditColorParameterFile = 0;
89 m_bUpdateParameterSet =
true;
92 QRadioButton *pCheckBoxColorSkin =
new QRadioButton(
"Skin",
this);
93 pCheckBoxColorSkin->setFixedWidth(200);
94 pCheckBoxColorSkin->move(width + 250, 20);
96 QRadioButton *pCheckBoxColorYellow =
new QRadioButton(
"Yellow",
this);
97 pCheckBoxColorYellow->setFixedWidth(200);
98 pCheckBoxColorYellow->move(width + 250, 45);
100 QRadioButton *pCheckBoxColorOrange =
new QRadioButton(
"Orange",
this);
101 pCheckBoxColorOrange->setFixedWidth(200);
102 pCheckBoxColorOrange->move(width + 250, 70);
104 QRadioButton *pCheckBoxColorRed =
new QRadioButton(
"Red",
this);
105 pCheckBoxColorRed->setFixedWidth(200);
106 pCheckBoxColorRed->move(width + 250, 95);
108 QRadioButton *pCheckBoxColorBlue =
new QRadioButton(
"Blue",
this);
109 pCheckBoxColorBlue->setFixedWidth(200);
110 pCheckBoxColorBlue->move(width + 350, 20);
112 QRadioButton *pCheckBoxColorGreen =
new QRadioButton(
"Green",
this);
113 pCheckBoxColorGreen->setFixedWidth(200);
114 pCheckBoxColorGreen->move(width + 350, 45);
116 QRadioButton *pCheckBoxColorCustom =
new QRadioButton(
"Custom",
this);
117 pCheckBoxColorCustom->setFixedWidth(200);
118 pCheckBoxColorCustom->move(width + 350, 70);
121 m_pCheckBoxShowSegmentedImage =
new QCheckBox(
"Show Segmented Image",
this);
122 m_pCheckBoxShowSegmentedImage->setChecked(
false);
123 m_pCheckBoxShowSegmentedImage->setFixedWidth(200);
124 m_pCheckBoxShowSegmentedImage->move(width + 20, 120);
126 m_pCheckBoxShowRightImage =
new QCheckBox(
"Show Right Image",
this);
127 m_pCheckBoxShowRightImage->setChecked(
false);
128 m_pCheckBoxShowRightImage->setFixedWidth(200);
129 m_pCheckBoxShowRightImage->move(width + 20, 145);
132 m_pColorButtonGroup =
new QButtonGroup();
134 #if QT_VERSION >= 0x040000
135 m_pColorButtonGroup->addButton(pCheckBoxColorSkin);
136 m_pColorButtonGroup->addButton(pCheckBoxColorYellow);
137 m_pColorButtonGroup->addButton(pCheckBoxColorOrange);
138 m_pColorButtonGroup->addButton(pCheckBoxColorRed);
139 m_pColorButtonGroup->addButton(pCheckBoxColorBlue);
140 m_pColorButtonGroup->addButton(pCheckBoxColorGreen);
141 m_pColorButtonGroup->addButton(pCheckBoxColorCustom);
143 m_pColorButtonGroup->insert(pCheckBoxColorSkin);
144 m_pColorButtonGroup->insert(pCheckBoxColorYellow);
145 m_pColorButtonGroup->insert(pCheckBoxColorOrange);
146 m_pColorButtonGroup->insert(pCheckBoxColorRed);
147 m_pColorButtonGroup->insert(pCheckBoxColorBlue);
148 m_pColorButtonGroup->insert(pCheckBoxColorGreen);
149 m_pColorButtonGroup->insert(pCheckBoxColorCustom);
153 m_pSliderColorH =
new QSlider(Qt::Horizontal,
this);
154 m_pSliderColorH->setRange(0, 180);
155 m_pSliderColorH->setPageStep(1);
156 m_pSliderColorH->setValue(124);
157 m_pSliderColorH->setFixedWidth(180);
158 m_pSliderColorH->setFixedHeight(20);
159 m_pSliderColorH->move(width + 255, 130);
161 m_pSliderColorHT =
new QSlider(Qt::Horizontal,
this);
162 m_pSliderColorHT->setRange(0, 180);
163 m_pSliderColorHT->setPageStep(1);
164 m_pSliderColorHT->setValue(26);
165 m_pSliderColorHT->setFixedWidth(180);
166 m_pSliderColorHT->setFixedHeight(20);
167 m_pSliderColorHT->move(width + 255, 155);
169 m_pSliderColorMinS =
new QSlider(Qt::Horizontal,
this);
170 m_pSliderColorMinS->setRange(0, 255);
171 m_pSliderColorMinS->setPageStep(1);
172 m_pSliderColorMinS->setValue(109);
173 m_pSliderColorMinS->setFixedWidth(180);
174 m_pSliderColorMinS->setFixedHeight(20);
175 m_pSliderColorMinS->move(width + 255, 180);
177 m_pSliderColorMaxS =
new QSlider(Qt::Horizontal,
this);
178 m_pSliderColorMaxS->setRange(0, 255);
179 m_pSliderColorMaxS->setPageStep(1);
180 m_pSliderColorMaxS->setValue(255);
181 m_pSliderColorMaxS->setFixedWidth(180);
182 m_pSliderColorMaxS->setFixedHeight(20);
183 m_pSliderColorMaxS->move(width + 255, 205);
185 m_pSliderColorMinV =
new QSlider(Qt::Horizontal,
this);
186 m_pSliderColorMinV->setRange(0, 255);
187 m_pSliderColorMinV->setPageStep(1);
188 m_pSliderColorMinV->setValue(0);
189 m_pSliderColorMinV->setFixedWidth(180);
190 m_pSliderColorMinV->setFixedHeight(20);
191 m_pSliderColorMinV->move(width + 255, 230);
193 m_pSliderColorMaxV =
new QSlider(Qt::Horizontal,
this);
194 m_pSliderColorMaxV->setRange(0, 255);
195 m_pSliderColorMaxV->setPageStep(1);
196 m_pSliderColorMaxV->setValue(255);
197 m_pSliderColorMaxV->setFixedWidth(180);
198 m_pSliderColorMaxV->setFixedHeight(20);
199 m_pSliderColorMaxV->move(width + 255, 255);
202 m_pLineEditColorParameterFile =
new QLineEdit(
this);
203 m_pLineEditColorParameterFile->setText(
"files/colors_kitchen.txt");
204 m_pLineEditColorParameterFile->setReadOnly(
true);
205 m_pLineEditColorParameterFile->setFixedWidth(250);
206 m_pLineEditColorParameterFile->setFixedHeight(20);
207 m_pLineEditColorParameterFile->move(width + 20, 390);
210 QPushButton *pPrintColorParametersButton =
new QPushButton(
this);
211 pPrintColorParametersButton->setText(
"Print Color Parameters");
212 pPrintColorParametersButton->setFixedHeight(20);
213 pPrintColorParametersButton->setFixedWidth(180);
214 pPrintColorParametersButton->move(width + 20, 190);
216 QPushButton *pLoadColorParametersButton =
new QPushButton(
this);
217 pLoadColorParametersButton->setText(
"Load Color Parameters");
218 pLoadColorParametersButton->setFixedHeight(20);
219 pLoadColorParametersButton->setFixedWidth(180);
220 pLoadColorParametersButton->move(width + 20, 215);
222 QPushButton *pSaveColorParametersButton =
new QPushButton(
this);
223 pSaveColorParametersButton->setText(
"Save Color Parameters");
224 pSaveColorParametersButton->setFixedHeight(20);
225 pSaveColorParametersButton->setFixedWidth(180);
226 pSaveColorParametersButton->move(width + 20, 240);
228 QPushButton *pColorParameterFileBrowseButton =
new QPushButton(
this);
229 pColorParameterFileBrowseButton->setText(
"Browse Color Parameter File");
230 pColorParameterFileBrowseButton->setFixedHeight(20);
231 pColorParameterFileBrowseButton->setFixedWidth(155);
232 pColorParameterFileBrowseButton->move(width + 280, 390);
234 QLabel *pLabelH =
new QLabel(
this);
235 pLabelH->setText(
"H");
236 pLabelH->setFixedWidth(40);
237 pLabelH->setFixedHeight(20);
238 pLabelH->move(width + 210, 130);
240 QLabel *pLabelHTol =
new QLabel(
this);
241 pLabelHTol->setText(
"H Tol");
242 pLabelHTol->setFixedWidth(40);
243 pLabelHTol->setFixedHeight(20);
244 pLabelHTol->move(width + 210, 155);
246 QLabel *pLabelMinS =
new QLabel(
this);
247 pLabelMinS->setText(
"S Min");
248 pLabelMinS->setFixedWidth(40);
249 pLabelMinS->setFixedHeight(20);
250 pLabelMinS->move(width + 210, 180);
252 QLabel *pLabelMaxS =
new QLabel(
this);
253 pLabelMaxS->setText(
"S Max");
254 pLabelMaxS->setFixedWidth(40);
255 pLabelMaxS->setFixedHeight(20);
256 pLabelMaxS->move(width + 210, 205);
258 QLabel *pLabelMinV =
new QLabel(
this);
259 pLabelMinV->setText(
"V Min");
260 pLabelMinV->setFixedWidth(40);
261 pLabelMinV->setFixedHeight(20);
262 pLabelMinV->move(width + 210, 230);
264 QLabel *pLabelMaxV =
new QLabel(
this);
265 pLabelMaxV->setText(
"V Max");
266 pLabelMaxV->setFixedWidth(40);
267 pLabelMaxV->setFixedHeight(20);
268 pLabelMaxV->move(width + 210, 255);
271 SliderValueChanged(0);
274 ColorRadioButtonClicked(3);
275 #if QT_VERSION >= 0x040000
276 m_pColorButtonGroup->button(3)->click();
278 m_pColorButtonGroup->setButton(3);
282 connect(m_pColorButtonGroup, SIGNAL(clicked(
int)),
this, SLOT(ColorRadioButtonClicked(
int)));
283 connect(pPrintColorParametersButton, SIGNAL(clicked()),
this, SLOT(PrintColorParametersButtonClicked()));
284 connect(pLoadColorParametersButton, SIGNAL(clicked()),
this, SLOT(LoadColorParametersButtonClicked()));
285 connect(pSaveColorParametersButton, SIGNAL(clicked()),
this, SLOT(SaveColorParametersButtonClicked()));
286 connect(pColorParameterFileBrowseButton, SIGNAL(clicked()),
this, SLOT(ColorParameterFileBrowseButtonClicked()));
287 connect(m_pSliderColorH, SIGNAL(valueChanged(
int)),
this, SLOT(SliderValueChanged(
int)));
288 connect(m_pSliderColorHT, SIGNAL(valueChanged(
int)),
this, SLOT(SliderValueChanged(
int)));
289 connect(m_pSliderColorMinS, SIGNAL(valueChanged(
int)),
this, SLOT(SliderValueChanged(
int)));
290 connect(m_pSliderColorMaxS, SIGNAL(valueChanged(
int)),
this, SLOT(SliderValueChanged(
int)));
291 connect(m_pSliderColorMinV, SIGNAL(valueChanged(
int)),
this, SLOT(SliderValueChanged(
int)));
292 connect(m_pSliderColorMaxV, SIGNAL(valueChanged(
int)),
this, SLOT(SliderValueChanged(
int)));
297 delete m_pColorParameterSet;
305 void CQTColorParameterWindow::LoadColorParametersButtonClicked()
307 #if QT_VERSION >= 0x040000
308 m_pColorParameterSet->
LoadFromFile(m_pLineEditColorParameterFile->text().toLatin1().constData());
309 QAbstractButton *pActiveButton = m_pColorButtonGroup->checkedButton();
311 m_pColorParameterSet->
LoadFromFile(m_pLineEditColorParameterFile->text().latin1());
312 QButton *pActiveButton = m_pColorButtonGroup->selected();
317 ColorRadioButtonClicked(m_pColorButtonGroup->id(pActiveButton));
321 void CQTColorParameterWindow::SaveColorParametersButtonClicked()
324 #if QT_VERSION >= 0x040000
325 m_pColorParameterSet->
SaveToFile(m_pLineEditColorParameterFile->text().toLatin1().constData());
327 m_pColorParameterSet->
SaveToFile(m_pLineEditColorParameterFile->text().latin1());
331 void CQTColorParameterWindow::PrintColorParametersButtonClicked()
333 printf(
"color parameters: (%i, %i, %i, %i, %i, %i)\n", m_pSliderColorH->value(), m_pSliderColorHT->value(), m_pSliderColorMinS->value(), m_pSliderColorMaxS->value(), m_pSliderColorMinV->value(), m_pSliderColorMaxV->value());
336 void CQTColorParameterWindow::ColorParameterFileBrowseButtonClicked()
338 #if QT_VERSION >= 0x040000
339 QString s = QFileDialog::getOpenFileName(
this,tr(
"Choose a file"),
"",tr(
"Text (*.txt)") );
341 QString s = QFileDialog::getOpenFileName(
"",
"Text (*.txt)",
this,
"Open File Dialog",
"Choose a file");
345 m_pLineEditColorParameterFile->setText(s);
348 void CQTColorParameterWindow::SliderValueChanged(
int nValue)
350 if (!m_bUpdateParameterSet)
353 if (m_color ==
eNone)
355 custom_par1 = m_pSliderColorH->value();
356 custom_par2 = m_pSliderColorHT->value();
357 custom_par3 = m_pSliderColorMinS->value();
358 custom_par4 = m_pSliderColorMaxS->value();
359 custom_par5 = m_pSliderColorMinV->value();
360 custom_par6 = m_pSliderColorMaxV->value();
365 m_pSliderColorH->value(),
366 m_pSliderColorHT->value(),
367 m_pSliderColorMinS->value(),
368 m_pSliderColorMaxS->value(),
369 m_pSliderColorMinV->value(),
370 m_pSliderColorMaxV->value()
375 void CQTColorParameterWindow::ColorRadioButtonClicked(
int id)
377 m_bUpdateParameterSet =
false;
379 if (
id >= 0 &&
id <= 5)
383 case 0: m_color =
eSkin;
break;
384 case 1: m_color =
eYellow;
break;
385 case 2: m_color =
eOrange;
break;
386 case 3: m_color =
eRed;
break;
387 case 4: m_color =
eBlue;
break;
388 case 5: m_color =
eGreen;
break;
400 m_pSliderColorH->setValue(custom_par1);
401 m_pSliderColorHT->setValue(custom_par2);
402 m_pSliderColorMinS->setValue(custom_par3);
403 m_pSliderColorMaxS->setValue(custom_par4);
404 m_pSliderColorMinV->setValue(custom_par5);
405 m_pSliderColorMaxV->setValue(custom_par6);
409 m_bUpdateParameterSet =
true;
414 const int nIndex = (nImages == 1 || !m_pCheckBoxShowRightImage->isChecked()) ? 0 : 1;
420 ImageProcessor::FilterHSV(&hsv_image, &result_image, m_pSliderColorH->value(), m_pSliderColorHT->value(), m_pSliderColorMinS->value(), m_pSliderColorMaxS->value(), m_pSliderColorMinV->value(), m_pSliderColorMaxV->value());
424 if (m_pCheckBoxShowSegmentedImage->isChecked())
432 return m_pColorParameterSet;
void Update(const CByteImage *const *ppInputImages, int nImages)
const CColorParameterSet * GetColorParameterSet() const
void DrawImage(const CByteImage *pImage, int x=0, int y=0)
bool LoadFromFile(const char *pFileName)
bool SaveToFile(const char *pFileName)
bool Erode(const CByteImage *pInputImage, CByteImage *pOutputImage, int nMaskSize=3, const MyRegion *pROI=0)
Applies a morphological erode operation to a binary CByteImage and writes the result to a binary CByt...
bool FilterHSV(const CByteImage *pInputImage, CByteImage *pOutputImage, unsigned char hue, unsigned char tol_hue, unsigned char min_sat, unsigned char max_sat, unsigned char min_v, unsigned char max_v, const MyRegion *pROI=0)
Performs color filtering with binarization for an HSV CByteImage and writes the result to a grayscale...
bool CalculateHSVImage(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0)
Computes the HSV image for a RGB CByteImage and writes the result to a CByteImage.
const int * GetColorParameters(ObjectColor color) const
CQTColorParameterWindow(int width, int height)
void SetColorParameters(ObjectColor color, int par1, int par2, int par3, int par4, int par5, int par6)
~CQTColorParameterWindow()
bool Dilate(const CByteImage *pInputImage, CByteImage *pOutputImage, int nMaskSize=3, const MyRegion *pROI=0)
Applies a morphological dilate operation to a binary CByteImage and writes the result to a binary CBy...
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...