Commit 21cc65fca3f29bdd2d0297bbd9c7ae37a26219a6
1 parent
50d90a53
cleaned up toQImage
Showing
3 changed files
with
13 additions
and
41 deletions
openbr/gui/utility.cpp
| @@ -5,7 +5,9 @@ | @@ -5,7 +5,9 @@ | ||
| 5 | 5 | ||
| 6 | using namespace cv; | 6 | using namespace cv; |
| 7 | 7 | ||
| 8 | -/**** STATIC ****/ | 8 | +namespace br |
| 9 | +{ | ||
| 10 | + | ||
| 9 | QImage toQImage(const Mat &mat) | 11 | QImage toQImage(const Mat &mat) |
| 10 | { | 12 | { |
| 11 | // Convert to 8U depth | 13 | // Convert to 8U depth |
| @@ -44,3 +46,5 @@ QImage toQImage(const Mat &mat) | @@ -44,3 +46,5 @@ QImage toQImage(const Mat &mat) | ||
| 44 | 46 | ||
| 45 | return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); | 47 | return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); |
| 46 | } | 48 | } |
| 49 | + | ||
| 50 | +} // namespace br |
openbr/gui/utility.h
| @@ -3,7 +3,13 @@ | @@ -3,7 +3,13 @@ | ||
| 3 | 3 | ||
| 4 | #include <QImage> | 4 | #include <QImage> |
| 5 | #include <opencv2/core/core.hpp> | 5 | #include <opencv2/core/core.hpp> |
| 6 | +#include <openbr/openbr_export.h> | ||
| 6 | 7 | ||
| 7 | -QImage toQImage(const cv::Mat &mat); | 8 | +namespace br |
| 9 | +{ | ||
| 10 | + | ||
| 11 | +BR_EXPORT QImage toQImage(const cv::Mat &mat); | ||
| 12 | + | ||
| 13 | +} // namespace br | ||
| 8 | 14 | ||
| 9 | #endif // BR_UTILITY_H | 15 | #endif // BR_UTILITY_H |
openbr/plugins/gui.cpp
| @@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
| 13 | 13 | ||
| 14 | #include <opencv2/imgproc/imgproc.hpp> | 14 | #include <opencv2/imgproc/imgproc.hpp> |
| 15 | #include "openbr_internal.h" | 15 | #include "openbr_internal.h" |
| 16 | +#include "openbr/gui/utility.h" | ||
| 16 | 17 | ||
| 17 | using namespace cv; | 18 | using namespace cv; |
| 18 | 19 | ||
| @@ -121,45 +122,6 @@ public slots: | @@ -121,45 +122,6 @@ public slots: | ||
| 121 | } | 122 | } |
| 122 | }; | 123 | }; |
| 123 | 124 | ||
| 124 | -QImage toQImage(const Mat &mat) | ||
| 125 | -{ | ||
| 126 | - // Convert to 8U depth | ||
| 127 | - Mat mat8u; | ||
| 128 | - if (mat.depth() != CV_8U) { | ||
| 129 | - double globalMin = std::numeric_limits<double>::max(); | ||
| 130 | - double globalMax = -std::numeric_limits<double>::max(); | ||
| 131 | - | ||
| 132 | - std::vector<Mat> mv; | ||
| 133 | - split(mat, mv); | ||
| 134 | - for (size_t i=0; i<mv.size(); i++) { | ||
| 135 | - double min, max; | ||
| 136 | - minMaxLoc(mv[i], &min, &max); | ||
| 137 | - globalMin = std::min(globalMin, min); | ||
| 138 | - globalMax = std::max(globalMax, max); | ||
| 139 | - } | ||
| 140 | - assert(globalMax >= globalMin); | ||
| 141 | - | ||
| 142 | - double range = globalMax - globalMin; | ||
| 143 | - if (range != 0) { | ||
| 144 | - double scale = 255 / range; | ||
| 145 | - convertScaleAbs(mat, mat8u, scale, -(globalMin * scale)); | ||
| 146 | - } else { | ||
| 147 | - // Monochromatic | ||
| 148 | - mat8u = Mat(mat.size(), CV_8UC1, Scalar((globalMin+globalMax)/2)); | ||
| 149 | - } | ||
| 150 | - } else { | ||
| 151 | - mat8u = mat; | ||
| 152 | - } | ||
| 153 | - | ||
| 154 | - // Convert to 3 channels | ||
| 155 | - Mat mat8uc3; | ||
| 156 | - if (mat8u.channels() == 4) cvtColor(mat8u, mat8uc3, CV_BGRA2RGB); | ||
| 157 | - else if (mat8u.channels() == 3) cvtColor(mat8u, mat8uc3, CV_BGR2RGB); | ||
| 158 | - else if (mat8u.channels() == 1) cvtColor(mat8u, mat8uc3, CV_GRAY2RGB); | ||
| 159 | - | ||
| 160 | - return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); | ||
| 161 | -} | ||
| 162 | - | ||
| 163 | class DisplayWindow : public QLabel | 125 | class DisplayWindow : public QLabel |
| 164 | { | 126 | { |
| 165 | Q_OBJECT | 127 | Q_OBJECT |