Added "--images_not_saved" argument to not keep images in RAM after the features are extracted (only in console mode)
This commit is contained in:
parent
9754130ec8
commit
388236e5c4
11
app/main.cpp
11
app/main.cpp
@ -106,6 +106,8 @@ void showUsage()
|
|||||||
" If set to \"\", default parameters are used "
|
" If set to \"\", default parameters are used "
|
||||||
" without saving modified parameters on closing.\n"
|
" without saving modified parameters on closing.\n"
|
||||||
" --scene \"path\" Path to a scene image file.\n"
|
" --scene \"path\" Path to a scene image file.\n"
|
||||||
|
" --images_not_saved Don't keep images in RAM after the features are extracted (only\n"
|
||||||
|
" in console mode). Images won't be saved if an output session is set.\n"
|
||||||
" --debug Show debug log.\n"
|
" --debug Show debug log.\n"
|
||||||
" --debug-time Show debug log with time.\n"
|
" --debug-time Show debug log with time.\n"
|
||||||
" --params Show all parameters.\n"
|
" --params Show all parameters.\n"
|
||||||
@ -137,6 +139,7 @@ int main(int argc, char* argv[])
|
|||||||
QString configPath = find_object::Settings::iniDefaultPath();
|
QString configPath = find_object::Settings::iniDefaultPath();
|
||||||
QString jsonPath;
|
QString jsonPath;
|
||||||
find_object::ParametersMap customParameters;
|
find_object::ParametersMap customParameters;
|
||||||
|
bool imagesSaved = true;
|
||||||
|
|
||||||
for(int i=1; i<argc; ++i)
|
for(int i=1; i<argc; ++i)
|
||||||
{
|
{
|
||||||
@ -269,6 +272,12 @@ int main(int argc, char* argv[])
|
|||||||
guiMode = false;
|
guiMode = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(strcmp(argv[i], "-images_not_saved") == 0 ||
|
||||||
|
strcmp(argv[i], "--images_not_saved") == 0)
|
||||||
|
{
|
||||||
|
imagesSaved = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(strcmp(argv[i], "-debug") == 0 ||
|
if(strcmp(argv[i], "-debug") == 0 ||
|
||||||
strcmp(argv[i], "--debug") == 0)
|
strcmp(argv[i], "--debug") == 0)
|
||||||
{
|
{
|
||||||
@ -392,7 +401,7 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create FindObject
|
// Create FindObject
|
||||||
find_object::FindObject * findObject = new find_object::FindObject();
|
find_object::FindObject * findObject = new find_object::FindObject(guiMode || imagesSaved);
|
||||||
|
|
||||||
// Load objects if path is set
|
// Load objects if path is set
|
||||||
int objectsLoaded = 0;
|
int objectsLoaded = 0;
|
||||||
|
|||||||
@ -62,7 +62,7 @@ public:
|
|||||||
cv::Mat & Ai);
|
cv::Mat & Ai);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FindObject(QObject * parent = 0);
|
FindObject(bool keepImagesInRAM_ = true, QObject * parent = 0);
|
||||||
virtual ~FindObject();
|
virtual ~FindObject();
|
||||||
|
|
||||||
bool loadSession(const QString & path);
|
bool loadSession(const QString & path);
|
||||||
@ -104,6 +104,7 @@ private:
|
|||||||
KeypointDetector * detector_;
|
KeypointDetector * detector_;
|
||||||
DescriptorExtractor * extractor_;
|
DescriptorExtractor * extractor_;
|
||||||
bool sessionModified_;
|
bool sessionModified_;
|
||||||
|
bool keepImagesInRAM_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace find_object
|
} // namespace find_object
|
||||||
|
|||||||
@ -57,7 +57,7 @@ public:
|
|||||||
virtual ~ObjWidget();
|
virtual ~ObjWidget();
|
||||||
|
|
||||||
void setId(int id);
|
void setId(int id);
|
||||||
void setData(const std::vector<cv::KeyPoint> & keypoints, const QImage & image);
|
void setData(const std::vector<cv::KeyPoint> & keypoints, const QImage & image, const QRect & rect = QRect());
|
||||||
void setTextLabel(const QString & text);
|
void setTextLabel(const QString & text);
|
||||||
void resetKptsColor();
|
void resetKptsColor();
|
||||||
void setKptColor(int index, const QColor & color);
|
void setKptColor(int index, const QColor & color);
|
||||||
@ -111,6 +111,7 @@ private:
|
|||||||
int id_;
|
int id_;
|
||||||
std::vector<cv::KeyPoint> keypoints_;
|
std::vector<cv::KeyPoint> keypoints_;
|
||||||
QPixmap pixmap_;
|
QPixmap pixmap_;
|
||||||
|
QRect rect_;
|
||||||
QList<KeypointItem*> keypointItems_;
|
QList<KeypointItem*> keypointItems_;
|
||||||
QGraphicsView * graphicsView_;
|
QGraphicsView * graphicsView_;
|
||||||
QVector<QColor> kptColors_;
|
QVector<QColor> kptColors_;
|
||||||
|
|||||||
@ -43,12 +43,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
namespace find_object {
|
namespace find_object {
|
||||||
|
|
||||||
FindObject::FindObject(QObject * parent) :
|
FindObject::FindObject(bool keepImagesInRAM, QObject * parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
vocabulary_(new Vocabulary()),
|
vocabulary_(new Vocabulary()),
|
||||||
detector_(Settings::createKeypointDetector()),
|
detector_(Settings::createKeypointDetector()),
|
||||||
extractor_(Settings::createDescriptorExtractor()),
|
extractor_(Settings::createDescriptorExtractor()),
|
||||||
sessionModified_(false)
|
sessionModified_(false),
|
||||||
|
keepImagesInRAM_(keepImagesInRAM)
|
||||||
{
|
{
|
||||||
qRegisterMetaType<find_object::DetectionInfo>("find_object::DetectionInfo");
|
qRegisterMetaType<find_object::DetectionInfo>("find_object::DetectionInfo");
|
||||||
UASSERT(detector_ != 0 && extractor_ != 0);
|
UASSERT(detector_ != 0 && extractor_ != 0);
|
||||||
@ -85,7 +86,7 @@ bool FindObject::loadSession(const QString & path)
|
|||||||
while(!in.atEnd())
|
while(!in.atEnd())
|
||||||
{
|
{
|
||||||
ObjSignature * obj = new ObjSignature();
|
ObjSignature * obj = new ObjSignature();
|
||||||
obj->load(in);
|
obj->load(in, !keepImagesInRAM_);
|
||||||
if(obj->id() >= 0)
|
if(obj->id() >= 0)
|
||||||
{
|
{
|
||||||
objects_.insert(obj->id(), obj);
|
objects_.insert(obj->id(), obj);
|
||||||
@ -705,6 +706,11 @@ void FindObject::updateObjects(const QList<int> & ids)
|
|||||||
int id = threads[j]->objectId();
|
int id = threads[j]->objectId();
|
||||||
|
|
||||||
objects_.value(id)->setData(threads[j]->keypoints(), threads[j]->descriptors());
|
objects_.value(id)->setData(threads[j]->keypoints(), threads[j]->descriptors());
|
||||||
|
|
||||||
|
if(!keepImagesInRAM_)
|
||||||
|
{
|
||||||
|
objects_.value(id)->removeImage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UINFO("Features extraction from %d objects... done! (%d ms)", objectsList.size(), time.elapsed());
|
UINFO("Features extraction from %d objects... done! (%d ms)", objectsList.size(), time.elapsed());
|
||||||
|
|||||||
@ -981,7 +981,8 @@ void MainWindow::updateObjects(const QList<int> & ids)
|
|||||||
{
|
{
|
||||||
if(ids.contains(signatures[i]->id()))
|
if(ids.contains(signatures[i]->id()))
|
||||||
{
|
{
|
||||||
objWidgets_.value(signatures[i]->id())->setData(signatures[i]->keypoints(), cvtCvMat2QImage(signatures[i]->image()));
|
QImage qtImage = cvtCvMat2QImage(signatures[i]->image());
|
||||||
|
objWidgets_.value(signatures[i]->id())->setData(signatures[i]->keypoints(), qtImage, signatures[i]->rect());
|
||||||
|
|
||||||
//update object labels
|
//update object labels
|
||||||
QLabel * title = qFindChild<QLabel*>(this, QString("%1title").arg(signatures[i]->id()));
|
QLabel * title = qFindChild<QLabel*>(this, QString("%1title").arg(signatures[i]->id()));
|
||||||
|
|||||||
@ -45,6 +45,7 @@ public:
|
|||||||
ObjSignature(int id, const cv::Mat & image, const QString & filePath) :
|
ObjSignature(int id, const cv::Mat & image, const QString & filePath) :
|
||||||
id_(id),
|
id_(id),
|
||||||
image_(image),
|
image_(image),
|
||||||
|
rect_(0,0,image.cols, image.rows),
|
||||||
filePath_(filePath)
|
filePath_(filePath)
|
||||||
{}
|
{}
|
||||||
virtual ~ObjSignature() {}
|
virtual ~ObjSignature() {}
|
||||||
@ -56,8 +57,9 @@ public:
|
|||||||
}
|
}
|
||||||
void setWords(const QMultiMap<int, int> & words) {words_ = words;}
|
void setWords(const QMultiMap<int, int> & words) {words_ = words;}
|
||||||
void setId(int id) {id_ = id;}
|
void setId(int id) {id_ = id;}
|
||||||
|
void removeImage() {image_ = cv::Mat();}
|
||||||
|
|
||||||
QRect rect() const {return QRect(0,0,image_.cols, image_.rows);}
|
const QRect & rect() const {return rect_;}
|
||||||
|
|
||||||
int id() const {return id_;}
|
int id() const {return id_;}
|
||||||
const QString & filePath() const {return filePath_;}
|
const QString & filePath() const {return filePath_;}
|
||||||
@ -94,9 +96,11 @@ public:
|
|||||||
std::vector<unsigned char> bytes;
|
std::vector<unsigned char> bytes;
|
||||||
cv::imencode(".png", image_, bytes);
|
cv::imencode(".png", image_, bytes);
|
||||||
streamPtr << QByteArray((char*)bytes.data(), (int)bytes.size());
|
streamPtr << QByteArray((char*)bytes.data(), (int)bytes.size());
|
||||||
|
|
||||||
|
streamPtr << rect_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(QDataStream & streamPtr)
|
void load(QDataStream & streamPtr, bool ignoreImage)
|
||||||
{
|
{
|
||||||
int nKpts;
|
int nKpts;
|
||||||
streamPtr >> id_ >> filePath_ >> nKpts;
|
streamPtr >> id_ >> filePath_ >> nKpts;
|
||||||
@ -124,14 +128,20 @@ public:
|
|||||||
|
|
||||||
QByteArray image;
|
QByteArray image;
|
||||||
streamPtr >> image;
|
streamPtr >> image;
|
||||||
|
if(!ignoreImage)
|
||||||
|
{
|
||||||
std::vector<unsigned char> bytes(image.size());
|
std::vector<unsigned char> bytes(image.size());
|
||||||
memcpy(bytes.data(), image.data(), image.size());
|
memcpy(bytes.data(), image.data(), image.size());
|
||||||
image_ = cv::imdecode(bytes, cv::IMREAD_UNCHANGED);
|
image_ = cv::imdecode(bytes, cv::IMREAD_UNCHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
streamPtr >> rect_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int id_;
|
int id_;
|
||||||
cv::Mat image_;
|
cv::Mat image_;
|
||||||
|
QRect rect_;
|
||||||
QString filePath_;
|
QString filePath_;
|
||||||
std::vector<cv::KeyPoint> keypoints_;
|
std::vector<cv::KeyPoint> keypoints_;
|
||||||
cv::Mat descriptors_;
|
cv::Mat descriptors_;
|
||||||
|
|||||||
@ -74,7 +74,7 @@ ObjWidget::ObjWidget(int id, const std::vector<cv::KeyPoint> & keypoints, const
|
|||||||
color_(QColor((Qt::GlobalColor)((id % 11 + 7)==Qt::yellow?Qt::gray:(id % 11 + 7))))
|
color_(QColor((Qt::GlobalColor)((id % 11 + 7)==Qt::yellow?Qt::gray:(id % 11 + 7))))
|
||||||
{
|
{
|
||||||
setupUi();
|
setupUi();
|
||||||
this->setData(keypoints, image);
|
this->setData(keypoints, image, image.rect());
|
||||||
}
|
}
|
||||||
ObjWidget::~ObjWidget()
|
ObjWidget::~ObjWidget()
|
||||||
{
|
{
|
||||||
@ -264,7 +264,7 @@ void ObjWidget::setTextLabel(const QString & text)
|
|||||||
label_->setText(text);
|
label_->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjWidget::setData(const std::vector<cv::KeyPoint> & keypoints, const QImage & image)
|
void ObjWidget::setData(const std::vector<cv::KeyPoint> & keypoints, const QImage & image, const QRect & rect)
|
||||||
{
|
{
|
||||||
keypoints_ = keypoints;
|
keypoints_ = keypoints;
|
||||||
kptColors_ = QVector<QColor>((int)keypoints.size(), defaultColor());
|
kptColors_ = QVector<QColor>((int)keypoints.size(), defaultColor());
|
||||||
@ -275,6 +275,11 @@ void ObjWidget::setData(const std::vector<cv::KeyPoint> & keypoints, const QImag
|
|||||||
mouseCurrentPos_ = mousePressedPos_; // this will reset roi selection
|
mouseCurrentPos_ = mousePressedPos_; // this will reset roi selection
|
||||||
|
|
||||||
pixmap_ = QPixmap::fromImage(image);
|
pixmap_ = QPixmap::fromImage(image);
|
||||||
|
rect_ = rect;
|
||||||
|
if(rect_.isNull())
|
||||||
|
{
|
||||||
|
rect_ = pixmap_.rect();
|
||||||
|
}
|
||||||
//this->setMinimumSize(image_.size());
|
//this->setMinimumSize(image_.size());
|
||||||
|
|
||||||
if(graphicsViewMode_->isChecked())
|
if(graphicsViewMode_->isChecked())
|
||||||
@ -397,10 +402,10 @@ void ObjWidget::computeScaleOffsets(float & scale, float & offsetX, float & offs
|
|||||||
offsetX = 0.0f;
|
offsetX = 0.0f;
|
||||||
offsetY = 0.0f;
|
offsetY = 0.0f;
|
||||||
|
|
||||||
if(!pixmap_.isNull())
|
if(!rect_.isNull())
|
||||||
{
|
{
|
||||||
float w = pixmap_.width();
|
float w = rect_.width();
|
||||||
float h = pixmap_.height();
|
float h = rect_.height();
|
||||||
float widthRatio = float(this->rect().width()) / w;
|
float widthRatio = float(this->rect().width()) / w;
|
||||||
float heightRatio = float(this->rect().height()) / h;
|
float heightRatio = float(this->rect().height()) / h;
|
||||||
|
|
||||||
@ -439,7 +444,7 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!pixmap_.isNull())
|
if(!rect_.isNull())
|
||||||
{
|
{
|
||||||
//Scale
|
//Scale
|
||||||
float ratio, offsetX, offsetY;
|
float ratio, offsetX, offsetY;
|
||||||
@ -448,7 +453,7 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
if(mirrorView_->isChecked())
|
if(mirrorView_->isChecked())
|
||||||
{
|
{
|
||||||
painter.translate(offsetX+pixmap_.width()*ratio, offsetY);
|
painter.translate(offsetX+rect_.width()*ratio, offsetY);
|
||||||
painter.scale(-ratio, ratio);
|
painter.scale(-ratio, ratio);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -457,7 +462,7 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
|||||||
painter.scale(ratio, ratio);
|
painter.scale(ratio, ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(showImage_->isChecked())
|
if(!pixmap_.isNull() && showImage_->isChecked())
|
||||||
{
|
{
|
||||||
painter.drawPixmap(QPoint(0,0), pixmap_);
|
painter.drawPixmap(QPoint(0,0), pixmap_);
|
||||||
}
|
}
|
||||||
@ -487,15 +492,15 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
|||||||
if(mirrorView_->isChecked())
|
if(mirrorView_->isChecked())
|
||||||
{
|
{
|
||||||
int l = left;
|
int l = left;
|
||||||
left = qAbs(right - pixmap_.width());
|
left = qAbs(right - rect_.width());
|
||||||
right = qAbs(l - pixmap_.width());
|
right = qAbs(l - rect_.width());
|
||||||
}
|
}
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.setBrush(QBrush(QColor(0,0,0,100)));
|
painter.setBrush(QBrush(QColor(0,0,0,100)));
|
||||||
painter.drawRect(0, 0, pixmap_.width(), top);
|
painter.drawRect(0, 0, rect_.width(), top);
|
||||||
painter.drawRect(0, top, left, bottom-top);
|
painter.drawRect(0, top, left, bottom-top);
|
||||||
painter.drawRect(right, top, pixmap_.width()-right, bottom-top);
|
painter.drawRect(right, top, rect_.width()-right, bottom-top);
|
||||||
painter.drawRect(0, bottom, pixmap_.width(), pixmap_.height()-bottom);
|
painter.drawRect(0, bottom, rect_.width(), rect_.height()-bottom);
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -534,7 +539,7 @@ void ObjWidget::mouseMoveEvent(QMouseEvent * event)
|
|||||||
|
|
||||||
void ObjWidget::mouseReleaseEvent(QMouseEvent * event)
|
void ObjWidget::mouseReleaseEvent(QMouseEvent * event)
|
||||||
{
|
{
|
||||||
if(!pixmap_.isNull())
|
if(!rect_.isNull())
|
||||||
{
|
{
|
||||||
int left,top,bottom,right;
|
int left,top,bottom,right;
|
||||||
|
|
||||||
@ -546,8 +551,8 @@ void ObjWidget::mouseReleaseEvent(QMouseEvent * event)
|
|||||||
if(mirrorView_->isChecked())
|
if(mirrorView_->isChecked())
|
||||||
{
|
{
|
||||||
int l = left;
|
int l = left;
|
||||||
left = qAbs(right - pixmap_.width());
|
left = qAbs(right - rect_.width());
|
||||||
right = qAbs(l - pixmap_.width());
|
right = qAbs(l - rect_.width());
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT roiChanged(cv::Rect(left, top, right-left, bottom-top));
|
Q_EMIT roiChanged(cv::Rect(left, top, right-left, bottom-top));
|
||||||
@ -747,10 +752,10 @@ std::vector<cv::KeyPoint> ObjWidget::selectedKeypoints() const
|
|||||||
|
|
||||||
void ObjWidget::setupGraphicsView()
|
void ObjWidget::setupGraphicsView()
|
||||||
{
|
{
|
||||||
if(!pixmap_.isNull())
|
if(!rect_.isNull())
|
||||||
{
|
{
|
||||||
graphicsView_->setVisible(true);
|
graphicsView_->setVisible(true);
|
||||||
graphicsView_->scene()->setSceneRect(pixmap_.rect());
|
graphicsView_->scene()->setSceneRect(rect_);
|
||||||
QList<KeypointItem*> items;
|
QList<KeypointItem*> items;
|
||||||
|
|
||||||
QRectF sceneRect = graphicsView_->sceneRect();
|
QRectF sceneRect = graphicsView_->sceneRect();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user