diff --git a/openbr/gui/utility.cpp b/openbr/gui/utility.cpp index ff30e33..a675cb5 100644 --- a/openbr/gui/utility.cpp +++ b/openbr/gui/utility.cpp @@ -5,7 +5,9 @@ using namespace cv; -/**** STATIC ****/ +namespace br +{ + QImage toQImage(const Mat &mat) { // Convert to 8U depth @@ -44,3 +46,5 @@ QImage toQImage(const Mat &mat) return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); } + +} // namespace br diff --git a/openbr/gui/utility.h b/openbr/gui/utility.h index f4c3d60..da5a147 100644 --- a/openbr/gui/utility.h +++ b/openbr/gui/utility.h @@ -3,7 +3,13 @@ #include #include +#include -QImage toQImage(const cv::Mat &mat); +namespace br +{ + +BR_EXPORT QImage toQImage(const cv::Mat &mat); + +} // namespace br #endif // BR_UTILITY_H diff --git a/openbr/plugins/gui.cpp b/openbr/plugins/gui.cpp index d3af3b2..6d82687 100644 --- a/openbr/plugins/gui.cpp +++ b/openbr/plugins/gui.cpp @@ -13,6 +13,7 @@ #include #include "openbr_internal.h" +#include "openbr/gui/utility.h" using namespace cv; @@ -121,45 +122,6 @@ public slots: } }; -QImage toQImage(const Mat &mat) -{ - // Convert to 8U depth - Mat mat8u; - if (mat.depth() != CV_8U) { - double globalMin = std::numeric_limits::max(); - double globalMax = -std::numeric_limits::max(); - - std::vector mv; - split(mat, mv); - for (size_t i=0; i= globalMin); - - double range = globalMax - globalMin; - if (range != 0) { - double scale = 255 / range; - convertScaleAbs(mat, mat8u, scale, -(globalMin * scale)); - } else { - // Monochromatic - mat8u = Mat(mat.size(), CV_8UC1, Scalar((globalMin+globalMax)/2)); - } - } else { - mat8u = mat; - } - - // Convert to 3 channels - Mat mat8uc3; - if (mat8u.channels() == 4) cvtColor(mat8u, mat8uc3, CV_BGRA2RGB); - else if (mat8u.channels() == 3) cvtColor(mat8u, mat8uc3, CV_BGR2RGB); - else if (mat8u.channels() == 1) cvtColor(mat8u, mat8uc3, CV_GRAY2RGB); - - return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); -} - class DisplayWindow : public QLabel { Q_OBJECT