/* Copyright (c) 2018-2019 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ /** \file jkqtpopencvinterface.h * \ingroup jkqtpopencvinterface */ #include "jkqtplottertools/jkqtp_imexport.h" #include "jkqtplotter/jkqtpdatastore.h" #include #ifndef JKQTPOPENCVINTERFACE_H #define JKQTPOPENCVINTERFACE_H /** \brief add one external column to the datastore. It will be filled with the contents of vector \a data. * \ingroup jkqtpopencvinterface * * \param datastore the datastore to which the OpenCV matrix shuld be added (as column) * \param mat OpenCV-matrix to store here * \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. */ inline size_t JKQTPCopyCvMatToColumn(JKQTPDatastore* datastore, const cv::Mat& mat, const QString& name=QString(""), int channel=0); //////////////////////////////////////////////////////////////////////////////////////// namespace JKQTPDatastore_Helper { /** \brief internal helper function for JKQTPCopyCvMatToColumn() * \ingroup jkqtpopencvinterface * \internal */ template inline void copyDataFromMat(double* data, const cv::Mat& mat, int channel) { size_t r=0; const int channels=mat.channels(); for (int iy=0; iy(iy); for (int ix=0; ix(&(row[ix*channels+channel]))); r++; } } } } inline size_t JKQTPCopyCvMatToColumn(JKQTPDatastore* datastore, const cv::Mat& mat, const QString &name, int channel) { const size_t N=static_cast(mat.cols*mat.rows); double* d=static_cast(malloc(static_cast(N)*sizeof(double))); if (CV_MAT_DEPTH(mat.type())==CV_64F) JKQTPDatastore_Helper::copyDataFromMat(d, mat, channel); else if (CV_MAT_DEPTH(mat.type())==CV_32F) JKQTPDatastore_Helper::copyDataFromMat(d, mat, channel); else if (CV_MAT_DEPTH(mat.type())==CV_32S) JKQTPDatastore_Helper::copyDataFromMat(d, mat, channel); else if (CV_MAT_DEPTH(mat.type())==CV_16S) JKQTPDatastore_Helper::copyDataFromMat(d, mat, channel); else if (CV_MAT_DEPTH(mat.type())==CV_16U) JKQTPDatastore_Helper::copyDataFromMat(d, mat, channel); else if (CV_MAT_DEPTH(mat.type())==CV_8S) JKQTPDatastore_Helper::copyDataFromMat(d, mat, channel); else if (CV_MAT_DEPTH(mat.type())==CV_8U) JKQTPDatastore_Helper::copyDataFromMat(d, mat, channel); else throw std::runtime_error("datatype of cv::Mat not supported by JKQTPDatastore::copyImageToColumn()"); size_t itemid=datastore->addInternalItem(d, N); return datastore->addColumnForItem(itemid, 0, name); } #endif // JKQTPOPENCVINTERFACE_H