JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpinterfaceopencv.h
1/*
2 Copyright (c) 2018-2020 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21
22#include "jkqtplotter/jkqtpdatastorage.h"
23#include <opencv2/core.hpp>
24
25#ifndef JKQTPINTERFACEOPENCV_H
26#define JKQTPINTERFACEOPENCV_H
27
28
29/** \brief add one external column to the datastore. It will be filled with the contents of CImg matrix cv::Mat
30 * \ingroup jkqtpinterfaceopencv
31 *
32 * \param datastore the datastore to which the <a href="https://opencv.org/">OpenCV</a> matrix shuld be added (as column)
33 * \param mat <a href="https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html">OpenCV-matrix</a> to store here
34 * \param name name for the column
35 * \param channel to copy from \a mat
36 * \return the ID of the newly created column
37 *
38 * \see \ref jkqtpinterfaceopencv, \ref JKQTPlotterImagePlotOpenCV or \ref JKQTPlotterImagePlotRGBOpenCV for details on how to use this function.
39 */
40inline size_t JKQTPCopyCvMatToColumn(JKQTPDatastore* datastore, const cv::Mat& mat, const QString& name=QString(""), int channel=0);
41
42
43
44
45
46////////////////////////////////////////////////////////////////////////////////////////
48 /** \brief internal helper function for JKQTPCopyCvMatToColumn()
49 * \ingroup jkqtpinterfaceopencv
50 * \internal */
51 template <typename TPixel>
52 inline void copyDataFromMat(double* data, const cv::Mat& mat, int channel) {
53 size_t r=0;
54 const int channels=mat.channels();
55 for (int iy=0; iy<mat.rows; iy++ ) {
56 const TPixel* row=mat.ptr<TPixel>(iy);
57 for (int ix=0; ix<mat.cols; ix++ ) {
58 data[r]=jkqtp_todouble(*static_cast<const TPixel*>(&(row[ix*channels+channel])));
59 r++;
60 }
61 }
62 }
63}
64
65inline size_t JKQTPCopyCvMatToColumn(JKQTPDatastore* datastore, const cv::Mat& mat, const QString &name, int channel)
66{
67 const size_t N=static_cast<size_t>(mat.cols*mat.rows);
68 double* d=static_cast<double*>(malloc(static_cast<size_t>(N)*sizeof(double)));
69
70 if (CV_MAT_DEPTH(mat.type())==CV_64F) JKQTPDatastore_Helper::copyDataFromMat<double>(d, mat, channel);
71 else if (CV_MAT_DEPTH(mat.type())==CV_32F) JKQTPDatastore_Helper::copyDataFromMat<float>(d, mat, channel);
72 else if (CV_MAT_DEPTH(mat.type())==CV_32S) JKQTPDatastore_Helper::copyDataFromMat<uint32_t>(d, mat, channel);
73 else if (CV_MAT_DEPTH(mat.type())==CV_16S) JKQTPDatastore_Helper::copyDataFromMat<int16_t>(d, mat, channel);
74 else if (CV_MAT_DEPTH(mat.type())==CV_16U) JKQTPDatastore_Helper::copyDataFromMat<uint16_t>(d, mat, channel);
75 else if (CV_MAT_DEPTH(mat.type())==CV_8S) JKQTPDatastore_Helper::copyDataFromMat<int8_t>(d, mat, channel);
76 else if (CV_MAT_DEPTH(mat.type())==CV_8U) JKQTPDatastore_Helper::copyDataFromMat<uint8_t>(d, mat, channel);
77 else throw std::runtime_error("datatype of cv::Mat not supported by JKQTPDatastore::copyImageToColumn()");
78
79 return datastore->addInternalImageColumn(d, mat.cols, mat.rows, name);
80}
81
82
83
84#endif // JKQTPINTERFACEOPENCV_H
This class manages data columns (with entries of type double ), used by JKQTPlotter/JKQTBasePlotter t...
Definition jkqtpdatastorage.h:282
size_t addInternalImageColumn(double *data, size_t width, size_t height, const QString &name)
add a column with width * height entries from the array data, ownership of the memory behind data is ...
void copyDataFromMat(double *data, const cv::Mat &mat, int channel)
internal helper function for JKQTPCopyCvMatToColumn()
Definition jkqtpinterfaceopencv.h:52
size_t JKQTPCopyCvMatToColumn(JKQTPDatastore *datastore, const cv::Mat &mat, const QString &name=QString(""), int channel=0)
add one external column to the datastore. It will be filled with the contents of CImg matrix cv::Mat
Definition jkqtpinterfaceopencv.h:65
constexpr double jkqtp_todouble(const T &d)
converts a boolean to a double, is used to convert boolean to double by JKQTPDatastore
Definition jkqtpmathtools.h:113
Definition jkqtpinterfaceopencv.h:47