42#include <visp3/core/vpImage.h>
43#include <visp3/core/vpImageConvert.h>
44#include <visp3/core/vpRGBa.h>
45#include <visp3/core/vpHSV.h>
49#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
51#ifdef ENABLE_VISP_NAMESPACE
55#ifndef DOXYGEN_SHOULD_SKIP_THIS
68template<
typename Type,
bool useFullScale >
77 std::cout << static_cast<int>(rgb_truth.
R) <<
","
78 <<
static_cast<int>(rgb_truth.
G) <<
","
79 <<
static_cast<int>(rgb_truth.
B) <<
"): Expected hsv value: ("
80 <<
static_cast<int>(hsv_truth.
H) <<
","
81 <<
static_cast<int>(hsv_truth.
S) <<
","
82 <<
static_cast<int>(hsv_truth.
V) <<
") converted value: ("
83 <<
static_cast<int>(hsv_computed.
H) <<
","
84 <<
static_cast<int>(hsv_computed.
S) <<
","
85 <<
static_cast<int>(hsv_computed.
V) <<
")" << std::endl;
95 bool isSuccess =
true;
97 std::vector< vpColVector > rgb_truth;
116 size_t size = rgb_truth.size();
118 for (
size_t test = 0; test < 2; ++test) {
129 std::vector< vpColVector > hsv_truth;
130 hsv_truth.emplace_back(std::vector<double>({ 0., 0., 0. }));
131 hsv_truth.emplace_back(std::vector<double>({ 0., 0., 255. }));
132 hsv_truth.emplace_back(std::vector<double>({ 0., 255., 255. }));
133 hsv_truth.emplace_back(std::vector<double>({ h_max * 120. / 360., 255., 255. }));
134 hsv_truth.emplace_back(std::vector<double>({ h_max * 240. / 360., 255., 255. }));
135 hsv_truth.emplace_back(std::vector<double>({ h_max * 60. / 360., 255., 255. }));
136 hsv_truth.emplace_back(std::vector<double>({ h_max * 180. / 360., 255., 255. }));
137 hsv_truth.emplace_back(std::vector<double>({ h_max * 300. / 360., 255., 255. }));
138 hsv_truth.emplace_back(std::vector<double>({ 0., 0., 128. }));
139 hsv_truth.emplace_back(std::vector<double>({ h_max * 60. / 360., 255., 128. }));
140 hsv_truth.emplace_back(std::vector<double>({ 0., 255., 128. }));
141 hsv_truth.emplace_back(std::vector<double>({ h_max * 120. / 360., 255., 128. }));
142 hsv_truth.emplace_back(std::vector<double>({ h_max * 180. / 360., 255., 128. }));
143 hsv_truth.emplace_back(std::vector<double>({ h_max * 240. / 360., 255., 128. }));
144 hsv_truth.emplace_back(std::vector<double>({ h_max * 300. / 360., 255., 128. }));
147 std::cout << std::endl <<
"----- Test rgba -> hsv (unsigned char) conversion with h full scale: " << (h_full ?
"yes" :
"no") <<
" -----" << std::endl;
148 for (
unsigned int id = 0;
id < size; ++id) {
149 vpRGBa rgba(rgb_truth[
id]);
165 std::cout << std::endl <<
"----- Test rgb -> hsv (double) conversion -----" << std::endl;
166 for (
unsigned int id = 0;
id < size; ++id) {
167 vpRGBa rgba(rgb_truth[
id]);
169 for (
unsigned char c = 0; c < vpHSV<double>::nbChannels; ++c) {
170 hsv_truth[id][c] = hsv_truth[id][c] / 255.;
172 isSuccess = isSuccess && test_hsv(hsv, rgba,
vpHSV<double>(hsv_truth[
id]));
177 std::cout << std::endl <<
"----- Testing vpImageConvert::convert(vpImage<vpRGBa>, vpImage<vpHSV>) conversions -----" << std::endl;
186 bool localSuccess = vpHSVTests::areAlmostEqual(Ihsvucf,
"Ihsvucf", Ihsvucf_truth,
"Ihsvucf_truth", 1.0);
188 std::cerr <<
"vpImageConvert(rgba, hsv<uchar, false>) failed!" << std::endl;
190 isSuccess = isSuccess && localSuccess;
192 localSuccess = vpHSVTests::areAlmostEqual(Ihsvuct,
"Ihsvuct", Ihsvuct_truth,
"Ihsvuct_truth", 1.0);
194 std::cerr <<
"vpImageConvert(rgba, hsv<uchar, true>) failed!" << std::endl;
196 isSuccess = isSuccess && localSuccess;
198 localSuccess = vpHSVTests::areAlmostEqual(Ihsvd,
"Ihsvd", Ihsvd_truth,
"Ihsvd_truth");
200 std::cerr <<
"vpImageConvert(rgba, hsv<double>) failed!" << std::endl;
202 isSuccess = isSuccess && localSuccess;
205 std::cout <<
"All tests were successful !" << std::endl;
208 std::cerr <<
"ERROR: Something went wrong !" << std::endl;
215 std::cout <<
"vpHSV class is not available, please use CXX 11 standard" << std::endl;
Class implementing the HSV pixel format.
static constexpr unsigned char maxHueUsingLimitedRange
Maximum value of the Hue channel when using unsigned char and the limited range.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
static bool equal(double x, double y, double threshold=0.001)
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.