38 #include <visp3/core/vpConfig.h>
40 #ifdef VISP_HAVE_CATCH2
41 #define CATCH_CONFIG_ENABLE_BENCHMARKING
42 #define CATCH_CONFIG_RUNNER
46 #include <visp3/core/vpImageMorphology.h>
47 #include <visp3/core/vpImageTools.h>
48 #include <visp3/core/vpIoTools.h>
49 #include <visp3/io/vpImageIo.h>
51 #ifdef ENABLE_VISP_NAMESPACE
56 TEST_CASE(
"Benchmark binary image morphology",
"[benchmark]")
63 vpImageTools::binarise(I_Klimt_binarized, (
unsigned char)127, (
unsigned char)127, (
unsigned char)0, (
unsigned char)1,
64 (
unsigned char)1,
true);
68 SECTION(
"4-connexity")
71 BENCHMARK(
"Benchmark dilatation (naive code)")
73 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
74 return I_Klimt_binarized;
77 BENCHMARK(
"Benchmark dilatation (ViSP)")
80 return I_Klimt_binarized;
84 SECTION(
"8-connexity")
87 BENCHMARK(
"Benchmark dilatation (naive code)")
89 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
90 return I_Klimt_binarized;
93 BENCHMARK(
"Benchmark dilatation (ViSP)")
96 return I_Klimt_binarized;
103 SECTION(
"4-connexity")
106 BENCHMARK(
"Benchmark erosion (naive code)")
108 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
109 return I_Klimt_binarized;
112 BENCHMARK(
"Benchmark erosion (ViSP)")
115 return I_Klimt_binarized;
119 SECTION(
"8-connexity")
122 BENCHMARK(
"Benchmark erosion (naive code)")
124 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
125 return I_Klimt_binarized;
128 BENCHMARK(
"Benchmark erosion (ViSP)")
131 return I_Klimt_binarized;
137 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
138 TEST_CASE(
"Benchmark gray image morphology",
"[benchmark]")
144 cv::Mat img, imgMorph;
147 cv::Mat cross_SE = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
148 cv::Mat rect_SE = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
150 SECTION(
"Dilatation")
152 SECTION(
"4-connexity")
155 BENCHMARK(
"Benchmark dilatation (naive code)")
157 common_tools::imageDilatationRef(I, connexity);
161 BENCHMARK(
"Benchmark dilatation (ViSP)")
163 vpImageMorphology::dilatation<unsigned char>(I, connexity);
167 BENCHMARK(
"Benchmark dilatation (OpenCV)")
169 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, cross_SE);
174 SECTION(
"8-connexity")
177 BENCHMARK(
"Benchmark dilatation (naive code)")
179 common_tools::imageDilatationRef(I, connexity);
183 BENCHMARK(
"Benchmark dilatation (ViSP)")
185 vpImageMorphology::dilatation<unsigned char>(I, connexity);
189 BENCHMARK(
"Benchmark dilatation (OpenCV)")
191 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, rect_SE);
199 SECTION(
"4-connexity")
202 BENCHMARK(
"Benchmark erosion (naive code)")
204 common_tools::imageErosionRef(I, connexity);
208 BENCHMARK(
"Benchmark erosion (ViSP)")
210 vpImageMorphology::erosion<unsigned char>(I, connexity);
214 BENCHMARK(
"Benchmark dilatation (OpenCV)")
216 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, cross_SE);
221 SECTION(
"8-connexity")
224 BENCHMARK(
"Benchmark erosion (naive code)")
226 common_tools::imageErosionRef(I, connexity);
230 BENCHMARK(
"Benchmark erosion (ViSP)")
232 vpImageMorphology::erosion<unsigned char>(I, connexity);
236 BENCHMARK(
"Benchmark dilatation (OpenCV)")
238 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, rect_SE);
246 int main(
int argc,
char *argv[])
248 Catch::Session session;
250 bool runBenchmark =
false;
252 using namespace Catch::clara;
253 auto cli = session.cli()
262 session.applyCommandLine(argc, argv);
265 int numFailed = session.run();
278 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)