-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PerfectMemory: Accept non-uint8 images as inputs
- Loading branch information
Showing
4 changed files
with
117 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
// OpenCV | ||
#include <opencv2/opencv.hpp> | ||
|
||
namespace BoBRobotics { | ||
namespace ImgProc { | ||
void | ||
convertScale(const cv::Mat &in, cv::Mat &out, int targetType); | ||
} // ImgProc | ||
} // BoBRobotics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// BoB robotics includes | ||
#include "common/macros.h" | ||
#include "imgproc/convert_scale.h" | ||
|
||
// Standard C++ includes | ||
#include <limits> | ||
#include <stdexcept> | ||
#include <type_traits> | ||
|
||
// Standard C includes | ||
#include <cstdint> | ||
|
||
// Anonymous namespace | ||
namespace { | ||
template<class T, typename = void> | ||
struct ImageMax; | ||
|
||
template<class T> | ||
struct ImageMax<T, std::enable_if_t<std::is_unsigned<T>::value>> { | ||
static constexpr T value = std::numeric_limits<T>::max(); | ||
}; | ||
|
||
template<class T> | ||
struct ImageMax<T, std::enable_if_t<std::is_floating_point<T>::value>> { | ||
static constexpr T value{ 1 }; | ||
}; | ||
|
||
#define BOB_GET_MAX(TYPE) \ | ||
case cv::DataType<TYPE>::type: \ | ||
return ImageMax<TYPE>::value | ||
|
||
inline double | ||
getMax(int type) | ||
{ | ||
switch (type) { | ||
BOB_GET_MAX(uchar); | ||
BOB_GET_MAX(uint16_t); | ||
BOB_GET_MAX(float); | ||
BOB_GET_MAX(double); | ||
default: | ||
throw std::invalid_argument("Unsupported matrix type"); | ||
} | ||
} | ||
} | ||
|
||
namespace BoBRobotics { | ||
namespace ImgProc { | ||
void | ||
convertScale(const cv::Mat &in, cv::Mat &out, int targetType) | ||
{ | ||
BOB_ASSERT(in.channels() == 1); | ||
|
||
if (in.type() == targetType) { | ||
out = in; | ||
return; | ||
} | ||
|
||
in.convertTo(out, targetType, getMax(targetType) / getMax(in.type())); | ||
} | ||
|
||
} // ImgProc | ||
} // BoBRobotics |