Fixed a crash (Windows) after adding an object. This may be related to issue 1. The cause is that the first image acquired from the camera is blank, so no features are extracted and the code not handled this case, crashing during nearest neighbor search.

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@67 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2012-01-05 00:31:29 +00:00
parent ba1919d2c6
commit aafe4beac4
2 changed files with 34 additions and 15 deletions

View File

@ -353,24 +353,31 @@ void MainWindow::update(const cv::Mat & image)
delete detector; delete detector;
ui_->label_timeDetection->setText(QString::number(time.restart())); ui_->label_timeDetection->setText(QString::number(time.restart()));
// EXTRACT DESCRIPTORS
cv::Mat descriptors; cv::Mat descriptors;
cv::DescriptorExtractor * extractor = Settings::createDescriptorsExtractor(); if(keypoints.size())
extractor->compute(img, keypoints, descriptors);
delete extractor;
if((int)keypoints.size() != descriptors.rows)
{ {
printf("ERROR : kpt=%d != descriptors=%d\n", (int)keypoints.size(), descriptors.rows); // EXTRACT DESCRIPTORS
cv::DescriptorExtractor * extractor = Settings::createDescriptorsExtractor();
extractor->compute(img, keypoints, descriptors);
delete extractor;
if((int)keypoints.size() != descriptors.rows)
{
printf("ERROR : kpt=%d != descriptors=%d\n", (int)keypoints.size(), descriptors.rows);
}
if(imageGrayScale)
{
cvReleaseImage(&imageGrayScale);
}
ui_->label_timeExtraction->setText(QString::number(time.restart()));
} }
if(imageGrayScale) else
{ {
cvReleaseImage(&imageGrayScale); printf("WARNING: no features detected !?!\n");
ui_->label_timeExtraction->setText(QString::number(0));
} }
ui_->label_timeExtraction->setText(QString::number(time.restart()));
// COMPARE // COMPARE
int alpha = 20*255/100; if(!dataTree_.empty() && keypoints.size() && (Settings::getNearestNeighbor_nndrRatioUsed() || Settings::getNearestNeighbor_minDistanceUsed()))
if(!dataTree_.empty() && (Settings::getNearestNeighbor_nndrRatioUsed() || Settings::getNearestNeighbor_minDistanceUsed()))
{ {
// CREATE INDEX // CREATE INDEX
cv::Mat environment(descriptors.rows, descriptors.cols, CV_32F); cv::Mat environment(descriptors.rows, descriptors.cols, CV_32F);
@ -390,7 +397,6 @@ void MainWindow::update(const cv::Mat & image)
treeFlannIndex.knnSearch(dataTree_, results, dists, k, cv::flann::SearchParams(emax) ); // maximum number of leafs checked treeFlannIndex.knnSearch(dataTree_, results, dists, k, cv::flann::SearchParams(emax) ); // maximum number of leafs checked
ui_->label_timeMatching->setText(QString::number(time.restart())); ui_->label_timeMatching->setText(QString::number(time.restart()));
// PROCESS RESULTS // PROCESS RESULTS
if(this->isVisible()) if(this->isVisible())
{ {
@ -406,7 +412,6 @@ void MainWindow::update(const cv::Mat & image)
for(int i=0; i<dataTree_.rows; ++i) for(int i=0; i<dataTree_.rows; ++i)
{ {
QColor color((Qt::GlobalColor)(j % 12 + 7 )); QColor color((Qt::GlobalColor)(j % 12 + 7 ));
color.setAlpha(alpha);
bool matched = false; bool matched = false;
// Check if this descriptor matches with those of the objects // Check if this descriptor matches with those of the objects
if(Settings::getNearestNeighbor_nndrRatioUsed() && if(Settings::getNearestNeighbor_nndrRatioUsed() &&
@ -497,7 +502,7 @@ void MainWindow::update(const cv::Mat & image)
} }
else else
{ {
objects_.at(j)->setKptColor(indexes_1.at(k), QColor(0,0,0,alpha)); objects_.at(j)->setKptColor(indexes_1.at(k), QColor(0,0,0));
} }
} }
} }

View File

@ -20,6 +20,7 @@
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QGraphicsRectItem> #include <QtGui/QGraphicsRectItem>
#include <QtGui/QInputDialog> #include <QtGui/QInputDialog>
#include <QtGui/QPen>
#include <QtCore/QDir> #include <QtCore/QDir>
@ -201,6 +202,14 @@ void ObjWidget::setAlpha(int alpha)
color.setAlpha(alpha_); color.setAlpha(alpha_);
keypointItems_.at(i)->setColor(color); keypointItems_.at(i)->setColor(color);
} }
for(int i=0; i<rectItems_.size(); ++i)
{
QPen pen = rectItems_.at(i)->pen();
QColor color = pen.color();
color.setAlpha(alpha_);
pen.setColor(color);
rectItems_.at(i)->setPen(pen);
}
} }
if(!_graphicsViewMode->isChecked()) if(!_graphicsViewMode->isChecked())
{ {
@ -282,6 +291,11 @@ void ObjWidget::addRect(QGraphicsRectItem * rect)
graphicsView_->scene()->addItem(rect); graphicsView_->scene()->addItem(rect);
} }
rect->setZValue(2); rect->setZValue(2);
QPen pen = rect->pen();
QColor color = pen.color();
color.setAlpha(alpha_);
pen.setColor(color);
rect->setPen(pen);
rectItems_.append(rect); rectItems_.append(rect);
} }