mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 09:31:40 +08:00
added RGB image plot example/test
This commit is contained in:
parent
9d50c352e6
commit
a446de1ff5
15
README.md
15
README.md
@ -1,5 +1,5 @@
|
||||
# JKQtPlotter
|
||||
This is an extensive library of function/data plotter classes for Qt (>= 4.7, tested with Qt up to 5.4).
|
||||
This is an extensive library of function/data plotter classes for Qt (>= 4.7, tested with Qt up to 5.11).
|
||||
|
||||
This software is licensed under the term of the GNU Lesser General Public License 2.1
|
||||
(LGPL 2.1) or above.
|
||||
@ -17,17 +17,18 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
|
||||
| Screenshot | Description | Notes |
|
||||
|:-------------:| ------------- | ------------- |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest1_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest) | [Very Basic Example (Line Graph)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest) | C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_symbols_and_errors_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | [Simple Line/Symbol Graph With Errorbars](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_barchart_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | [Simple Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarVerticalGraphStacked_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | [Stacked Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | C++-style vectors of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest1_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest) | [Very Basic Example (Line Graph)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest) | `JKQTPxyLineGraph`<br/>C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_symbols_and_errors_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | [Simple Line/Symbol Graph With Errorbars](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | `JKQTPxyLineErrorGraph`<br/>C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_barchart_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | [Simple Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | `JKQTPbarVerticalGraph`<br/>C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarVerticalGraphStacked_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | [Stacked Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | `JKQTPbarVerticalStackableGraph`, `JKQTPbarHorizontalStackableGraph`<br/>C++-style vectors of data |
|
||||
|
||||
### Image data Plots
|
||||
|
||||
| Screenshot | Description | Notes |
|
||||
|:-------------:| ------------- | ------------- |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_imageplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot) | [1-channel Raw C Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot) | image data copied from C-style row-major array into a single column of the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_imageplot_opencv_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot_opencv) | [1-channel OpenCV cv::Mat Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot_opencv) | image data copied from OpenCV cv::Mat-structure into a single column of the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_imageplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot) | [1-channel Raw C Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot) | `JKQTPColumnMathImage`<br/>image data copied from C-style row-major array into a single column of the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_imageplot_opencv_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot_opencv) | [1-channel OpenCV cv::Mat Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_imageplot_opencv) | `JKQTPColumnMathImage`<br/>image data copied from OpenCV cv::Mat-structure into a single column of the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_rgbimageplot_opencv_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_rgbimageplot_opencv) | [RGB OpenCV cv::Mat Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_rgbimageplot_opencv) | `JKQTPColumnRGBMathImage`<br/>image data copied from OpenCV cv::Mat-structure into three columns of the internal datastore |
|
||||
|
||||
### Tools and Special Features
|
||||
|
||||
|
@ -274,6 +274,8 @@ class LIB_EXPORT JKQTPdatastore{
|
||||
* \param name name for the column
|
||||
* \param channel to copy from \a mat
|
||||
* \return the ID of the newly created column
|
||||
*
|
||||
* \note You need to define the Macro JKQTPLOTTER_OPENCV_INTERFACE when compiling this lib to enabled this function.
|
||||
*/
|
||||
size_t copyCvMatToColumn(const cv::Mat& mat, const QString& name=QString(""), int channel=0);
|
||||
#endif
|
||||
|
@ -508,13 +508,22 @@ class LIB_EXPORT JKQTPRGBMathImage: public JKQTPMathImageBase {
|
||||
JKQTPGET_SET_MACRO(int, colorBarOffset)
|
||||
JKQTPGET_SET_MACRO(double, colorBarRelativeHeight)
|
||||
JKQTPGET_SET_MACRO(double, imageMin)
|
||||
inline void set_imageMinR(double m) {
|
||||
set_imageMin(m);
|
||||
}
|
||||
JKQTPGET_SET_MACRO(double, imageMax)
|
||||
inline void set_imageMaxR(double m) {
|
||||
set_imageMax(m);
|
||||
}
|
||||
JKQTPGET_SET_MACRO(double, imageMinG)
|
||||
JKQTPGET_SET_MACRO(double, imageMaxG)
|
||||
JKQTPGET_SET_MACRO(double, imageMinB)
|
||||
JKQTPGET_SET_MACRO(double, imageMaxB)
|
||||
JKQTPGET_SET_MACRO(bool, autoImageRange)
|
||||
JKQTPGET_SET_MACRO(QString, imageName)
|
||||
inline void set_imageNameR(const QString& m) {
|
||||
set_imageName(m);
|
||||
}
|
||||
JKQTPGET_SET_MACRO(QString, imageNameG)
|
||||
JKQTPGET_SET_MACRO(QString, imageNameB)
|
||||
JKQTPGET_SET_MACRO(QString, imageNameFontName)
|
||||
|
BIN
screenshots/jkqtplotter_simpletest_rgbimageplot_opencv.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_rgbimageplot_opencv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 326 KiB |
BIN
screenshots/jkqtplotter_simpletest_rgbimageplot_opencv_small.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_rgbimageplot_opencv_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@ -3,9 +3,12 @@
|
||||
# JKQtPlotter
|
||||
|
||||
## Simple math image plot, showin a 1-channel OpenCV cv::Mat
|
||||
This project (see `./test/jkqtplotter_simpletest_imageplot_opencv/`) simply creates a JKQtPlotter widget (as a new window) and adds a color-coded image plot of a mathematical function (here the Airy disk). The image is stored as a simple C-array in row-major ordering and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore). This very simple interface can also be used to interface with many common image processing libraries, like CImg or OpenCV.
|
||||
This project (see `./test/jkqtplotter_simpletest_imageplot_opencv/`) simply creates a JKQtPlotter widget (as a new window) and adds a color-coded image plot of a mathematical function (here the Airy disk). The image is generated as an OpenCV cv::Mat image and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore).
|
||||
To copy the data a special OpenCV Interface function `JKQTPdatastore::copyCvMatToColumn()` is used, that copies the data from a cv::Mat directly into a column.
|
||||
|
||||
The soruce code of the main application is (see `./test/jkqtplotter_simpletest_imageplot_opencv/jkqtplotter_simpletest_imageplot_opencv.cpp`):
|
||||
The function `JKQTPdatastore::copyCvMatToColumn()` is only available, when the preprocessore macro `JKQTPLOTTER_OPENCV_INTERFACE` is defined when compiling the JKQtPlotter library.
|
||||
|
||||
The source code of the main application is (see `./test/jkqtplotter_simpletest_imageplot_opencv/jkqtplotter_simpletest_imageplot_opencv.cpp`):
|
||||
```c++
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
|
1
test/jkqtplotter_simpletest_rgbimageplot_opencv/.gitignore
vendored
Normal file
1
test/jkqtplotter_simpletest_rgbimageplot_opencv/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/OpenCV-3.4.1
|
103
test/jkqtplotter_simpletest_rgbimageplot_opencv/README.md
Normal file
103
test/jkqtplotter_simpletest_rgbimageplot_opencv/README.md
Normal file
@ -0,0 +1,103 @@
|
||||
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
||||
|
||||
# JKQtPlotter
|
||||
|
||||
## Simple math image plot, showin a 1-channel OpenCV cv::Mat
|
||||
This project (see `./test/jkqtplotter_simpletest_imageplot_opencv/`) simply creates a JKQtPlotter widget (as a new window) and adds a color-coded image plot of a mathematical function (here the Airy disk). The image is generated as an OpenCV cv::Mat image and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore).
|
||||
To copy the data a special OpenCV Interface function `JKQTPdatastore::copyCvMatToColumn()` is used, that copies the data from a cv::Mat directly into a column.
|
||||
|
||||
The function `JKQTPdatastore::copyCvMatToColumn()` is only available, when the preprocessore macro `JKQTPLOTTER_OPENCV_INTERFACE` is defined when compiling the JKQtPlotter library.
|
||||
|
||||
The source code of the main application is (see `./test/jkqtplotter_simpletest_imageplot_opencv/jkqtplotter_simpletest_imageplot_opencv.cpp`):
|
||||
```c++
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/jkqtpimageelements.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
JKQtPlotter plot;
|
||||
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
plot.get_plotter()->set_useAntiAliasingForGraphs(true); // nicer (but slower) plotting
|
||||
plot.get_plotter()->set_useAntiAliasingForSystem(true); // nicer (but slower) plotting
|
||||
plot.get_plotter()->set_useAntiAliasingForText(true); // nicer (but slower) text rendering
|
||||
JKQTPdatastore* ds=plot.getDatastore();
|
||||
|
||||
|
||||
// 2. now we open a BMP-file and load it into an OpenCV cv::Mat
|
||||
cv::Mat picture = cv::imread("example.bmp");
|
||||
|
||||
|
||||
|
||||
// 3. make data available to JKQtPlotter by adding it to the internal datastore.
|
||||
// In this step the contents of each channel of the openCV cv::Mat is copied into a column
|
||||
// of the datastore in row-major order
|
||||
size_t cPictureR=ds->copyCvMatToColumn(picture, "R-channel", 2);
|
||||
size_t cPictureG=ds->copyCvMatToColumn(picture, "G-channel", 1);
|
||||
size_t cPictureB=ds->copyCvMatToColumn(picture, "B-channel", 0);
|
||||
|
||||
|
||||
// 4. create a graph (JKQTPColumnRGBMathImage) with the columns created above as data
|
||||
JKQTPColumnRGBMathImage* graph=new JKQTPColumnRGBMathImage(&plot);
|
||||
graph->set_title("");
|
||||
// set size of the data (the datastore does not contain this info, as it only manages 1D columns of data and this is used to assume a row-major ordering
|
||||
graph->set_Nx(picture.cols);
|
||||
graph->set_Ny(picture.rows);
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->set_x(0);
|
||||
graph->set_y(0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->set_width(picture.cols);
|
||||
graph->set_height(picture.rows);
|
||||
// image column with the data
|
||||
graph->set_imageRColumn(cPictureR);
|
||||
graph->set_imageGColumn(cPictureG);
|
||||
graph->set_imageBColumn(cPictureB);
|
||||
// determine min/max of each channel manually
|
||||
graph->set_imageMinR(0);
|
||||
graph->set_imageMaxR(255);
|
||||
graph->set_imageMinG(0);
|
||||
graph->set_imageMaxG(255);
|
||||
graph->set_imageMinB(0);
|
||||
graph->set_imageMaxB(255);
|
||||
|
||||
|
||||
|
||||
// 5. add the graphs to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
|
||||
// 6. set axis labels
|
||||
plot.get_xAxis()->set_axisLabel("x [pixels]");
|
||||
plot.get_yAxis()->set_axisLabel("y [pixels]");
|
||||
|
||||
// 7. fix axis aspect ratio to width/height, so pixels are square
|
||||
plot.get_plotter()->set_maintainAspectRatio(true);
|
||||
plot.get_plotter()->set_aspectRatio(double(picture.cols)/double(picture.rows));
|
||||
|
||||
// 8. autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(800,600);
|
||||
plot.setWindowTitle("JKQTPColumnMathImage");
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
```
|
||||
The result looks like this:
|
||||
|
||||
![jkqtplotter_simpletest_imageplot](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_rgbimageplot_opencv.png)
|
||||
|
||||
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
BIN
test/jkqtplotter_simpletest_rgbimageplot_opencv/example.bmp
Normal file
BIN
test/jkqtplotter_simpletest_rgbimageplot_opencv/example.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 412 KiB |
@ -0,0 +1,84 @@
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/jkqtpimageelements.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
JKQtPlotter plot;
|
||||
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
plot.get_plotter()->set_useAntiAliasingForGraphs(true); // nicer (but slower) plotting
|
||||
plot.get_plotter()->set_useAntiAliasingForSystem(true); // nicer (but slower) plotting
|
||||
plot.get_plotter()->set_useAntiAliasingForText(true); // nicer (but slower) text rendering
|
||||
JKQTPdatastore* ds=plot.getDatastore();
|
||||
|
||||
|
||||
// 2. now we open a BMP-file and load it into an OpenCV cv::Mat
|
||||
cv::Mat picture = cv::imread("example.bmp");
|
||||
|
||||
|
||||
|
||||
// 3. make data available to JKQtPlotter by adding it to the internal datastore.
|
||||
// In this step the contents of each channel of the openCV cv::Mat is copied into a column
|
||||
// of the datastore in row-major order
|
||||
size_t cPictureR=ds->copyCvMatToColumn(picture, "R-channel", 2);
|
||||
size_t cPictureG=ds->copyCvMatToColumn(picture, "G-channel", 1);
|
||||
size_t cPictureB=ds->copyCvMatToColumn(picture, "B-channel", 0);
|
||||
|
||||
|
||||
// 4. create a graph (JKQTPColumnRGBMathImage) with the columns created above as data
|
||||
JKQTPColumnRGBMathImage* graph=new JKQTPColumnRGBMathImage(&plot);
|
||||
graph->set_title("");
|
||||
// set size of the data (the datastore does not contain this info, as it only manages 1D columns of data and this is used to assume a row-major ordering
|
||||
graph->set_Nx(picture.cols);
|
||||
graph->set_Ny(picture.rows);
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->set_x(0);
|
||||
graph->set_y(0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->set_width(picture.cols);
|
||||
graph->set_height(picture.rows);
|
||||
// image column with the data
|
||||
graph->set_imageRColumn(cPictureR);
|
||||
graph->set_imageGColumn(cPictureG);
|
||||
graph->set_imageBColumn(cPictureB);
|
||||
// determine min/max of each channel manually
|
||||
graph->set_imageMinR(0);
|
||||
graph->set_imageMaxR(255);
|
||||
graph->set_imageMinG(0);
|
||||
graph->set_imageMaxG(255);
|
||||
graph->set_imageMinB(0);
|
||||
graph->set_imageMaxB(255);
|
||||
|
||||
|
||||
|
||||
// 5. add the graphs to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
|
||||
// 6. set axis labels
|
||||
plot.get_xAxis()->set_axisLabel("x [pixels]");
|
||||
plot.get_yAxis()->set_axisLabel("y [pixels]");
|
||||
|
||||
// 7. fix axis aspect ratio to width/height, so pixels are square
|
||||
plot.get_plotter()->set_maintainAspectRatio(true);
|
||||
plot.get_plotter()->set_aspectRatio(double(picture.cols)/double(picture.rows));
|
||||
|
||||
// 8. autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(800,600);
|
||||
plot.setWindowTitle("JKQTPColumnMathImage");
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
# source code for this simple demo
|
||||
SOURCES = jkqtplotter_simpletest_rgbimageplot_opencv.cpp
|
||||
|
||||
# configure Qt
|
||||
CONFIG += qt
|
||||
QT += core gui svg
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
# output executable name
|
||||
TARGET = jkqtplotter_simpletest_rgbimageplot_opencv
|
||||
|
||||
# include JKQtPlotter source code
|
||||
include(../../lib/jkqtplotter.pri)
|
||||
# here you can activate some debug options
|
||||
#DEFINES += SHOW_JKQTPLOTTER_DEBUG
|
||||
#DEFINES += JKQTBP_AUTOTIMER
|
||||
|
||||
|
||||
# link agains OpenCV-3.4.1
|
||||
INCLUDEPATH += $$PWD/OpenCV-3.4.1/include/
|
||||
LIBS += -L$$PWD/OpenCV-3.4.1/bin/ -llibopencv_core341 -llibopencv_imgcodecs341
|
||||
|
||||
# add OpenCV-interface to JKQTPdatastore
|
||||
DEFINES += JKQTPLOTTER_OPENCV_INTERFACE
|
Loading…
Reference in New Issue
Block a user