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