Skip to content
Snippets Groups Projects
OpenCVFilter2DBenchmark.cpp 1.71 KiB
Newer Older
zhanghb97's avatar
zhanghb97 committed
//===- OpenCVFilter2DBenchmark.cpp ----------------------------------------===//
zhanghb97's avatar
zhanghb97 committed
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
//
// This file implements the benchmark for OpenCV filter2D.
zhanghb97's avatar
zhanghb97 committed
//
//===----------------------------------------------------------------------===//

#include "ImageProcessing/Kernels.h"
#include <benchmark/benchmark.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

// Declare input image, kernel and output image.
Mat inputImageFilter2D, kernelFilter2D, outputFilter2D;
zhanghb97's avatar
zhanghb97 committed

zhanghb97's avatar
zhanghb97 committed
void initializeOpenCVFilter2D(int argc, char **argv) {
  inputImageFilter2D = imread(argv[1], IMREAD_GRAYSCALE);

  kernelFilter2D = Mat(get<1>(kernelMap[argv[2]]), get<2>(kernelMap[argv[2]]),
                       CV_32FC1, get<0>(kernelMap[argv[2]]));
}
zhanghb97's avatar
zhanghb97 committed

// Benchmarking function.
zhanghb97's avatar
zhanghb97 committed
static void OpenCV_Filter2D(benchmark::State &state) {
zhanghb97's avatar
zhanghb97 committed
  for (auto _ : state) {
    for (int i = 0; i < state.range(0); ++i) {
      filter2D(inputImageFilter2D, outputFilter2D, CV_32FC1, kernelFilter2D,
               cv::Point(-1, -1), 0.0, cv::BORDER_CONSTANT);
zhanghb97's avatar
zhanghb97 committed
    }
  }
}

// Register benchmarking function.
zhanghb97's avatar
zhanghb97 committed
BENCHMARK(OpenCV_Filter2D)->Arg(1);