From f60ffee0bb3e13e11adeac97b638f2f6be648f4e Mon Sep 17 00:00:00 2001 From: Dmitry Kokorin Date: Wed, 5 Sep 2018 23:37:37 +0300 Subject: [PATCH] cleanup --- CMakeLists.txt | 8 +++----- integral_image.h | 4 ++++ main.cpp | 19 +++++++++---------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76d5eea..f7a738c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,15 @@ cmake_minimum_required(VERSION 2.8) set(PROJECT "integral_image") -set(PROJECT_TESTS tests) +set(PROJECT_TESTS ${PROJECT}_tests) include(CTest) find_package(OpenCV REQUIRED) find_package(OpenMP REQUIRED) -if (OPENMP_FOUND) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") -endif() +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(SOURCES diff --git a/integral_image.h b/integral_image.h index 754dfaf..f121857 100644 --- a/integral_image.h +++ b/integral_image.h @@ -12,6 +12,10 @@ namespace integral_image { +//TODO: The algorithms do not require the data to be of 'double' type. +//Consider to turn functions into template functions. + + using Mat = cv::Mat_; //! A reference serial implementation of the integral image algorithm. diff --git a/main.cpp b/main.cpp index f40ab38..c5139fc 100644 --- a/main.cpp +++ b/main.cpp @@ -10,7 +10,6 @@ #include "integral_image.h" - namespace { @@ -64,7 +63,7 @@ Arguments parse_arguments(int argc, char **argv) std::ostream &operator<<(std::ostream &os, const integral_image::Mat &mat) { //The specification doesn't require any precision or data presentation format, - //so here we use a default one + //so here we use default ones if (mat.data) { @@ -107,7 +106,7 @@ int main(int argc, char **argv) mat.release(); - auto output_file_name = file_name + OUTPUT_FILE_POSTFIX; + const auto output_file_name = file_name + OUTPUT_FILE_POSTFIX; std::fstream fs(output_file_name, std::ios_base::out); if (fs.bad()) { @@ -115,19 +114,19 @@ int main(int argc, char **argv) continue; } - for (auto &channel : channels) { + for (const auto &channel : channels) { using namespace integral_image; - //The specification implicitly assumes that an output consists of floating-point values. + //The specification implicitly assumes that an output file consists of floating-point values. //Since the reasons of that decision are unknown, we convert data to 'double' format before - //calculations. Pros: no overflow, cons: precision loss. - Mat float_channel; - channel.convertTo(float_channel, CV_64FC1); + //calculations. Pros: no overflow, cons: precision loss, slower calculations. + Mat float_mat; + channel.convertTo(float_mat, CV_64FC1); - float_channel = integral_image_openmp(float_channel, args.thread_number); + float_mat = integral_image_openmp(float_mat, args.thread_number); - fs << float_channel; + fs << float_mat; if (fs.fail()) { std::cerr << "Failed to write data to file " << output_file_name << std::endl;