Added code example for descriptors extraction
git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@20 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
parent
d71dcd00ea
commit
a761af58da
@ -58,7 +58,7 @@ ENDIF(APPLE AND BUILD_AS_BUNDLE)
|
||||
|
||||
####### SOURCES (Projects) #######
|
||||
ADD_SUBDIRECTORY( src )
|
||||
|
||||
ADD_SUBDIRECTORY( example )
|
||||
|
||||
|
||||
|
||||
|
||||
43
example/CMakeLists.txt
Normal file
43
example/CMakeLists.txt
Normal file
@ -0,0 +1,43 @@
|
||||
### Qt Gui stuff ###
|
||||
SET(headers_ui
|
||||
../src/ObjWidget.h
|
||||
../src/Camera.h
|
||||
)
|
||||
#This will generate moc_* for Qt
|
||||
QT4_WRAP_CPP(moc_srcs ${headers_ui})
|
||||
### Qt Gui stuff end###
|
||||
|
||||
SET(SRC_FILES
|
||||
main.cpp
|
||||
../src/ObjWidget.cpp
|
||||
../src/KeypointItem.cpp
|
||||
../src/qtipl.cpp
|
||||
../src/Settings.cpp
|
||||
../src/Camera.cpp
|
||||
${moc_srcs}
|
||||
)
|
||||
|
||||
SET(INCLUDE_DIRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${OpenCV_INCLUDE_DIRS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src
|
||||
)
|
||||
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
|
||||
SET(LIBRARIES
|
||||
${OpenCV_LIBS}
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
||||
# Make sure the compiler can find include files from our library.
|
||||
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
|
||||
|
||||
# Add binary called "example" that is built from the source file "main.cpp".
|
||||
# The extension is automatically found.
|
||||
ADD_EXECUTABLE(example ${SRC_FILES})
|
||||
TARGET_LINK_LIBRARIES(example ${LIBRARIES})
|
||||
|
||||
SET_TARGET_PROPERTIES( example
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-example)
|
||||
|
||||
236
example/main.cpp
Normal file
236
example/main.cpp
Normal file
@ -0,0 +1,236 @@
|
||||
/*
|
||||
* main.cpp
|
||||
*
|
||||
* Created on: 2011-11-15
|
||||
* Author: matlab
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Qt stuff
|
||||
#include <QtCore/QTime>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QGraphicsRectItem>
|
||||
#include <QtGui/QPen>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
// OpenCV stuff
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include <opencv2/calib3d/calib3d.hpp> // for homography
|
||||
|
||||
// From this project (see src folder)
|
||||
#include "ObjWidget.h"
|
||||
|
||||
void showUsage()
|
||||
{
|
||||
printf("\n");
|
||||
printf("Usage :\n");
|
||||
printf(" ./example object.png scene.png\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if(argc<3)
|
||||
{
|
||||
showUsage();
|
||||
}
|
||||
QTime time;
|
||||
time.start();
|
||||
|
||||
// GUI stuff
|
||||
QApplication app(argc, argv);
|
||||
ObjWidget objWidget;
|
||||
ObjWidget sceneWidget;
|
||||
|
||||
//Load as grayscale
|
||||
IplImage * objectImg = cvLoadImage(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
|
||||
IplImage * sceneImg = cvLoadImage(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
|
||||
|
||||
if(objectImg && sceneImg)
|
||||
{
|
||||
std::vector<cv::KeyPoint> objectKeypoints;
|
||||
std::vector<cv::KeyPoint> sceneKeypoints;
|
||||
cv::Mat objectDescriptors;
|
||||
cv::Mat sceneDescriptors;
|
||||
|
||||
////////////////////////////
|
||||
// EXTRACT KEYPOINTS
|
||||
////////////////////////////
|
||||
// The detector can be any of (see OpenCV features2d.hpp):
|
||||
// cv::FeatureDetector * detector = new cv::FastFeatureDetector();
|
||||
// cv::FeatureDetector * detector = new cv::SiftFeatureDetector();
|
||||
// cv::FeatureDetector * detector = new cv::SurfFeatureDetector();
|
||||
// cv::FeatureDetector * detector = new cv::StarFeatureDetector();
|
||||
cv::FeatureDetector * detector = new cv::SurfFeatureDetector();
|
||||
detector->detect(objectImg, objectKeypoints);
|
||||
printf("Object: %d keypoints detected in %d ms\n", (int)objectKeypoints.size(), time.restart());
|
||||
detector->detect(sceneImg, sceneKeypoints);
|
||||
printf("Scene: %d keypoints detected in %d ms\n", (int)sceneKeypoints.size(), time.restart());
|
||||
|
||||
////////////////////////////
|
||||
// EXTRACT DESCRIPTORS
|
||||
////////////////////////////
|
||||
// The extractor can be any of (see OpenCV features2d.hpp):
|
||||
// cv::DescriptorExtractor * detector = new cv::BriefDescriptorExtractor();
|
||||
// cv::DescriptorExtractor * detector = new cv::SiftFeatureDetector();
|
||||
// cv::DescriptorExtractor * detector = new cv::SurfFeatureDetector();
|
||||
cv::DescriptorExtractor * extractor = new cv::SurfDescriptorExtractor();
|
||||
extractor->compute(objectImg, objectKeypoints, objectDescriptors);
|
||||
printf("Object: %d descriptors extracted in %d ms\n", objectDescriptors.rows, time.restart());
|
||||
extractor->compute(sceneImg, sceneKeypoints, sceneDescriptors);
|
||||
printf("Scene: %d descriptors extracted in %d ms\n", sceneDescriptors.rows, time.restart());
|
||||
|
||||
////////////////////////////
|
||||
// NEAREST NEIGHBOR MATCHING USING FLANN LIBRARY (included in OpenCV)
|
||||
////////////////////////////
|
||||
// Format descriptors for Flann
|
||||
cv::Mat objectData;
|
||||
cv::Mat sceneData;
|
||||
if(objectDescriptors.type()!=CV_32F) {
|
||||
objectDescriptors.convertTo(objectData, CV_32F); // make sure it's CV_32F
|
||||
}
|
||||
else {
|
||||
objectData = objectDescriptors;
|
||||
}
|
||||
if(sceneDescriptors.type()!=CV_32F) {
|
||||
sceneDescriptors.convertTo(sceneData, CV_32F); // make sure it's CV_32F
|
||||
}
|
||||
else {
|
||||
sceneData = sceneDescriptors;
|
||||
}
|
||||
|
||||
// Create Flann index
|
||||
cv::flann::Index treeFlannIndex(sceneData, cv::flann::KDTreeIndexParams());
|
||||
printf("Time creating FLANN index = %d ms\n", time.restart());
|
||||
|
||||
// search (nearest neighbor)
|
||||
int k=2; // find the 2 nearest neighbors
|
||||
cv::Mat results(objectData.rows, k, CV_32SC1); // Results index
|
||||
cv::Mat dists(objectData.rows, k, CV_32FC1); // Distance results are CV_32FC1
|
||||
treeFlannIndex.knnSearch(objectData, results, dists, k, cv::flann::SearchParams() ); // maximum number of leafs checked
|
||||
printf("Time nearest neighbor search = %d ms\n", time.restart());
|
||||
|
||||
////////////////////////////
|
||||
// PROCESS NEAREST NEIGHBOR RESULTS
|
||||
////////////////////////////
|
||||
// Set gui data
|
||||
objWidget.setData(objectKeypoints, objectDescriptors, objectImg);
|
||||
sceneWidget.setData(sceneKeypoints, sceneDescriptors, sceneImg);
|
||||
|
||||
// Find correspondences by NNDR (Nearest Neighbor Distance Ratio)
|
||||
float nndrRatio = 0.6;
|
||||
std::vector<cv::Point2f> mpts_1, mpts_2; // Used for homography
|
||||
std::vector<int> indexes_1, indexes_2; // Used for homography
|
||||
std::vector<uchar> outlier_mask; // Used for homography
|
||||
for(unsigned int i=0; i<objectData.rows; ++i)
|
||||
{
|
||||
// Check if this descriptor matches with those of the objects
|
||||
// Apply NNDR
|
||||
if(dists.at<float>(i,0) <= nndrRatio * dists.at<float>(i,1))
|
||||
{
|
||||
mpts_1.push_back(objectKeypoints.at(i).pt);
|
||||
indexes_1.push_back(i);
|
||||
|
||||
mpts_2.push_back(sceneKeypoints.at(results.at<int>(i,0)).pt);
|
||||
indexes_2.push_back(results.at<int>(i,0));
|
||||
}
|
||||
}
|
||||
|
||||
// FIND HOMOGRAPHY
|
||||
int minInliers = 8;
|
||||
if(mpts_1.size() >= minInliers)
|
||||
{
|
||||
cv::Mat H = findHomography(mpts_1,
|
||||
mpts_2,
|
||||
cv::RANSAC,
|
||||
1.0,
|
||||
outlier_mask);
|
||||
int inliers=0, outliers=0;
|
||||
for(int k=0; k<mpts_1.size();++k)
|
||||
{
|
||||
if(outlier_mask.at(k))
|
||||
{
|
||||
++inliers;
|
||||
}
|
||||
else
|
||||
{
|
||||
++outliers;
|
||||
}
|
||||
}
|
||||
QTransform hTransform(
|
||||
H.at<double>(0,0), H.at<double>(1,0), H.at<double>(2,0),
|
||||
H.at<double>(0,1), H.at<double>(1,1), H.at<double>(2,1),
|
||||
H.at<double>(0,2), H.at<double>(1,2), H.at<double>(2,2));
|
||||
|
||||
// GUI : Change color and add homography rectangle
|
||||
QColor color(Qt::red);
|
||||
int alpha = 130;
|
||||
color.setAlpha(alpha);
|
||||
for(int k=0; k<mpts_1.size();++k)
|
||||
{
|
||||
if(outlier_mask.at(k))
|
||||
{
|
||||
objWidget.setKptColor(indexes_1.at(k), color);
|
||||
sceneWidget.setKptColor(indexes_2.at(k), color);
|
||||
}
|
||||
else
|
||||
{
|
||||
objWidget.setKptColor(indexes_1.at(k), QColor(0,0,0,alpha));
|
||||
}
|
||||
}
|
||||
QPen rectPen(color);
|
||||
rectPen.setWidth(4);
|
||||
QGraphicsRectItem * rectItem = new QGraphicsRectItem(objWidget.image().rect());
|
||||
rectItem->setPen(rectPen);
|
||||
rectItem->setTransform(hTransform);
|
||||
sceneWidget.addRect(rectItem);
|
||||
printf("Inliers=%d Outliers=%d\n", inliers, outliers);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Not enough matches (%d) for homography...\n", (int)mpts_1.size());
|
||||
}
|
||||
|
||||
// Wait for gui
|
||||
objWidget.setGraphicsViewMode(false);
|
||||
objWidget.setWindowTitle("Object");
|
||||
objWidget.show();
|
||||
sceneWidget.setGraphicsViewMode(false);
|
||||
sceneWidget.setWindowTitle("Scene");
|
||||
sceneWidget.show();
|
||||
int r = app.exec();
|
||||
|
||||
////////////////////////////
|
||||
//Cleanup
|
||||
////////////////////////////
|
||||
delete detector;
|
||||
delete extractor;
|
||||
|
||||
if(objectImg) {
|
||||
cvReleaseImage(&objectImg);
|
||||
}
|
||||
if(sceneImg) {
|
||||
cvReleaseImage(&sceneImg);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(objectImg) {
|
||||
cvReleaseImage(&objectImg);
|
||||
}
|
||||
if(sceneImg) {
|
||||
cvReleaseImage(&sceneImg);
|
||||
}
|
||||
|
||||
printf("Images are not valid!\n");
|
||||
showUsage();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
#include "AddObjectDialog.h"
|
||||
#include "ui_addObjectDialog.h"
|
||||
#include "Object.h"
|
||||
#include "ObjWidget.h"
|
||||
#include "KeypointItem.h"
|
||||
#include "Camera.h"
|
||||
#include "qtipl.h"
|
||||
@ -15,7 +15,7 @@
|
||||
#include <opencv2/imgproc/imgproc_c.h>
|
||||
#include <opencv2/highgui/highgui_c.h>
|
||||
|
||||
AddObjectDialog::AddObjectDialog(QList<Object*> * objects, QWidget * parent, Qt::WindowFlags f) :
|
||||
AddObjectDialog::AddObjectDialog(QList<ObjWidget*> * objects, QWidget * parent, Qt::WindowFlags f) :
|
||||
QDialog(parent, f),
|
||||
camera_(0),
|
||||
objects_(objects),
|
||||
@ -191,7 +191,7 @@ void AddObjectDialog::setState(int state)
|
||||
selectedKeypoints.at(i).pt.y -= roi.y;
|
||||
}
|
||||
}
|
||||
objects_->append(new Object(0, selectedKeypoints, descriptors, cvImage_, Settings::currentDetectorType(), Settings::currentDescriptorType()));
|
||||
objects_->append(new ObjWidget(0, selectedKeypoints, descriptors, cvImage_, Settings::currentDetectorType(), Settings::currentDescriptorType()));
|
||||
cvResetImageROI(cvImage_);
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include <opencv2/core/core_c.h>
|
||||
|
||||
class Ui_addObjectDialog;
|
||||
class Object;
|
||||
class ObjWidget;
|
||||
class Camera;
|
||||
class KeypointItem;
|
||||
|
||||
@ -16,7 +16,7 @@ class AddObjectDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AddObjectDialog(QList<Object*> * objects, QWidget * parent = 0, Qt::WindowFlags f = 0);
|
||||
AddObjectDialog(QList<ObjWidget*> * objects, QWidget * parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~AddObjectDialog();
|
||||
|
||||
private slots:
|
||||
@ -37,7 +37,7 @@ private:
|
||||
Ui_addObjectDialog * ui_;
|
||||
Camera * camera_;
|
||||
QTimer cameraTimer_;
|
||||
QList<Object*> * objects_;
|
||||
QList<ObjWidget*> * objects_;
|
||||
IplImage * cvImage_;
|
||||
|
||||
enum State{kTakePicture, kSelectFeatures, kVerifySelection, kClosing};
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
SET(headers_ui
|
||||
./MainWindow.h
|
||||
./AddObjectDialog.h
|
||||
./Object.h
|
||||
./ObjWidget.h
|
||||
./Camera.h
|
||||
./ParametersToolBox.h
|
||||
)
|
||||
@ -38,7 +38,7 @@ SET(SRC_FILES
|
||||
./Camera.cpp
|
||||
./ParametersToolBox.cpp
|
||||
./Settings.cpp
|
||||
./Object.cpp
|
||||
./ObjWidget.cpp
|
||||
${moc_srcs}
|
||||
${moc_uis}
|
||||
#${srcs_qrc}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include "ui_mainWindow.h"
|
||||
#include "qtipl.h"
|
||||
#include "KeypointItem.h"
|
||||
#include "Object.h"
|
||||
#include "ObjWidget.h"
|
||||
#include "Camera.h"
|
||||
#include "Settings.h"
|
||||
#include "ParametersToolBox.h"
|
||||
@ -87,7 +87,7 @@ void MainWindow::loadObjects()
|
||||
QDataStream in(&file);
|
||||
while(!in.atEnd())
|
||||
{
|
||||
Object * obj = new Object();
|
||||
ObjWidget * obj = new ObjWidget();
|
||||
obj->load(in);
|
||||
bool alreadyLoaded = false;
|
||||
for(int i=0; i<objects_.size(); ++i)
|
||||
@ -132,7 +132,7 @@ void MainWindow::saveObjects()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::removeObject(Object * object)
|
||||
void MainWindow::removeObject(ObjWidget * object)
|
||||
{
|
||||
if(object)
|
||||
{
|
||||
@ -152,12 +152,12 @@ void MainWindow::addObject()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showObject(Object * obj)
|
||||
void MainWindow::showObject(ObjWidget * obj)
|
||||
{
|
||||
if(obj)
|
||||
{
|
||||
obj->setGraphicsViewMode(false);
|
||||
QList<Object*> objs = ui_->objects_area->findChildren<Object*>();
|
||||
QList<ObjWidget*> objs = ui_->objects_area->findChildren<ObjWidget*>();
|
||||
QVBoxLayout * vLayout = new QVBoxLayout();
|
||||
int id = Settings::getGeneral_nextObjID().toInt();
|
||||
if(obj->id() == 0)
|
||||
@ -183,7 +183,7 @@ void MainWindow::showObject(Object * obj)
|
||||
vLayout->addLayout(hLayout);
|
||||
vLayout->addWidget(obj);
|
||||
objects_.last()->setDeletable(true);
|
||||
connect(obj, SIGNAL(removalTriggered(Object*)), this, SLOT(removeObject(Object*)));
|
||||
connect(obj, SIGNAL(removalTriggered(ObjWidget*)), this, SLOT(removeObject(ObjWidget*)));
|
||||
connect(obj, SIGNAL(destroyed(QObject *)), title, SLOT(deleteLater()));
|
||||
connect(obj, SIGNAL(destroyed(QObject *)), detectedLabel, SLOT(deleteLater()));
|
||||
connect(obj, SIGNAL(destroyed(QObject *)), detectorDescriptorType, SLOT(deleteLater()));
|
||||
@ -293,6 +293,7 @@ void MainWindow::update()
|
||||
if(cvImage)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
|
||||
//Convert to grayscale
|
||||
IplImage * imageGrayScale = 0;
|
||||
@ -312,13 +313,11 @@ void MainWindow::update()
|
||||
}
|
||||
|
||||
// EXTRACT KEYPOINTS
|
||||
time.start();
|
||||
cv::FeatureDetector * detector = Settings::createFeaturesDetector();
|
||||
std::vector<cv::KeyPoint> keypoints;
|
||||
detector->detect(img, keypoints);
|
||||
delete detector;
|
||||
ui_->label_timeDetection->setText(QString::number(time.elapsed()));
|
||||
time.start();
|
||||
ui_->label_timeDetection->setText(QString::number(time.restart()));
|
||||
|
||||
// EXTRACT DESCRIPTORS
|
||||
cv::Mat descriptors;
|
||||
@ -333,8 +332,7 @@ void MainWindow::update()
|
||||
{
|
||||
cvReleaseImage(&imageGrayScale);
|
||||
}
|
||||
ui_->label_timeExtraction->setText(QString::number(time.elapsed()));
|
||||
time.start();
|
||||
ui_->label_timeExtraction->setText(QString::number(time.restart()));
|
||||
|
||||
// COMPARE
|
||||
int alpha = 20*255/100;
|
||||
@ -344,8 +342,7 @@ void MainWindow::update()
|
||||
cv::Mat environment(descriptors.rows, descriptors.cols, CV_32F);
|
||||
descriptors.convertTo(environment, CV_32F);
|
||||
cv::flann::Index treeFlannIndex(environment, cv::flann::KDTreeIndexParams());
|
||||
ui_->label_timeIndexing->setText(QString::number(time.elapsed()));
|
||||
time.start();
|
||||
ui_->label_timeIndexing->setText(QString::number(time.restart()));
|
||||
|
||||
// DO NEAREST NEIGHBOR
|
||||
int k = 2;
|
||||
@ -353,8 +350,7 @@ void MainWindow::update()
|
||||
cv::Mat results(dataTree_.rows, k, CV_32SC1); // results index
|
||||
cv::Mat dists(dataTree_.rows, k, CV_32FC1); // Distance results are CV_32FC1
|
||||
treeFlannIndex.knnSearch(dataTree_, results, dists, k, cv::flann::SearchParams(emax) ); // maximum number of leafs checked
|
||||
ui_->label_timeMatching->setText(QString::number(time.elapsed()));
|
||||
time.start();
|
||||
ui_->label_timeMatching->setText(QString::number(time.restart()));
|
||||
|
||||
|
||||
// PROCESS RESULTS
|
||||
@ -367,7 +363,7 @@ void MainWindow::update()
|
||||
{
|
||||
// Check if this descriptor matches with those of the objects
|
||||
// Apply NNDR
|
||||
if(dists.at<float>(i,0) <= Settings::getNN_nndrRatio().toFloat() * dists.at<float>(i,1))
|
||||
if(dists.at<float>(i,0) <= Settings::getNearestNeighbor_nndrRatio().toFloat() * dists.at<float>(i,1))
|
||||
{
|
||||
if(j>0)
|
||||
{
|
||||
@ -468,13 +464,11 @@ void MainWindow::update()
|
||||
|
||||
ui_->label_nfeatures->setText(QString::number(keypoints.size()));
|
||||
ui_->imageView_source->update();
|
||||
ui_->label_timeGui->setText(QString::number(time.elapsed()));
|
||||
ui_->label_timeGui->setText(QString::number(time.restart()));
|
||||
|
||||
cvReleaseImage(&cvImage);
|
||||
}
|
||||
}
|
||||
ui_->label_detectorDescriptorType->setText(QString("%1/%2").arg(Settings::currentDetectorType()).arg(Settings::currentDescriptorType()));
|
||||
ui_->label_timeRefreshRate->setText(QString("(%1 Hz - %2 Hz)").arg(QString::number(1000/cameraTimer_.interval())).arg(QString::number(int(1000.0f/(float)(updateRate_.elapsed()) + 1))));
|
||||
//printf("GUI refresh rate %f Hz\n", 1000.0f/(float)(updateRate_.elapsed()));
|
||||
updateRate_.start();
|
||||
ui_->label_timeRefreshRate->setText(QString("(%1 Hz - %2 Hz)").arg(QString::number(1000/cameraTimer_.interval())).arg(QString::number(int(1000.0f/(float)(updateRate_.restart()) + 1))));
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#include <opencv2/imgproc/imgproc_c.h>
|
||||
|
||||
class Ui_mainWindow;
|
||||
class Object;
|
||||
class ObjWidget;
|
||||
class Camera;
|
||||
class ParametersToolBox;
|
||||
class QLabel;
|
||||
@ -37,15 +37,15 @@ private slots:
|
||||
void saveObjects();
|
||||
void update();
|
||||
void updateData();
|
||||
void removeObject(Object * object);
|
||||
void removeObject(ObjWidget * object);
|
||||
|
||||
private:
|
||||
void showObject(Object * obj);
|
||||
void showObject(ObjWidget * obj);
|
||||
|
||||
private:
|
||||
Ui_mainWindow * ui_;
|
||||
Camera * camera_;
|
||||
QList<Object*> objects_;
|
||||
QList<ObjWidget*> objects_;
|
||||
QTimer cameraTimer_;
|
||||
cv::Mat dataTree_;
|
||||
QList<int> dataRange_;
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
* Author: matlab
|
||||
*/
|
||||
|
||||
#include "Object.h"
|
||||
#include "ObjWidget.h"
|
||||
#include "KeypointItem.h"
|
||||
#include "qtipl.h"
|
||||
#include "Settings.h"
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
Object::Object(QWidget * parent) :
|
||||
ObjWidget::ObjWidget(QWidget * parent) :
|
||||
QWidget(parent),
|
||||
iplImage_(0),
|
||||
graphicsView_(0),
|
||||
@ -46,7 +46,7 @@ Object::Object(QWidget * parent) :
|
||||
{
|
||||
setupUi();
|
||||
}
|
||||
Object::Object(int id,
|
||||
ObjWidget::ObjWidget(int id,
|
||||
const std::vector<cv::KeyPoint> & keypoints,
|
||||
const cv::Mat & descriptors,
|
||||
const IplImage * iplImage,
|
||||
@ -64,7 +64,7 @@ Object::Object(int id,
|
||||
setupUi();
|
||||
this->setData(keypoints, descriptors, iplImage);
|
||||
}
|
||||
Object::~Object()
|
||||
ObjWidget::~ObjWidget()
|
||||
{
|
||||
if(iplImage_)
|
||||
{
|
||||
@ -72,14 +72,14 @@ Object::~Object()
|
||||
}
|
||||
}
|
||||
|
||||
void Object::setupUi()
|
||||
void ObjWidget::setupUi()
|
||||
{
|
||||
graphicsView_ = new QGraphicsView(this);
|
||||
graphicsView_->setVisible(true);
|
||||
graphicsView_->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
graphicsView_->setScene(new QGraphicsScene(graphicsView_));
|
||||
|
||||
this->setLayout(new QVBoxLayout(graphicsView_));
|
||||
this->setLayout(new QVBoxLayout(this));
|
||||
this->layout()->addWidget(graphicsView_);
|
||||
this->layout()->setContentsMargins(0,0,0,0);
|
||||
|
||||
@ -110,7 +110,7 @@ void Object::setupUi()
|
||||
connect(graphicsView_->scene(), SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
|
||||
}
|
||||
|
||||
void Object::setId(int id)
|
||||
void ObjWidget::setId(int id)
|
||||
{
|
||||
id_=id;
|
||||
if(id_)
|
||||
@ -119,7 +119,7 @@ void Object::setId(int id)
|
||||
}
|
||||
}
|
||||
|
||||
void Object::setGraphicsViewMode(bool on)
|
||||
void ObjWidget::setGraphicsViewMode(bool on)
|
||||
{
|
||||
graphicsViewMode_ = on;
|
||||
graphicsView_->setVisible(on);
|
||||
@ -143,7 +143,7 @@ void Object::setGraphicsViewMode(bool on)
|
||||
this->update();
|
||||
}
|
||||
|
||||
void Object::setData(const std::vector<cv::KeyPoint> & keypoints, const cv::Mat & descriptors, const IplImage * image)
|
||||
void ObjWidget::setData(const std::vector<cv::KeyPoint> & keypoints, const cv::Mat & descriptors, const IplImage * image)
|
||||
{
|
||||
keypoints_ = keypoints;
|
||||
descriptors_ = descriptors;
|
||||
@ -175,7 +175,7 @@ void Object::setData(const std::vector<cv::KeyPoint> & keypoints, const cv::Mat
|
||||
}
|
||||
}
|
||||
|
||||
void Object::resetKptsColor()
|
||||
void ObjWidget::resetKptsColor()
|
||||
{
|
||||
for(int i=0; i<kptColors_.size(); ++i)
|
||||
{
|
||||
@ -188,7 +188,7 @@ void Object::resetKptsColor()
|
||||
rectItems_.clear();
|
||||
}
|
||||
|
||||
void Object::setKptColor(unsigned int index, const QColor & color)
|
||||
void ObjWidget::setKptColor(unsigned int index, const QColor & color)
|
||||
{
|
||||
if(index < kptColors_.size())
|
||||
{
|
||||
@ -204,38 +204,38 @@ void Object::setKptColor(unsigned int index, const QColor & color)
|
||||
}
|
||||
}
|
||||
|
||||
void Object::addRect(QGraphicsRectItem * rect)
|
||||
void ObjWidget::addRect(QGraphicsRectItem * rect)
|
||||
{
|
||||
graphicsView_->scene()->addItem(rect);
|
||||
rectItems_.append(rect);
|
||||
}
|
||||
|
||||
QList<QGraphicsItem*> Object::selectedItems() const
|
||||
QList<QGraphicsItem*> ObjWidget::selectedItems() const
|
||||
{
|
||||
return graphicsView_->scene()->selectedItems();
|
||||
}
|
||||
|
||||
bool Object::isImageShown() const
|
||||
bool ObjWidget::isImageShown() const
|
||||
{
|
||||
return _showImage->isChecked();
|
||||
}
|
||||
|
||||
bool Object::isFeaturesShown() const
|
||||
bool ObjWidget::isFeaturesShown() const
|
||||
{
|
||||
return _showFeatures->isChecked();
|
||||
}
|
||||
|
||||
bool Object::isMirrorView() const
|
||||
bool ObjWidget::isMirrorView() const
|
||||
{
|
||||
return _mirrorView->isChecked();
|
||||
}
|
||||
|
||||
void Object::setDeletable(bool deletable)
|
||||
void ObjWidget::setDeletable(bool deletable)
|
||||
{
|
||||
_delete->setEnabled(deletable);
|
||||
}
|
||||
|
||||
void Object::save(QDataStream & streamPtr) const
|
||||
void ObjWidget::save(QDataStream & streamPtr) const
|
||||
{
|
||||
streamPtr << id_ << detectorType_ << descriptorType_;
|
||||
streamPtr << (int)keypoints_.size();
|
||||
@ -259,7 +259,7 @@ void Object::save(QDataStream & streamPtr) const
|
||||
streamPtr << image_;
|
||||
}
|
||||
|
||||
void Object::load(QDataStream & streamPtr)
|
||||
void ObjWidget::load(QDataStream & streamPtr)
|
||||
{
|
||||
std::vector<cv::KeyPoint> kpts;
|
||||
cv::Mat descriptors;
|
||||
@ -291,7 +291,7 @@ void Object::load(QDataStream & streamPtr)
|
||||
this->setMinimumSize(image_.size());
|
||||
}
|
||||
|
||||
void Object::paintEvent(QPaintEvent *event)
|
||||
void ObjWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
if(graphicsViewMode_)
|
||||
{
|
||||
@ -367,16 +367,16 @@ void Object::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void Object::resizeEvent(QResizeEvent* event)
|
||||
void ObjWidget::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
if(graphicsViewMode_)
|
||||
{
|
||||
graphicsView_->fitInView(graphicsView_->sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
void Object::contextMenuEvent(QContextMenuEvent * event)
|
||||
void ObjWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||
{
|
||||
QAction * action = _menu->exec(event->globalPos());
|
||||
if(action == _saveImage)
|
||||
@ -431,7 +431,7 @@ void Object::contextMenuEvent(QContextMenuEvent * event)
|
||||
QWidget::contextMenuEvent(event);
|
||||
}
|
||||
|
||||
QPixmap Object::getSceneAsPixmap()
|
||||
QPixmap ObjWidget::getSceneAsPixmap()
|
||||
{
|
||||
if(graphicsViewMode_)
|
||||
{
|
||||
@ -446,7 +446,7 @@ QPixmap Object::getSceneAsPixmap()
|
||||
}
|
||||
}
|
||||
|
||||
void Object::updateItemsShown()
|
||||
void ObjWidget::updateItemsShown()
|
||||
{
|
||||
QList<QGraphicsItem*> items = graphicsView_->scene()->items();
|
||||
for(int i=0; i<items.size(); ++i)
|
||||
@ -462,7 +462,7 @@ void Object::updateItemsShown()
|
||||
}
|
||||
}
|
||||
|
||||
void Object::drawKeypoints(QPainter * painter)
|
||||
void ObjWidget::drawKeypoints(QPainter * painter)
|
||||
{
|
||||
QList<KeypointItem *> items;
|
||||
KeypointItem * item = 0;
|
||||
@ -499,13 +499,13 @@ void Object::drawKeypoints(QPainter * painter)
|
||||
}
|
||||
}
|
||||
|
||||
QColor Object::defaultColor() const
|
||||
QColor ObjWidget::defaultColor() const
|
||||
{
|
||||
int alpha = 20*255/100;
|
||||
return QColor(255, 255, 0, alpha);
|
||||
}
|
||||
|
||||
std::vector<cv::KeyPoint> Object::selectedKeypoints() const
|
||||
std::vector<cv::KeyPoint> ObjWidget::selectedKeypoints() const
|
||||
{
|
||||
std::vector<cv::KeyPoint> selected;
|
||||
if(graphicsViewMode_)
|
||||
@ -522,20 +522,23 @@ std::vector<cv::KeyPoint> Object::selectedKeypoints() const
|
||||
return selected;
|
||||
}
|
||||
|
||||
void Object::setupGraphicsView()
|
||||
void ObjWidget::setupGraphicsView()
|
||||
{
|
||||
graphicsView_->scene()->clear();
|
||||
graphicsView_->scene()->setSceneRect(image_.rect());
|
||||
QList<KeypointItem*> items;
|
||||
if(image_.width() > 0 && image_.height() > 0)
|
||||
if(!image_.isNull())
|
||||
{
|
||||
QRectF sceneRect = graphicsView_->sceneRect();
|
||||
graphicsView_->scene()->setSceneRect(image_.rect());
|
||||
QList<KeypointItem*> items;
|
||||
if(image_.width() > 0 && image_.height() > 0)
|
||||
{
|
||||
QRectF sceneRect = graphicsView_->sceneRect();
|
||||
|
||||
QGraphicsPixmapItem * pixmapItem = graphicsView_->scene()->addPixmap(image_);
|
||||
pixmapItem->setVisible(this->isImageShown());
|
||||
this->drawKeypoints();
|
||||
QGraphicsPixmapItem * pixmapItem = graphicsView_->scene()->addPixmap(image_);
|
||||
pixmapItem->setVisible(this->isImageShown());
|
||||
this->drawKeypoints();
|
||||
|
||||
graphicsView_->fitInView(sceneRect, Qt::KeepAspectRatio);
|
||||
graphicsView_->fitInView(sceneRect, Qt::KeepAspectRatio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/*
|
||||
* VisualObject.h
|
||||
* ObjWidget.h
|
||||
*
|
||||
* Created on: 2011-10-21
|
||||
* Author: matlab
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_H_
|
||||
#define OBJECT_H_
|
||||
#ifndef OBJWIDGET_H_
|
||||
#define OBJWIDGET_H_
|
||||
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include <QtGui/QWidget>
|
||||
@ -20,20 +20,20 @@ class QGraphicsScene;
|
||||
class QGraphicsRectItem;
|
||||
class QGraphicsItem;
|
||||
|
||||
class Object : public QWidget
|
||||
class ObjWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Object(QWidget * parent = 0);
|
||||
Object(int id,
|
||||
ObjWidget(QWidget * parent = 0);
|
||||
ObjWidget(int id,
|
||||
const std::vector<cv::KeyPoint> & keypoints,
|
||||
const cv::Mat & descriptors,
|
||||
const IplImage * image,
|
||||
const QString & detectorType = "NA",
|
||||
const QString & descriptorType = "NA",
|
||||
QWidget * parent = 0);
|
||||
virtual ~Object();
|
||||
virtual ~ObjWidget();
|
||||
|
||||
void setId(int id);
|
||||
void setData(const std::vector<cv::KeyPoint> & keypoints,
|
||||
@ -71,7 +71,7 @@ protected:
|
||||
virtual void resizeEvent(QResizeEvent* event);
|
||||
|
||||
signals:
|
||||
void removalTriggered(Object *);
|
||||
void removalTriggered(ObjWidget *);
|
||||
void selectionChanged();
|
||||
|
||||
private:
|
||||
@ -106,4 +106,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* OBJECT_H_ */
|
||||
#endif /* OBJWIDGET_H_ */
|
||||
@ -106,7 +106,7 @@ class Settings
|
||||
PARAMETER(Surf, upright, bool, false);
|
||||
PARAMETER(Surf, extended, bool, false);
|
||||
|
||||
PARAMETER(NN, nndrRatio, float, 0.8f); // NNDR RATIO
|
||||
PARAMETER(NearestNeighbor, nndrRatio, float, 0.8f); // NNDR RATIO
|
||||
|
||||
PARAMETER(General, nextObjID, unsigned int, 1);
|
||||
|
||||
|
||||
@ -24,10 +24,10 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="Object" name="cameraView" native="true"/>
|
||||
<widget class="ObjWidget" name="cameraView" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Object" name="objectView" native="true"/>
|
||||
<widget class="ObjWidget" name="objectView" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@ -80,9 +80,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Object</class>
|
||||
<class>ObjWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Object.h</header>
|
||||
<header>ObjWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
||||
@ -116,7 +116,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="Object" name="imageView_source" native="true"/>
|
||||
<widget class="ObjWidget" name="imageView_source" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -433,9 +433,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Object</class>
|
||||
<class>ObjWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Object.h</header>
|
||||
<header>ObjWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user