36 #include <visp3/core/vpConfig.h>
38 #ifdef VISP_HAVE_CATCH2
39 #define CATCH_CONFIG_ENABLE_BENCHMARKING
40 #define CATCH_CONFIG_RUNNER
44 #include <visp3/core/vpImageMorphology.h>
45 #include <visp3/core/vpImageTools.h>
46 #include <visp3/core/vpIoTools.h>
47 #include <visp3/io/vpImageIo.h>
51 TEST_CASE(
"Benchmark binary image morphology",
"[benchmark]")
58 vpImageTools::binarise(I_Klimt_binarized, (
unsigned char)127, (
unsigned char)127, (
unsigned char)0, (
unsigned char)1,
59 (
unsigned char)1,
true);
63 SECTION(
"4-connexity")
66 BENCHMARK(
"Benchmark dilatation (naive code)")
68 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
69 return I_Klimt_binarized;
72 BENCHMARK(
"Benchmark dilatation (ViSP)")
75 return I_Klimt_binarized;
79 SECTION(
"8-connexity")
82 BENCHMARK(
"Benchmark dilatation (naive code)")
84 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
85 return I_Klimt_binarized;
88 BENCHMARK(
"Benchmark dilatation (ViSP)")
91 return I_Klimt_binarized;
98 SECTION(
"4-connexity")
101 BENCHMARK(
"Benchmark erosion (naive code)")
103 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
104 return I_Klimt_binarized;
107 BENCHMARK(
"Benchmark erosion (ViSP)")
110 return I_Klimt_binarized;
114 SECTION(
"8-connexity")
117 BENCHMARK(
"Benchmark erosion (naive code)")
119 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
120 return I_Klimt_binarized;
123 BENCHMARK(
"Benchmark erosion (ViSP)")
126 return I_Klimt_binarized;
132 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
133 TEST_CASE(
"Benchmark gray image morphology",
"[benchmark]")
139 cv::Mat img, imgMorph;
142 cv::Mat cross_SE = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
143 cv::Mat rect_SE = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
145 SECTION(
"Dilatation")
147 SECTION(
"4-connexity")
150 BENCHMARK(
"Benchmark dilatation (naive code)")
152 common_tools::imageDilatationRef(I, connexity);
156 BENCHMARK(
"Benchmark dilatation (ViSP)")
158 vpImageMorphology::dilatation<unsigned char>(I, connexity);
162 BENCHMARK(
"Benchmark dilatation (OpenCV)")
164 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, cross_SE);
169 SECTION(
"8-connexity")
172 BENCHMARK(
"Benchmark dilatation (naive code)")
174 common_tools::imageDilatationRef(I, connexity);
178 BENCHMARK(
"Benchmark dilatation (ViSP)")
180 vpImageMorphology::dilatation<unsigned char>(I, connexity);
184 BENCHMARK(
"Benchmark dilatation (OpenCV)")
186 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, rect_SE);
194 SECTION(
"4-connexity")
197 BENCHMARK(
"Benchmark erosion (naive code)")
199 common_tools::imageErosionRef(I, connexity);
203 BENCHMARK(
"Benchmark erosion (ViSP)")
205 vpImageMorphology::erosion<unsigned char>(I, connexity);
209 BENCHMARK(
"Benchmark dilatation (OpenCV)")
211 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, cross_SE);
216 SECTION(
"8-connexity")
219 BENCHMARK(
"Benchmark erosion (naive code)")
221 common_tools::imageErosionRef(I, connexity);
225 BENCHMARK(
"Benchmark erosion (ViSP)")
227 vpImageMorphology::erosion<unsigned char>(I, connexity);
231 BENCHMARK(
"Benchmark dilatation (OpenCV)")
233 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, rect_SE);
241 int main(
int argc,
char *argv [])
243 Catch::Session session;
245 bool runBenchmark =
false;
247 using namespace Catch::clara;
248 auto cli = session.cli()
257 session.applyCommandLine(argc, argv);
260 int numFailed = session.run();
273 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)