36 #include <visp3/core/vpConfig.h> 38 #ifdef VISP_HAVE_CATCH2 39 #define CATCH_CONFIG_ENABLE_BENCHMARKING 40 #define CATCH_CONFIG_RUNNER 43 #include <visp3/core/vpIoTools.h> 44 #include <visp3/core/vpImageMorphology.h> 45 #include <visp3/core/vpImageTools.h> 46 #include <visp3/io/vpImageIo.h> 51 TEST_CASE(
"Benchmark binary image morphology",
"[benchmark]") {
58 (
unsigned char)1, (
unsigned char)1,
true);
62 SECTION(
"4-connexity")
65 BENCHMARK(
"Benchmark dilatation (naive code)") {
66 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
67 return I_Klimt_binarized;
70 BENCHMARK(
"Benchmark dilatation (ViSP)") {
72 return I_Klimt_binarized;
76 SECTION(
"8-connexity")
79 BENCHMARK(
"Benchmark dilatation (naive code)") {
80 common_tools::imageDilatationRef(I_Klimt_binarized, connexity);
81 return I_Klimt_binarized;
84 BENCHMARK(
"Benchmark dilatation (ViSP)") {
86 return I_Klimt_binarized;
93 SECTION(
"4-connexity")
96 BENCHMARK(
"Benchmark erosion (naive code)") {
97 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
98 return I_Klimt_binarized;
101 BENCHMARK(
"Benchmark erosion (ViSP)") {
103 return I_Klimt_binarized;
107 SECTION(
"8-connexity")
110 BENCHMARK(
"Benchmark erosion (naive code)") {
111 common_tools::imageErosionRef(I_Klimt_binarized, connexity);
112 return I_Klimt_binarized;
115 BENCHMARK(
"Benchmark erosion (ViSP)") {
117 return I_Klimt_binarized;
123 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 124 TEST_CASE(
"Benchmark gray image morphology",
"[benchmark]") {
129 cv::Mat img, imgMorph;
132 cv::Mat cross_SE = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
133 cv::Mat rect_SE = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
135 SECTION(
"Dilatation")
137 SECTION(
"4-connexity")
140 BENCHMARK(
"Benchmark dilatation (naive code)") {
141 common_tools::imageDilatationRef(I, connexity);
145 BENCHMARK(
"Benchmark dilatation (ViSP)") {
150 BENCHMARK(
"Benchmark dilatation (OpenCV)") {
151 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, cross_SE);
156 SECTION(
"8-connexity")
159 BENCHMARK(
"Benchmark dilatation (naive code)") {
160 common_tools::imageDilatationRef(I, connexity);
164 BENCHMARK(
"Benchmark dilatation (ViSP)") {
169 BENCHMARK(
"Benchmark dilatation (OpenCV)") {
170 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_DILATE, rect_SE);
178 SECTION(
"4-connexity")
181 BENCHMARK(
"Benchmark erosion (naive code)") {
182 common_tools::imageErosionRef(I, connexity);
186 BENCHMARK(
"Benchmark erosion (ViSP)") {
191 BENCHMARK(
"Benchmark dilatation (OpenCV)") {
192 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, cross_SE);
197 SECTION(
"8-connexity")
200 BENCHMARK(
"Benchmark erosion (naive code)") {
201 common_tools::imageErosionRef(I, connexity);
205 BENCHMARK(
"Benchmark erosion (ViSP)") {
210 BENCHMARK(
"Benchmark dilatation (OpenCV)") {
211 cv::morphologyEx(imgMorph, imgMorph, cv::MORPH_ERODE, rect_SE);
219 int main(
int argc,
char *argv[])
221 Catch::Session session;
223 bool runBenchmark =
false;
225 using namespace Catch::clara;
226 auto cli = session.cli()
235 session.applyCommandLine(argc, argv);
238 int numFailed = session.run();
static void dilatation(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void erosion(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
static void read(vpImage< unsigned char > &I, const std::string &filename)