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/io/vpImageIo.h> 49 void computeRegularRGBaToGrayscale(
const unsigned char * rgba,
unsigned char *grey,
unsigned int size)
51 const unsigned char *pt_input = rgba;
52 const unsigned char *pt_end = rgba + size * 4;
53 unsigned char *pt_output = grey;
55 while (pt_input != pt_end) {
56 *pt_output = (
unsigned char)(0.2126 * (*pt_input) + 0.7152 * (*(pt_input + 1)) + 0.0722 * (*(pt_input + 2)));
62 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 63 void computeRegularBGRToGrayscale(
unsigned char *bgr,
unsigned char *grey,
unsigned int width,
64 unsigned int height,
bool flip=
false)
68 int lineStep = (flip) ? -(
int)(width * 3) : (
int)(width * 3);
71 unsigned char *src = (flip) ? bgr + (width * height * 3) + lineStep : bgr;
76 for (i = 0; i < height; i++) {
77 unsigned char *line = src;
78 for (j = 0; j < width; j++) {
79 *grey++ = (
unsigned char)(0.2126 * *(line + 2) + 0.7152 * *(line + 1) + 0.0722 * *(line + 0));
90 TEST_CASE(
"Benchmark rgba to grayscale (naive code)",
"[benchmark]") {
97 BENCHMARK(
"Benchmark rgba to grayscale Klimt (naive code)") {
98 computeRegularRGBaToGrayscale(reinterpret_cast<unsigned char *>(I.
bitmap),
104 TEST_CASE(
"Benchmark rgba to grayscale (ViSP)",
"[benchmark]") {
111 BENCHMARK(
"Benchmark rgba to grayscale Klimt (ViSP)") {
117 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 118 TEST_CASE(
"Benchmark bgr to grayscale (naive code)",
"[benchmark]") {
120 cv::Mat img = cv::imread(imagePath);
124 BENCHMARK(
"Benchmark bgr to grayscale (naive code)") {
125 computeRegularBGRToGrayscale(reinterpret_cast<unsigned char*>(img.ptr<uchar>()),
126 reinterpret_cast<unsigned char *>(I_gray.bitmap),
127 I_gray.getWidth(), I_gray.getHeight());
132 TEST_CASE(
"Benchmark bgr to grayscale (ViSP)",
"[benchmark]") {
134 cv::Mat img = cv::imread(imagePath);
136 std::vector<unsigned char> grayscale(img.rows*img.cols);
138 BENCHMARK(
"Benchmark bgr to grayscale (ViSP)") {
140 grayscale.data(), img.cols, img.rows);
145 TEST_CASE(
"Benchmark bgr to grayscale (OpenCV)",
"[benchmark]") {
147 cv::Mat img = cv::imread(imagePath);
148 cv::Mat img_gray(img.size(), CV_8UC1);
150 BENCHMARK(
"Benchmark bgr to grayscale (OpenCV)") {
151 cv::cvtColor(img, img_gray, cv::COLOR_BGR2GRAY);
157 int main(
int argc,
char *argv[])
159 Catch::Session session;
161 bool runBenchmark =
false;
163 using namespace Catch::clara;
164 auto cli = session.cli()
173 session.applyCommandLine(argc, argv);
176 int numFailed = session.run();
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getSize() const
unsigned int getWidth() const