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:
+9
-3
@@ -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());
|
||||
|
||||
+2
-1
@@ -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()));
|
||||
|
||||
+15
-5
@@ -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;
|
||||
std::vector<unsigned char> bytes(image.size());
|
||||
memcpy(bytes.data(), image.data(), image.size());
|
||||
image_ = cv::imdecode(bytes, cv::IMREAD_UNCHANGED);
|
||||
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_;
|
||||
|
||||
+23
-18
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user