38 #include <visp3/core/vpConfig.h>
40 #if defined(VISP_HAVE_CATCH2)
42 #include <catch_amalgamated.hpp>
45 #include <visp3/core/vpImageMorphology.h>
46 #include <visp3/core/vpImageTools.h>
47 #include <visp3/core/vpIoTools.h>
48 #include <visp3/io/vpImageIo.h>
50 #ifdef ENABLE_VISP_NAMESPACE
55 TEST_CASE(
"Benchmark binary image morphology",
"[benchmark]")
62 vpImageTools::binarise(I_Klimt_binarized, (
unsigned char)127, (
unsigned char)127, (
unsigned char)0, (
unsigned char)1,
63 (
unsigned char)1,
true);
67 SECTION(
"4-connexity")
70 BENCHMARK(
"Benchmark dilatation (naive code)")
72 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
73 return I_Klimt_binarized;
76 BENCHMARK(
"Benchmark dilatation (ViSP)")
79 return I_Klimt_binarized;
83 SECTION(
"8-connexity")
86 BENCHMARK(
"Benchmark dilatation (naive code)")
88 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
89 return I_Klimt_binarized;
92 BENCHMARK(
"Benchmark dilatation (ViSP)")
95 return I_Klimt_binarized;
102 SECTION(
"4-connexity")
105 BENCHMARK(
"Benchmark erosion (naive code)")
107 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
108 return I_Klimt_binarized;
111 BENCHMARK(
"Benchmark erosion (ViSP)")
114 return I_Klimt_binarized;
118 SECTION(
"8-connexity")
121 BENCHMARK(
"Benchmark erosion (naive code)")
123 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
124 return I_Klimt_binarized;
127 BENCHMARK(
"Benchmark erosion (ViSP)")
130 return I_Klimt_binarized;
136 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
137 TEST_CASE(
"Benchmark gray image morphology",
"[benchmark]")
143 cv::Mat img, imgMorph;
146 cv::Mat cross_SE = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
147 cv::Mat rect_SE = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
149 SECTION(
"Dilatation")
151 SECTION(
"4-connexity")
154 BENCHMARK(
"Benchmark dilatation (naive code)")
156 common_tools::imageDilatationRef(I, connexity);
160 BENCHMARK(
"Benchmark dilatation (ViSP)")
162 vpImageMorphology::dilatation<unsigned char>(I, connexity);
166 BENCHMARK(
"Benchmark dilatation (OpenCV)")
168 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, cross_SE);
173 SECTION(
"8-connexity")
176 BENCHMARK(
"Benchmark dilatation (naive code)")
178 common_tools::imageDilatationRef(I, connexity);
182 BENCHMARK(
"Benchmark dilatation (ViSP)")
184 vpImageMorphology::dilatation<unsigned char>(I, connexity);
188 BENCHMARK(
"Benchmark dilatation (OpenCV)")
190 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, rect_SE);
198 SECTION(
"4-connexity")
201 BENCHMARK(
"Benchmark erosion (naive code)")
203 common_tools::imageErosionRef(I, connexity);
207 BENCHMARK(
"Benchmark erosion (ViSP)")
209 vpImageMorphology::erosion<unsigned char>(I, connexity);
213 BENCHMARK(
"Benchmark dilatation (OpenCV)")
215 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, cross_SE);
220 SECTION(
"8-connexity")
223 BENCHMARK(
"Benchmark erosion (naive code)")
225 common_tools::imageErosionRef(I, connexity);
229 BENCHMARK(
"Benchmark erosion (ViSP)")
231 vpImageMorphology::erosion<unsigned char>(I, connexity);
235 BENCHMARK(
"Benchmark dilatation (OpenCV)")
237 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, rect_SE);
245 int main(
int argc,
char *argv[])
247 Catch::Session session;
249 bool runBenchmark =
false;
250 auto cli = session.cli()
251 | Catch::Clara::Opt(runBenchmark)[
"--benchmark"](
"run benchmark?");
254 session.applyCommandLine(argc, argv);
257 int numFailed = session.run();
267 int main() {
return EXIT_SUCCESS; }
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void dilatation(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
static void erosion(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)