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 "
|
||||
" without saving modified parameters on closing.\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-time Show debug log with time.\n"
|
||||
" --params Show all parameters.\n"
|
||||
@ -137,6 +139,7 @@ int main(int argc, char* argv[])
|
||||
QString configPath = find_object::Settings::iniDefaultPath();
|
||||
QString jsonPath;
|
||||
find_object::ParametersMap customParameters;
|
||||
bool imagesSaved = true;
|
||||
|
||||
for(int i=1; i<argc; ++i)
|
||||
{
|
||||
@ -269,6 +272,12 @@ int main(int argc, char* argv[])
|
||||
guiMode = false;
|
||||
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 ||
|
||||
strcmp(argv[i], "--debug") == 0)
|
||||
{
|
||||
@ -392,7 +401,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// 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
|
||||
int objectsLoaded = 0;
|
||||
|
||||
@ -62,7 +62,7 @@ public:
|
||||
cv::Mat & Ai);
|
||||
|
||||
public:
|
||||
FindObject(QObject * parent = 0);
|
||||
FindObject(bool keepImagesInRAM_ = true, QObject * parent = 0);
|
||||
virtual ~FindObject();
|
||||
|
||||
bool loadSession(const QString & path);
|
||||
@ -104,6 +104,7 @@ private:
|
||||
KeypointDetector * detector_;
|
||||
DescriptorExtractor * extractor_;
|
||||
bool sessionModified_;
|
||||
bool keepImagesInRAM_;
|
||||
};
|
||||
|
||||
} // namespace find_object
|
||||
|
||||
@ -57,7 +57,7 @@ public:
|
||||
virtual ~ObjWidget();
|
||||
|
||||
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 resetKptsColor();
|
||||
void setKptColor(int index, const QColor & color);
|
||||
@ -111,6 +111,7 @@ private:
|
||||
int id_;
|
||||
std::vector<cv::KeyPoint> keypoints_;
|
||||
QPixmap pixmap_;
|
||||
QRect rect_;
|
||||
QList<KeypointItem*> keypointItems_;
|
||||
QGraphicsView * graphicsView_;
|
||||
QVector<QColor> kptColors_;
|
||||
|
||||
@ -43,12 +43,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
namespace find_object {
|
||||
|
||||
FindObject::FindObject(QObject * parent) :
|
||||
FindObject::FindObject(bool keepImagesInRAM, QObject * parent) :
|
||||
QObject(parent),
|
||||
vocabulary_(new Vocabulary()),
|
||||
detector_(Settings::createKeypointDetector()),
|
||||
extractor_(Settings::createDescriptorExtractor()),
|
||||
sessionModified_(false)
|
||||
sessionModified_(false),
|
||||
keepImagesInRAM_(keepImagesInRAM)
|
||||
{
|
||||
qRegisterMetaType<find_object::DetectionInfo>("find_object::DetectionInfo");
|
||||
UASSERT(detector_ != 0 && extractor_ != 0);
|
||||
@ -85,7 +86,7 @@ bool FindObject::loadSession(const QString & path)
|
||||
while(!in.atEnd())
|
||||
{
|
||||
ObjSignature * obj = new ObjSignature();
|
||||
obj->load(in);
|
||||
obj->load(in, !keepImagesInRAM_);
|
||||
if(obj->id() >= 0)
|
||||
{
|
||||
objects_.insert(obj->id(), obj);
|
||||
@ -705,6 +706,11 @@ void FindObject::updateObjects(const QList<int> & ids)
|
||||
int id = threads[j]->objectId();
|
||||
|
||||
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());
|
||||
|
||||
@ -981,7 +981,8 @@ void MainWindow::updateObjects(const QList<int> & ids)
|
||||
{
|
||||
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
|
||||
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) :
|
||||
id_(id),
|
||||
image_(image),
|
||||
rect_(0,0,image.cols, image.rows),
|
||||
filePath_(filePath)
|
||||
{}
|
||||
virtual ~ObjSignature() {}
|
||||
@ -56,8 +57,9 @@ public:
|
||||
}
|
||||
void setWords(const QMultiMap<int, int> & words) {words_ = words;}
|
||||
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_;}
|
||||
const QString & filePath() const {return filePath_;}
|
||||
@ -94,9 +96,11 @@ public:
|
||||
std::vector<unsigned char> bytes;
|
||||
cv::imencode(".png", image_, bytes);
|
||||
streamPtr << QByteArray((char*)bytes.data(), (int)bytes.size());
|
||||
|
||||
streamPtr << rect_;
|
||||
}
|
||||
|
||||
void load(QDataStream & streamPtr)
|
||||
void load(QDataStream & streamPtr, bool ignoreImage)
|
||||
{
|
||||
int nKpts;
|
||||
streamPtr >> id_ >> filePath_ >> nKpts;
|
||||
@ -124,14 +128,20 @@ public:
|
||||
|
||||
QByteArray image;
|
||||
streamPtr >> image;
|
||||
if(!ignoreImage)
|
||||
{
|
||||
std::vector<unsigned char> bytes(image.size());
|
||||
memcpy(bytes.data(), image.data(), image.size());
|
||||
image_ = cv::imdecode(bytes, cv::IMREAD_UNCHANGED);
|
||||
}
|
||||
|
||||
streamPtr >> rect_;
|
||||
}
|
||||
|
||||
private:
|
||||
int id_;
|
||||
cv::Mat image_;
|
||||
QRect rect_;
|
||||
QString filePath_;
|
||||
std::vector<cv::KeyPoint> keypoints_;
|
||||
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))))
|
||||
{
|
||||
setupUi();
|
||||
this->setData(keypoints, image);
|
||||
this->setData(keypoints, image, image.rect());
|
||||
}
|
||||
ObjWidget::~ObjWidget()
|
||||
{
|
||||
@ -264,7 +264,7 @@ void ObjWidget::setTextLabel(const QString & 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;
|
||||
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
|
||||
|
||||
pixmap_ = QPixmap::fromImage(image);
|
||||
rect_ = rect;
|
||||
if(rect_.isNull())
|
||||
{
|
||||
rect_ = pixmap_.rect();
|
||||
}
|
||||
//this->setMinimumSize(image_.size());
|
||||
|
||||
if(graphicsViewMode_->isChecked())
|
||||
@ -397,10 +402,10 @@ void ObjWidget::computeScaleOffsets(float & scale, float & offsetX, float & offs
|
||||
offsetX = 0.0f;
|
||||
offsetY = 0.0f;
|
||||
|
||||
if(!pixmap_.isNull())
|
||||
if(!rect_.isNull())
|
||||
{
|
||||
float w = pixmap_.width();
|
||||
float h = pixmap_.height();
|
||||
float w = rect_.width();
|
||||
float h = rect_.height();
|
||||
float widthRatio = float(this->rect().width()) / w;
|
||||
float heightRatio = float(this->rect().height()) / h;
|
||||
|
||||
@ -439,7 +444,7 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!pixmap_.isNull())
|
||||
if(!rect_.isNull())
|
||||
{
|
||||
//Scale
|
||||
float ratio, offsetX, offsetY;
|
||||
@ -448,7 +453,7 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
||||
|
||||
if(mirrorView_->isChecked())
|
||||
{
|
||||
painter.translate(offsetX+pixmap_.width()*ratio, offsetY);
|
||||
painter.translate(offsetX+rect_.width()*ratio, offsetY);
|
||||
painter.scale(-ratio, ratio);
|
||||
}
|
||||
else
|
||||
@ -457,7 +462,7 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
||||
painter.scale(ratio, ratio);
|
||||
}
|
||||
|
||||
if(showImage_->isChecked())
|
||||
if(!pixmap_.isNull() && showImage_->isChecked())
|
||||
{
|
||||
painter.drawPixmap(QPoint(0,0), pixmap_);
|
||||
}
|
||||
@ -487,15 +492,15 @@ void ObjWidget::paintEvent(QPaintEvent *event)
|
||||
if(mirrorView_->isChecked())
|
||||
{
|
||||
int l = left;
|
||||
left = qAbs(right - pixmap_.width());
|
||||
right = qAbs(l - pixmap_.width());
|
||||
left = qAbs(right - rect_.width());
|
||||
right = qAbs(l - rect_.width());
|
||||
}
|
||||
painter.setPen(Qt::NoPen);
|
||||
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(right, top, pixmap_.width()-right, bottom-top);
|
||||
painter.drawRect(0, bottom, pixmap_.width(), pixmap_.height()-bottom);
|
||||
painter.drawRect(right, top, rect_.width()-right, bottom-top);
|
||||
painter.drawRect(0, bottom, rect_.width(), rect_.height()-bottom);
|
||||
painter.restore();
|
||||
}
|
||||
}
|
||||
@ -534,7 +539,7 @@ void ObjWidget::mouseMoveEvent(QMouseEvent * event)
|
||||
|
||||
void ObjWidget::mouseReleaseEvent(QMouseEvent * event)
|
||||
{
|
||||
if(!pixmap_.isNull())
|
||||
if(!rect_.isNull())
|
||||
{
|
||||
int left,top,bottom,right;
|
||||
|
||||
@ -546,8 +551,8 @@ void ObjWidget::mouseReleaseEvent(QMouseEvent * event)
|
||||
if(mirrorView_->isChecked())
|
||||
{
|
||||
int l = left;
|
||||
left = qAbs(right - pixmap_.width());
|
||||
right = qAbs(l - pixmap_.width());
|
||||
left = qAbs(right - rect_.width());
|
||||
right = qAbs(l - rect_.width());
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if(!pixmap_.isNull())
|
||||
if(!rect_.isNull())
|
||||
{
|
||||
graphicsView_->setVisible(true);
|
||||
graphicsView_->scene()->setSceneRect(pixmap_.rect());
|
||||
graphicsView_->scene()->setSceneRect(rect_);
|
||||
QList<KeypointItem*> items;
|
||||
|
||||
QRectF sceneRect = graphicsView_->sceneRect();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user