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> 47 #include <opencv2/imgproc/imgproc_c.h> 57 ui_ =
new Ui_addObjectDialog();
64 connect(
ui_->pushButton_cancel, SIGNAL(clicked()),
this, SLOT(
cancel()));
65 connect(
ui_->pushButton_back, SIGNAL(clicked()),
this, SLOT(
back()));
66 connect(
ui_->pushButton_next, SIGNAL(clicked()),
this, SLOT(
next()));
67 connect(
ui_->pushButton_takePicture, SIGNAL(clicked()),
this, SLOT(
takePicture()));
71 connect(
ui_->cameraView, SIGNAL(roiChanged(
const cv::Rect &)),
this, SLOT(
updateNextButton(
const cv::Rect &)));
72 ui_->cameraView->setMirrorView(mirrorView);
78 else if(!image.empty())
114 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
117 QDialog::closeEvent(event);
178 if(
ui_->comboBox_selection->currentIndex() == 1)
180 if(
ui_->cameraView->selectedItems().size() > 0)
182 ui_->pushButton_next->setEnabled(
true);
186 ui_->pushButton_next->setEnabled(
false);
191 if(
roi_.width == 0 ||
roi_.height == 0)
193 ui_->pushButton_next->setEnabled(
false);
197 ui_->pushButton_next->setEnabled(
true);
213 ui_->pushButton_cancel->setEnabled(
true);
214 ui_->pushButton_back->setEnabled(
false);
215 ui_->pushButton_next->setEnabled(
false);
216 ui_->pushButton_takePicture->setEnabled(
true);
217 ui_->label_instruction->setText(tr(
"Place the object in front of the camera and click \"Take picture\"."));
218 ui_->pushButton_next->setText(tr(
"Next"));
219 ui_->cameraView->setVisible(
true);
220 ui_->cameraView->clearRoiSelection();
221 ui_->objectView->setVisible(
false);
222 ui_->cameraView->setGraphicsViewMode(
false);
223 ui_->comboBox_selection->setVisible(
false);
226 QMessageBox::critical(
this, tr(
"Camera error"), tr(
"Camera is not started!"));
227 ui_->pushButton_takePicture->setEnabled(
false);
231 connect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
239 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
244 ui_->pushButton_cancel->setEnabled(
true);
246 ui_->pushButton_next->setEnabled(
false);
247 ui_->pushButton_takePicture->setEnabled(
false);
248 ui_->pushButton_next->setText(tr(
"Next"));
249 ui_->cameraView->setVisible(
true);
250 ui_->cameraView->clearRoiSelection();
251 ui_->objectView->setVisible(
false);
252 ui_->comboBox_selection->setVisible(
true);
254 if(
ui_->comboBox_selection->currentIndex() == 1)
256 ui_->label_instruction->setText(tr(
"Select features representing the object."));
257 ui_->cameraView->setGraphicsViewMode(
true);
261 ui_->label_instruction->setText(tr(
"Select region representing the object."));
262 ui_->cameraView->setGraphicsViewMode(
false);
270 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
275 ui_->pushButton_cancel->setEnabled(
true);
276 ui_->pushButton_back->setEnabled(
true);
277 ui_->pushButton_takePicture->setEnabled(
false);
278 ui_->pushButton_next->setText(tr(
"End"));
279 ui_->cameraView->setVisible(
true);
280 ui_->objectView->setVisible(
true);
281 ui_->objectView->setMirrorView(
ui_->cameraView->isMirrorView());
282 ui_->objectView->setSizedFeatures(
ui_->cameraView->isSizedFeatures());
283 ui_->comboBox_selection->setVisible(
false);
284 if(
ui_->comboBox_selection->currentIndex() == 1)
286 ui_->cameraView->setGraphicsViewMode(
true);
290 ui_->cameraView->setGraphicsViewMode(
false);
293 std::vector<cv::KeyPoint> selectedKeypoints =
ui_->cameraView->selectedKeypoints();
297 ((
ui_->comboBox_selection->currentIndex() == 1 && selectedKeypoints.size()) ||
298 (
ui_->comboBox_selection->currentIndex() == 0 &&
roi_.width &&
roi_.height)))
300 if(
ui_->comboBox_selection->currentIndex() == 1)
307 if(
ui_->comboBox_selection->currentIndex() == 1)
311 for(
unsigned int i=0; i<selectedKeypoints.size(); ++i)
313 selectedKeypoints.at(i).pt.x -=
roi_.x;
314 selectedKeypoints.at(i).pt.y -=
roi_.y;
321 selectedKeypoints.clear();
325 ui_->objectView->updateData(selectedKeypoints, QMultiMap<int,int>());
326 ui_->objectView->setMinimumSize(
roi_.width,
roi_.height);
327 ui_->objectView->update();
328 ui_->pushButton_next->setEnabled(
true);
332 UINFO(
"Please select items");
333 ui_->pushButton_next->setEnabled(
false);
335 ui_->label_instruction->setText(tr(
"Selection : %1 features").arg(selectedKeypoints.size()));
339 std::vector<cv::KeyPoint> keypoints =
ui_->objectView->keypoints();
340 if((
ui_->comboBox_selection->currentIndex() == 1 && keypoints.size()) ||
341 (
ui_->comboBox_selection->currentIndex() == 0 &&
roi_.width &&
roi_.height))
357 if(keypoints.size() != (
unsigned int)descriptors.rows)
359 UERROR(
"keypoints=%d != descriptors=%d", (
int)keypoints.size(), descriptors.rows);
393 if(image.channels() != 1 || image.depth() != CV_8U)
403 std::vector<cv::KeyPoint> keypoints;
407 ui_->cameraView->updateData(keypoints, QMultiMap<int,int>());
408 ui_->cameraView->update();
412 UWARN(
"Camera cannot get more images (maybe the end of stream is reached)...");
419 cv::Rect roi(0,0,0,0);
420 int x1=0,x2=0,h1=0,h2=0;
421 for(
unsigned int i=0; i<kpts.size(); ++i)
423 float radius = kpts.at(i).size / 2;
426 x1 = int(kpts.at(i).pt.x - radius);
427 x2 = int(kpts.at(i).pt.x + radius);
428 h1 = int(kpts.at(i).pt.y - radius);
429 h2 = int(kpts.at(i).pt.y + radius);
433 if(x1 >
int(kpts.at(i).pt.x - radius))
435 x1 = int(kpts.at(i).pt.x - radius);
437 else if(x2 <
int(kpts.at(i).pt.x + radius))
439 x2 = int(kpts.at(i).pt.x + radius);
441 if(h1 >
int(kpts.at(i).pt.y - radius))
443 h1 = int(kpts.at(i).pt.y - radius);
445 else if(h2 <
int(kpts.at(i).pt.y + radius))
447 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)
static QString currentDetectorType()
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)
static QString currentDescriptorType()
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)