35 #include "ui_addObjectDialog.h" 41 #include <QGraphicsScene> 42 #include <QGraphicsPixmapItem> 43 #include <QMessageBox> 45 #include <opencv2/imgproc/imgproc.hpp> 46 #include <opencv2/highgui/highgui.hpp> 56 ui_ =
new Ui_addObjectDialog();
63 connect(
ui_->pushButton_cancel, SIGNAL(clicked()),
this, SLOT(
cancel()));
64 connect(
ui_->pushButton_back, SIGNAL(clicked()),
this, SLOT(
back()));
65 connect(
ui_->pushButton_next, SIGNAL(clicked()),
this, SLOT(
next()));
66 connect(
ui_->pushButton_takePicture, SIGNAL(clicked()),
this, SLOT(
takePicture()));
70 connect(
ui_->cameraView, SIGNAL(roiChanged(
const cv::Rect &)),
this, SLOT(
updateNextButton(
const cv::Rect &)));
71 ui_->cameraView->setMirrorView(mirrorView);
77 else if(!image.empty())
113 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
115 QDialog::closeEvent(event);
176 if(
ui_->comboBox_selection->currentIndex() == 1)
178 if(
ui_->cameraView->selectedItems().size() > 0)
180 ui_->pushButton_next->setEnabled(
true);
184 ui_->pushButton_next->setEnabled(
false);
189 if(
roi_.width == 0 ||
roi_.height == 0)
191 ui_->pushButton_next->setEnabled(
false);
195 ui_->pushButton_next->setEnabled(
true);
211 ui_->pushButton_cancel->setEnabled(
true);
212 ui_->pushButton_back->setEnabled(
false);
213 ui_->pushButton_next->setEnabled(
false);
214 ui_->pushButton_takePicture->setEnabled(
true);
215 ui_->label_instruction->setText(tr(
"Place the object in front of the camera and click \"Take picture\"."));
216 ui_->pushButton_next->setText(tr(
"Next"));
217 ui_->cameraView->setVisible(
true);
218 ui_->cameraView->clearRoiSelection();
219 ui_->objectView->setVisible(
false);
220 ui_->cameraView->setGraphicsViewMode(
false);
221 ui_->comboBox_selection->setVisible(
false);
224 QMessageBox::critical(
this, tr(
"Camera error"), tr(
"Camera is not started!"));
225 ui_->pushButton_takePicture->setEnabled(
false);
229 connect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
236 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
240 ui_->pushButton_cancel->setEnabled(
true);
242 ui_->pushButton_next->setEnabled(
false);
243 ui_->pushButton_takePicture->setEnabled(
false);
244 ui_->pushButton_next->setText(tr(
"Next"));
245 ui_->cameraView->setVisible(
true);
246 ui_->cameraView->clearRoiSelection();
247 ui_->objectView->setVisible(
false);
248 ui_->comboBox_selection->setVisible(
true);
250 if(
ui_->comboBox_selection->currentIndex() == 1)
252 ui_->label_instruction->setText(tr(
"Select features representing the object."));
253 ui_->cameraView->setGraphicsViewMode(
true);
257 ui_->label_instruction->setText(tr(
"Select region representing the object."));
258 ui_->cameraView->setGraphicsViewMode(
false);
266 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
270 ui_->pushButton_cancel->setEnabled(
true);
271 ui_->pushButton_back->setEnabled(
true);
272 ui_->pushButton_takePicture->setEnabled(
false);
273 ui_->pushButton_next->setText(tr(
"End"));
274 ui_->cameraView->setVisible(
true);
275 ui_->objectView->setVisible(
true);
276 ui_->objectView->setMirrorView(
ui_->cameraView->isMirrorView());
277 ui_->objectView->setSizedFeatures(
ui_->cameraView->isSizedFeatures());
278 ui_->comboBox_selection->setVisible(
false);
279 if(
ui_->comboBox_selection->currentIndex() == 1)
281 ui_->cameraView->setGraphicsViewMode(
true);
285 ui_->cameraView->setGraphicsViewMode(
false);
288 std::vector<cv::KeyPoint> selectedKeypoints =
ui_->cameraView->selectedKeypoints();
292 ((
ui_->comboBox_selection->currentIndex() == 1 && selectedKeypoints.size()) ||
293 (
ui_->comboBox_selection->currentIndex() == 0 &&
roi_.width &&
roi_.height)))
295 if(
ui_->comboBox_selection->currentIndex() == 1)
302 if(
ui_->comboBox_selection->currentIndex() == 1)
306 for(
unsigned int i=0; i<selectedKeypoints.size(); ++i)
308 selectedKeypoints.at(i).pt.x -=
roi_.x;
309 selectedKeypoints.at(i).pt.y -=
roi_.y;
316 selectedKeypoints.clear();
320 ui_->objectView->updateData(selectedKeypoints, QMultiMap<int,int>());
321 ui_->objectView->setMinimumSize(
roi_.width,
roi_.height);
322 ui_->objectView->update();
323 ui_->pushButton_next->setEnabled(
true);
327 UINFO(
"Please select items");
328 ui_->pushButton_next->setEnabled(
false);
330 ui_->label_instruction->setText(tr(
"Selection : %1 features").arg(selectedKeypoints.size()));
334 std::vector<cv::KeyPoint> keypoints =
ui_->objectView->keypoints();
335 if((
ui_->comboBox_selection->currentIndex() == 1 && keypoints.size()) ||
336 (
ui_->comboBox_selection->currentIndex() == 0 &&
roi_.width &&
roi_.height))
345 if(keypoints.size() != (
unsigned int)descriptors.rows)
347 UERROR(
"keypoints=%d != descriptors=%d", (
int)keypoints.size(), descriptors.rows);
376 if(image.channels() != 1 || image.depth() != CV_8U)
386 std::vector<cv::KeyPoint> keypoints;
390 ui_->cameraView->updateData(keypoints, QMultiMap<int,int>());
391 ui_->cameraView->update();
395 UWARN(
"Camera cannot get more images (maybe the end of stream is reached)...");
402 cv::Rect roi(0,0,0,0);
403 int x1=0,x2=0,h1=0,h2=0;
404 for(
unsigned int i=0; i<kpts.size(); ++i)
406 float radius = kpts.at(i).size / 2;
409 x1 = int(kpts.at(i).pt.x - radius);
410 x2 = int(kpts.at(i).pt.x + radius);
411 h1 = int(kpts.at(i).pt.y - radius);
412 h2 = int(kpts.at(i).pt.y + radius);
416 if(x1 >
int(kpts.at(i).pt.x - radius))
418 x1 = int(kpts.at(i).pt.x - radius);
420 else if(x2 <
int(kpts.at(i).pt.x + radius))
422 x2 = int(kpts.at(i).pt.x + radius);
424 if(h1 >
int(kpts.at(i).pt.y - radius))
426 h1 = int(kpts.at(i).pt.y - radius);
428 else if(h2 <
int(kpts.at(i).pt.y + radius))
430 h2 = int(kpts.at(i).pt.y + radius);
ObjSignature * objSignature_
void update(const cv::Mat &)
static Feature2D * createKeypointDetector()
void changeSelectionMode()
virtual ~AddObjectDialog()
#define UASSERT(condition)
virtual void closeEvent(QCloseEvent *event)
AddObjectDialog(Camera *camera, const cv::Mat &image, bool mirrorView, QWidget *parent=0, Qt::WindowFlags f=0)
virtual void detect(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints, const cv::Mat &mask=cv::Mat())
void setData(const std::vector< cv::KeyPoint > &keypoints, const cv::Mat &descriptors)
cv::Rect computeROI(const std::vector< cv::KeyPoint > &kpts)
virtual void compute(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints, cv::Mat &descriptors)
ULogger class and convenient macros.
static Feature2D * createDescriptorExtractor()
FINDOBJECT_EXP QImage cvtCvMat2QImage(const cv::Mat &image, bool isBgr=true)
void retrieveObject(ObjWidget **widget, ObjSignature **signature)