Make it more obvious when a image can be exported as a png and when not
This commit is contained in:
@ -26,6 +26,7 @@ CvImageViewer::CvImageViewer(QWidget *parent, size_t lastId) :
|
|||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
lastId_(lastId),
|
lastId_(lastId),
|
||||||
saveAction_("Save Image", nullptr),
|
saveAction_("Save Image", nullptr),
|
||||||
|
exportAction_("Export Image as PNG", nullptr),
|
||||||
zoomAction_("Zoom to selection", nullptr),
|
zoomAction_("Zoom to selection", nullptr),
|
||||||
resetAction_("Reset Zoom", nullptr),
|
resetAction_("Reset Zoom", nullptr),
|
||||||
statisticsAction_("Get selection properties", nullptr),
|
statisticsAction_("Get selection properties", nullptr),
|
||||||
@ -36,6 +37,7 @@ CvImageViewer::CvImageViewer(QWidget *parent, size_t lastId) :
|
|||||||
qimage_.load(":/images/noimage.png");
|
qimage_.load(":/images/noimage.png");
|
||||||
|
|
||||||
connect(&saveAction_, &QAction::triggered, this, &CvImageViewer::saveImage);
|
connect(&saveAction_, &QAction::triggered, this, &CvImageViewer::saveImage);
|
||||||
|
connect(&exportAction_, &QAction::triggered, this, &CvImageViewer::exportImage);
|
||||||
connect(&zoomAction_, &QAction::triggered, this, &CvImageViewer::zoomToSelection);
|
connect(&zoomAction_, &QAction::triggered, this, &CvImageViewer::zoomToSelection);
|
||||||
connect(&resetAction_, &QAction::triggered, this, &CvImageViewer::resetZoom);
|
connect(&resetAction_, &QAction::triggered, this, &CvImageViewer::resetZoom);
|
||||||
connect(&statisticsAction_, &QAction::triggered, this, &CvImageViewer::showSatDiag);
|
connect(&statisticsAction_, &QAction::triggered, this, &CvImageViewer::showSatDiag);
|
||||||
@ -43,6 +45,7 @@ CvImageViewer::CvImageViewer(QWidget *parent, size_t lastId) :
|
|||||||
connect(&yPlotAction_, &QAction::triggered, this, &CvImageViewer::plotOnY);
|
connect(&yPlotAction_, &QAction::triggered, this, &CvImageViewer::plotOnY);
|
||||||
|
|
||||||
imageContextMenu_.addAction(&saveAction_);
|
imageContextMenu_.addAction(&saveAction_);
|
||||||
|
imageContextMenu_.addAction(&exportAction_);
|
||||||
imageContextMenu_.addAction(&zoomAction_);
|
imageContextMenu_.addAction(&zoomAction_);
|
||||||
imageContextMenu_.addAction(&resetAction_);
|
imageContextMenu_.addAction(&resetAction_);
|
||||||
imageContextMenu_.addAction(&statisticsAction_);
|
imageContextMenu_.addAction(&statisticsAction_);
|
||||||
@ -63,32 +66,31 @@ CvImageViewer::~CvImageViewer()
|
|||||||
|
|
||||||
void CvImageViewer::saveImage()
|
void CvImageViewer::saveImage()
|
||||||
{
|
{
|
||||||
QString fileName;
|
QString fileName = QFileDialog::getSaveFileName(this, "Save Image", lastSavePath_, "*.mat" );
|
||||||
if(origImage_.type() == CV_8UC3 || origImage_.type() == CV_8SC3 || origImage_.type() == CV_8UC1 || origImage_.type() == CV_8SC1)
|
|
||||||
{
|
|
||||||
fileName = QFileDialog::getSaveFileName(this, "Save Image", lastSavePath_, "*.mat *.png" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fileName = QFileDialog::getSaveFileName(this, "Save Image", lastSavePath_, "*.mat" );
|
|
||||||
}
|
|
||||||
if(!fileName.isEmpty())
|
if(!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
lastSavePath_= fileName.mid(0, fileName.lastIndexOf('/'));
|
lastSavePath_= fileName.mid(0, fileName.lastIndexOf('/'));
|
||||||
QStringList tokens = fileName.split('.');
|
QStringList tokens = fileName.split('.');
|
||||||
if(tokens.back() != "mat" && tokens.back() != "png")
|
if(tokens.back() != "mat")
|
||||||
fileName.append(".mat");
|
fileName.append(".mat");
|
||||||
tokens = fileName.split('.');
|
cv::FileStorage matf(fileName.toStdString(), cv::FileStorage::WRITE);
|
||||||
if(tokens.back() == "png")
|
matf<<"image"<<origImage_;
|
||||||
{
|
matf.release();
|
||||||
imwrite(fileName.toStdString(), origImage_);
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
void CvImageViewer::exportImage()
|
||||||
cv::FileStorage matf(fileName.toStdString(), cv::FileStorage::WRITE);
|
{
|
||||||
matf<<"image"<<origImage_;
|
if(!(origImage_.type() == CV_8UC3 || origImage_.type() == CV_8SC3 || origImage_.type() == CV_8UC1 || origImage_.type() == CV_8SC1))
|
||||||
matf.release();
|
return;
|
||||||
}
|
QString fileName = QFileDialog::getSaveFileName(this, "Save Image", lastSavePath_, "*.png" );
|
||||||
|
if(!fileName.isEmpty())
|
||||||
|
{
|
||||||
|
lastSavePath_= fileName.mid(0, fileName.lastIndexOf('/'));
|
||||||
|
QStringList tokens = fileName.split('.');
|
||||||
|
if(tokens.back() != "png")
|
||||||
|
fileName.append(".png");
|
||||||
|
imwrite(fileName.toStdString(), origImage_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +148,7 @@ void CvImageViewer::convertImage(cv::Mat image)
|
|||||||
statisticsAction_.setDisabled(true);
|
statisticsAction_.setDisabled(true);
|
||||||
xPlotAction_.setDisabled(true);
|
xPlotAction_.setDisabled(true);
|
||||||
yPlotAction_.setDisabled(true);
|
yPlotAction_.setDisabled(true);
|
||||||
|
exportAction_.setDisabled(false);
|
||||||
}
|
}
|
||||||
else if(image_.type() == CV_8UC1 || image_.type() == CV_8SC1)
|
else if(image_.type() == CV_8UC1 || image_.type() == CV_8SC1)
|
||||||
{
|
{
|
||||||
@ -153,6 +156,7 @@ void CvImageViewer::convertImage(cv::Mat image)
|
|||||||
statisticsAction_.setDisabled(false);
|
statisticsAction_.setDisabled(false);
|
||||||
xPlotAction_.setDisabled(false);
|
xPlotAction_.setDisabled(false);
|
||||||
yPlotAction_.setDisabled(false);
|
yPlotAction_.setDisabled(false);
|
||||||
|
exportAction_.setDisabled(false);
|
||||||
}
|
}
|
||||||
else if(image_.type() == CV_32FC1 || image_.type() == CV_64FC1)
|
else if(image_.type() == CV_32FC1 || image_.type() == CV_64FC1)
|
||||||
{
|
{
|
||||||
@ -173,6 +177,7 @@ void CvImageViewer::convertImage(cv::Mat image)
|
|||||||
statisticsAction_.setDisabled(false);
|
statisticsAction_.setDisabled(false);
|
||||||
xPlotAction_.setDisabled(false);
|
xPlotAction_.setDisabled(false);
|
||||||
yPlotAction_.setDisabled(false);
|
yPlotAction_.setDisabled(false);
|
||||||
|
exportAction_.setDisabled(true);
|
||||||
}
|
}
|
||||||
else if(image_.type() == CV_32FC3 || image_.type() == CV_64FC3)
|
else if(image_.type() == CV_32FC3 || image_.type() == CV_64FC3)
|
||||||
{
|
{
|
||||||
@ -189,14 +194,16 @@ void CvImageViewer::convertImage(cv::Mat image)
|
|||||||
statisticsAction_.setDisabled(true);
|
statisticsAction_.setDisabled(true);
|
||||||
xPlotAction_.setDisabled(true);
|
xPlotAction_.setDisabled(true);
|
||||||
yPlotAction_.setDisabled(true);
|
yPlotAction_.setDisabled(true);
|
||||||
|
exportAction_.setDisabled(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
image_.convertTo(image_, CV_8UC1, 255, 0);
|
image_.convertTo(image_, CV_8UC1, 255, 0);
|
||||||
qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_Grayscale8);
|
qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_Grayscale8);
|
||||||
statisticsAction_.setDisabled(true);
|
statisticsAction_.setDisabled(false);
|
||||||
xPlotAction_.setDisabled(true);
|
xPlotAction_.setDisabled(false);
|
||||||
yPlotAction_.setDisabled(true);
|
yPlotAction_.setDisabled(false);
|
||||||
|
exportAction_.setDisabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ private:
|
|||||||
QMenu imageContextMenu_;
|
QMenu imageContextMenu_;
|
||||||
Plot plot;
|
Plot plot;
|
||||||
QAction saveAction_;
|
QAction saveAction_;
|
||||||
|
QAction exportAction_;
|
||||||
QAction zoomAction_;
|
QAction zoomAction_;
|
||||||
QAction resetAction_;
|
QAction resetAction_;
|
||||||
QAction statisticsAction_;
|
QAction statisticsAction_;
|
||||||
@ -58,6 +59,7 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void saveImage();
|
void saveImage();
|
||||||
|
void exportImage();
|
||||||
void zoomToSelection();
|
void zoomToSelection();
|
||||||
void resetZoom();
|
void resetZoom();
|
||||||
void showSatDiag();
|
void showSatDiag();
|
||||||
|
@ -114,7 +114,7 @@ void MainWindow::openImage()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(matf.isOpened() && (!image.data || image.type() != CV_32FC1))
|
if(matf.isOpened() && !image.data)
|
||||||
{
|
{
|
||||||
image.release();
|
image.release();
|
||||||
QMessageBox::warning(this, "Invalid file", "File selected dose not contain a valid image");
|
QMessageBox::warning(this, "Invalid file", "File selected dose not contain a valid image");
|
||||||
|
Reference in New Issue
Block a user