41#include <visp3/core/vpConfig.h>
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
66template<
bool useFullScale >
71 if ((hsv_computed.
H != hsv_truth.
H) ||
72 (hsv_computed.
S != hsv_truth.
S) ||
73 (hsv_computed.
V != hsv_truth.
V)) {
75 std::cout <<
"Expected hsv value: ("
76 <<
static_cast<int>(hsv_truth.
H) <<
","
77 <<
static_cast<int>(hsv_truth.
S) <<
","
78 <<
static_cast<int>(hsv_truth.
V) <<
") converted value: ("
79 <<
static_cast<int>(hsv_computed.
H) <<
","
80 <<
static_cast<int>(hsv_computed.
S) <<
","
81 <<
static_cast<int>(hsv_computed.
V) <<
")" << std::endl;
99template<
typename Type,
bool useFullScale >
108 std::cout <<
"Expected hsv value: ("
109 <<
static_cast<int>(hsv_truth.
H) <<
","
110 <<
static_cast<int>(hsv_truth.
S) <<
","
111 <<
static_cast<int>(hsv_truth.
V) <<
") converted value: ("
112 <<
static_cast<int>(hsv_computed.
H) <<
","
113 <<
static_cast<int>(hsv_computed.
S) <<
","
114 <<
static_cast<int>(hsv_computed.
V) <<
")" << std::endl;
124 bool isSuccess =
true;
126 std::cout << std::endl <<
"----- Testing single pixel HSV to HSV conversions -----" << std::endl;
140 isSuccess = isSuccess && test_hsv(hsvfucf,
vpHSV<float>(1., 1., 1.));
143 isSuccess = isSuccess && test_hsv(hsvfuct,
vpHSV<float>(1., 1., 1.));
146 isSuccess = isSuccess && test_hsv(hsvducf,
vpHSV<double>(1., 1., 1.));
149 isSuccess = isSuccess && test_hsv(hsvduct,
vpHSV<double>(1., 1., 1.));
151 std::cout << std::endl <<
"----- Testing vpImageConvert(HSV, HSV) conversions -----" << std::endl;
153 std::cout << std::endl <<
"\t UCHAR -> floating types" << std::endl;
157 bool localSuccess = vpHSVTests::areAlmostEqual(Ihff,
"Ihff", Ihff_truth,
"Ihff_truth");
159 std::cerr <<
"vpImageConvert(HSV<uchar, false>, HSV<float>) failed!" << std::endl;
161 isSuccess = isSuccess && localSuccess;
166 localSuccess = vpHSVTests::areAlmostEqual(Ihft,
"Ihft", Ihft_truth,
"Ihft_truth");
168 std::cerr <<
"vpImageConvert(HSV<uchar, true>, HSV<float>) failed!" << std::endl;
170 isSuccess = isSuccess && localSuccess;
174 localSuccess = vpHSVTests::areAlmostEqual(Ihdf,
"Ihdf", Ihdf_truth,
"Ihdf_truth");
176 std::cerr <<
"vpImageConvert(HSV<uchar, false>, HSV<double>) failed!" << std::endl;
178 isSuccess = isSuccess && localSuccess;
182 localSuccess = vpHSVTests::areAlmostEqual(Ihdt,
"Ihdt", Ihdt_truth,
"Ihdt_truth");
184 std::cerr <<
"vpImageConvert(HSV<uchar, true>, HSV<double>) failed!" << std::endl;
186 isSuccess = isSuccess && localSuccess;
190 std::cout << std::endl <<
"\t floating types -> UCHAR" << std::endl;
194 bool localSuccess = vpHSVTests::areAlmostEqual(Iucf,
"Iucf", Iucf_truth,
"Iucf_truth");
196 std::cerr <<
"vpImageConvert(HSV<float>, HSV<uchar, false>) failed!" << std::endl;
198 isSuccess = isSuccess && localSuccess;
203 localSuccess = vpHSVTests::areAlmostEqual(Iuct,
"Iuct", Iuct_truth,
"Iuct_truth");
205 std::cerr <<
"vpImageConvert(HSV<float>, HSV<uchar, true>) failed!" << std::endl;
207 isSuccess = isSuccess && localSuccess;
211 localSuccess = vpHSVTests::areAlmostEqual(Iucf,
"Iucf", Iucf_truth,
"Iucf_truth");
213 std::cerr <<
"vpImageConvert(HSV<double>, HSV<uchar, false>) failed!" << std::endl;
215 isSuccess = isSuccess && localSuccess;
219 localSuccess = vpHSVTests::areAlmostEqual(Iuct,
"Iuct", Iuct_truth,
"Iuct_truth");
221 std::cerr <<
"vpImageConvert(HSV<double>, HSV<uchar, true>) failed!" << std::endl;
223 isSuccess = isSuccess && localSuccess;
227 std::cout << std::endl <<
"\t floating types -> floating types" << std::endl;
231 bool localSuccess = vpHSVTests::areAlmostEqual(Idouble,
"Idouble", Idouble_truth,
"Idouble_truth");
233 std::cerr <<
"vpImageConvert(HSV<float>, HSV<double>) failed!" << std::endl;
235 isSuccess = isSuccess && localSuccess;
239 localSuccess = vpHSVTests::areAlmostEqual(Ifloat,
"Ifloat", Ifloat_truth,
"Ifloat_truth");
241 std::cerr <<
"vpImageConvert(HSV<double>, HSV<float>) failed!" << std::endl;
243 isSuccess = isSuccess && localSuccess;
247 std::cout <<
"All tests were successful !" << std::endl;
250 std::cerr <<
"ERROR: Something went wrong !" << std::endl;
257 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)