Fixed slow BRISK

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@340 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2014-06-19 17:43:34 +00:00
parent 83e932eae3
commit 4347951c57
5 changed files with 66 additions and 48 deletions

View File

@ -27,6 +27,10 @@ AddObjectDialog::AddObjectDialog(Camera * camera, const cv::Mat & image, bool mi
ui_ = new Ui_addObjectDialog();
ui_->setupUi(this);
detector_ = Settings::createFeaturesDetector();
extractor_ = Settings::createDescriptorsExtractor();
Q_ASSERT(detector_ != 0 && extractor_ != 0);
connect(ui_->pushButton_cancel, SIGNAL(clicked()), this, SLOT(cancel()));
connect(ui_->pushButton_back, SIGNAL(clicked()), this, SLOT(back()));
connect(ui_->pushButton_next, SIGNAL(clicked()), this, SLOT(next()));
@ -50,6 +54,8 @@ AddObjectDialog::AddObjectDialog(Camera * camera, const cv::Mat & image, bool mi
AddObjectDialog::~AddObjectDialog()
{
delete detector_;
delete extractor_;
if(object_)
{
delete object_;
@ -272,9 +278,7 @@ void AddObjectDialog::setState(int state)
{
// Extract keypoints
selectedKeypoints.clear();
cv::FeatureDetector * detector = Settings::createFeaturesDetector();
detector->detect(imgRoi, selectedKeypoints);
delete detector;
detector_->detect(imgRoi, selectedKeypoints);
}
ui_->objectView->setData(selectedKeypoints, cv::Mat(), imgRoi, Settings::currentDetectorType(), "");
ui_->objectView->setMinimumSize(roi.width, roi.height);
@ -298,9 +302,7 @@ void AddObjectDialog::setState(int state)
if(keypoints.size())
{
// Extract descriptors
cv::DescriptorExtractor * extractor = Settings::createDescriptorsExtractor();
extractor->compute(ui_->objectView->cvImage(), keypoints, descriptors);
delete extractor;
extractor_->compute(ui_->objectView->cvImage(), keypoints, descriptors);
if(keypoints.size() != (unsigned int)descriptors.rows)
{
@ -336,10 +338,8 @@ void AddObjectDialog::update(const cv::Mat & image)
}
// Extract keypoints
cv::FeatureDetector * detector = Settings::createFeaturesDetector();
cv::vector<cv::KeyPoint> keypoints;
detector->detect(cvImage_, keypoints);
delete detector;
detector_->detect(cvImage_, keypoints);
ui_->cameraView->setData(keypoints, cv::Mat(), cvImage_, Settings::currentDetectorType(), "");
ui_->cameraView->update();

View File

@ -47,6 +47,8 @@ private:
Camera * camera_;
ObjWidget * object_;
cv::Mat cvImage_;
cv::FeatureDetector * detector_;
cv::DescriptorExtractor * extractor_;
enum State{kTakePicture, kSelectFeatures, kVerifySelection, kClosing};
int state_;

View File

@ -51,7 +51,9 @@ MainWindow::MainWindow(Camera * camera, const QString & settings, QWidget * pare
inliersCurve_(0),
lowestRefreshRate_(99),
objectsModified_(false),
tcpServer_(0)
tcpServer_(0),
detector_(0),
extractor_(0)
{
ui_ = new Ui_mainWindow();
ui_->setupUi(this);
@ -113,6 +115,10 @@ MainWindow::MainWindow(Camera * camera, const QString & settings, QWidget * pare
ui_->toolBox->getParameterWidget(Settings::kFeature2D_SURF_gpu())->setEnabled(false);
}
detector_ = Settings::createFeaturesDetector();
extractor_ = Settings::createDescriptorsExtractor();
Q_ASSERT(detector_ != 0 && extractor_ != 0);
connect((QDoubleSpinBox*)ui_->toolBox->getParameterWidget(Settings::kCamera_4imageRate()),
SIGNAL(editingFinished()),
camera_,
@ -202,6 +208,8 @@ MainWindow::~MainWindow()
{
disconnect(camera_, SIGNAL(imageReceived(const cv::Mat &)), this, SLOT(update(const cv::Mat &)));
camera_->stop();
delete detector_;
delete extractor_;
objectsDescriptors_.clear();
qDeleteAll(objects_.begin(), objects_.end());
objects_.clear();
@ -1302,9 +1310,6 @@ void MainWindow::update(const cv::Mat & image)
if(!image.empty())
{
QTime time;
time.start();
//Convert to grayscale
cv::Mat grayscaleImg;
if(image.channels() != 1 || image.depth() != CV_8U)
@ -1316,11 +1321,12 @@ void MainWindow::update(const cv::Mat & image)
grayscaleImg = image;
}
QTime time;
time.start();
// EXTRACT KEYPOINTS
cv::FeatureDetector * detector = Settings::createFeaturesDetector();
std::vector<cv::KeyPoint> keypoints;
detector->detect(grayscaleImg, keypoints);
delete detector;
detector_->detect(grayscaleImg, keypoints);
ui_->label_timeDetection->setNum(time.restart());
cv::Mat descriptors;
@ -1335,9 +1341,7 @@ void MainWindow::update(const cv::Mat & image)
}
// EXTRACT DESCRIPTORS
cv::DescriptorExtractor * extractor = Settings::createDescriptorsExtractor();
extractor->compute(grayscaleImg, keypoints, descriptors);
delete extractor;
extractor_->compute(grayscaleImg, keypoints, descriptors);
if((int)keypoints.size() != descriptors.rows)
{
printf("ERROR : kpt=%d != descriptors=%d\n", (int)keypoints.size(), descriptors.rows);
@ -1658,6 +1662,7 @@ void MainWindow::update(const cv::Mat & image)
}
}
}
ui_->label_timeHomographies->setNum(time.restart());
}
else
{
@ -1769,7 +1774,6 @@ void MainWindow::update(const cv::Mat & image)
ui_->label_nfeatures->setNum((int)keypoints.size());
ui_->imageView_source->update();
ui_->label_timeGui->setNum(time.restart());
}
ui_->label_detectorDescriptorType->setText(QString("%1/%2").arg(Settings::currentDetectorType()).arg(Settings::currentDescriptorType()));
@ -1836,6 +1840,16 @@ void MainWindow::notifyParametersChanged(const QStringList & paramChanged)
}
}
if(detectorDescriptorParamsChanged)
{
//Re-init detector and extractor
delete detector_;
delete extractor_;
detector_ = Settings::createFeaturesDetector();
extractor_ = Settings::createDescriptorsExtractor();
Q_ASSERT(detector_ != 0 && extractor_ != 0);
}
if(Settings::getGeneral_autoUpdateObjects())
{
if(detectorDescriptorParamsChanged)

View File

@ -105,6 +105,8 @@ private:
QMap<int, QByteArray> imagesMap_;
TcpServer * tcpServer_;
QMap<QString, QVariant> lastObjectsUpdateParameters_; // ParametersMap
cv::FeatureDetector * detector_;
cv::DescriptorExtractor * extractor_;
};
#endif /* MainWindow_H_ */

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>826</width>
<height>488</height>
<height>506</height>
</rect>
</property>
<property name="windowTitle">
@ -200,7 +200,7 @@
<x>0</x>
<y>0</y>
<width>826</width>
<height>22</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -255,7 +255,7 @@
<property name="minimumSize">
<size>
<width>360</width>
<height>100</height>
<height>156</height>
</size>
</property>
<property name="floating">
@ -285,8 +285,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>348</width>
<height>76</height>
<width>360</width>
<height>73</height>
</rect>
</property>
<attribute name="label">
@ -343,8 +343,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>199</width>
<height>361</height>
<width>198</width>
<height>376</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_objects">
@ -448,6 +448,20 @@
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="3" column="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>ms</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="label_10">
<property name="text">
<string>ms</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
@ -469,20 +483,6 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>ms</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="label_10">
<property name="text">
<string>ms</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLabel" name="label_12">
<property name="text">
@ -525,13 +525,6 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_timeGui">
<property name="text">
<string>000</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@ -658,6 +651,13 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_timeHomographies">
<property name="text">
<string>000</string>
</property>
</widget>
</item>
</layout>
</item>
<item>