This commit is contained in:
Dmitry Kokorin 2018-09-05 23:37:37 +03:00
parent cccd0f1641
commit f60ffee0bb
3 changed files with 16 additions and 15 deletions

View file

@ -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(SOURCES

View file

@ -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_<double>;
//! A reference serial implementation of the integral image algorithm.

View file

@ -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;