mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 01:20:25 +08:00
Updated ImageView with GraphicsView mode disabled by default. Updated DataRecorder.
This commit is contained in:
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <rtabmap/utilite/ULogger.h>
|
||||
#include <rtabmap/utilite/UTimer.h>
|
||||
#include <rtabmap/core/Memory.h>
|
||||
#include <rtabmap/core/Signature.h>
|
||||
#include <rtabmap/core/CameraEvent.h>
|
||||
#include <rtabmap/core/util3d.h>
|
||||
#include <rtabmap/gui/ImageView.h>
|
||||
@@ -37,7 +38,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <QtCore/QMetaType>
|
||||
#include <QMessageBox>
|
||||
#include <QtGui/QCloseEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace rtabmap {
|
||||
|
||||
@@ -46,18 +48,25 @@ DataRecorder::DataRecorder(QWidget * parent) :
|
||||
QWidget(parent),
|
||||
memory_(0),
|
||||
imageView_(new ImageView(this)),
|
||||
dataQueue_(0)
|
||||
label_(new QLabel(this)),
|
||||
processingImages_(false),
|
||||
count_(0),
|
||||
totalSizeKB_(0)
|
||||
{
|
||||
qRegisterMetaType<rtabmap::SensorData>("rtabmap::SensorData");
|
||||
qRegisterMetaType<cv::Mat>("cv::Mat");
|
||||
|
||||
imageView_->setImageDepthShown(true);
|
||||
QHBoxLayout * layout = new QHBoxLayout(this);
|
||||
imageView_->setMinimumSize(320, 240);
|
||||
QVBoxLayout * layout = new QVBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
layout->addWidget(imageView_);
|
||||
layout->addWidget(label_);
|
||||
layout->setStretch(0,1);
|
||||
this->setLayout(layout);
|
||||
}
|
||||
bool DataRecorder::init(const QString & path, bool recordInRAM)
|
||||
{
|
||||
UScopeMutex scope(memoryMutex_);
|
||||
if(!memory_)
|
||||
{
|
||||
ParametersMap customParameters;
|
||||
@@ -88,11 +97,16 @@ bool DataRecorder::init(const QString & path, bool recordInRAM)
|
||||
|
||||
void DataRecorder::closeRecorder()
|
||||
{
|
||||
memoryMutex_.lock();
|
||||
if(memory_)
|
||||
{
|
||||
delete memory_;
|
||||
memory_ = 0;
|
||||
}
|
||||
memoryMutex_.unlock();
|
||||
processingImages_ = false;
|
||||
count_ = 0;
|
||||
totalSizeKB_ = 0;
|
||||
UINFO("Data recorded to \"%s\".", this->path().toStdString().c_str());
|
||||
if(this->isVisible())
|
||||
{
|
||||
@@ -102,36 +116,39 @@ void DataRecorder::closeRecorder()
|
||||
|
||||
DataRecorder::~DataRecorder()
|
||||
{
|
||||
this->unregisterFromEventsManager();
|
||||
this->closeRecorder();
|
||||
}
|
||||
|
||||
void DataRecorder::addData(const rtabmap::SensorData & data)
|
||||
{
|
||||
memoryMutex_.lock();
|
||||
if(memory_)
|
||||
{
|
||||
//save to database
|
||||
UTimer time;
|
||||
memory_->update(data);
|
||||
const Signature * s = memory_->getLastWorkingSignature();
|
||||
totalSizeKB_ += s->getImageCompressed().total()/1000;
|
||||
totalSizeKB_ += s->getDepthCompressed().total()/1000;
|
||||
memory_->cleanup();
|
||||
|
||||
if(data.id() % 30)
|
||||
if(++count_ % 30)
|
||||
{
|
||||
memory_->emptyTrash();
|
||||
}
|
||||
|
||||
UDEBUG("Time to process a message = %f s", time.ticks());
|
||||
}
|
||||
--dataQueue_;
|
||||
memoryMutex_.unlock();
|
||||
}
|
||||
|
||||
void DataRecorder::showImage(const rtabmap::SensorData & data)
|
||||
void DataRecorder::showImage(const cv::Mat & image, const cv::Mat & depth)
|
||||
{
|
||||
if(this->isVisible() && data.isValid())
|
||||
{
|
||||
imageView_->setImage(uCvMat2QImage(data.image()));
|
||||
imageView_->setImageDepth(uCvMat2QImage(data.depth()));
|
||||
imageView_->fitInView(imageView_->sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
processingImages_ = true;
|
||||
imageView_->setImage(uCvMat2QImage(image));
|
||||
imageView_->setImageDepth(uCvMat2QImage(depth));
|
||||
label_->setText(tr("Images=%1 (~%2 MB)").arg(count_).arg(totalSizeKB_/1000));
|
||||
processingImages_ = false;
|
||||
}
|
||||
|
||||
void DataRecorder::closeEvent(QCloseEvent* event)
|
||||
@@ -142,24 +159,26 @@ void DataRecorder::closeEvent(QCloseEvent* event)
|
||||
|
||||
void DataRecorder::handleEvent(UEvent * event)
|
||||
{
|
||||
if(event->getClassName().compare("CameraEvent") == 0)
|
||||
if(memory_)
|
||||
{
|
||||
CameraEvent * camEvent = (CameraEvent*)event;
|
||||
if(camEvent->getCode() == CameraEvent::kCodeImageDepth ||
|
||||
camEvent->getCode() == CameraEvent::kCodeImage)
|
||||
if(event->getClassName().compare("CameraEvent") == 0)
|
||||
{
|
||||
if(camEvent->data().isValid())
|
||||
CameraEvent * camEvent = (CameraEvent*)event;
|
||||
if(camEvent->getCode() == CameraEvent::kCodeImageDepth ||
|
||||
camEvent->getCode() == CameraEvent::kCodeImage)
|
||||
{
|
||||
UINFO("Receiving rate = %f Hz", 1.0f/timer_.ticks());
|
||||
if(memory_)
|
||||
if(camEvent->data().isValid())
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "addData", Q_ARG(rtabmap::SensorData, camEvent->data()));
|
||||
++dataQueue_;
|
||||
}
|
||||
UINFO("Receiving rate = %f Hz", 1.0f/timer_.ticks());
|
||||
this->addData(camEvent->data());
|
||||
|
||||
if(dataQueue_ < 2 && this->isVisible())
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "showImage", Q_ARG(rtabmap::SensorData, camEvent->data()));
|
||||
if(!processingImages_ && this->isVisible() && camEvent->data().isValid())
|
||||
{
|
||||
processingImages_ = true;
|
||||
QMetaObject::invokeMethod(this, "showImage",
|
||||
Q_ARG(cv::Mat, camEvent->data().image()),
|
||||
Q_ARG(cv::Mat, camEvent->data().depth()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user