initial commit; argument list parser is implemented
This commit is contained in:
commit
9016f8461e
4 changed files with 109 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
build/*
|
||||
*.swp
|
||||
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(PROJECT "integral_image")
|
||||
|
||||
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
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT} ${SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT} LINK_PUBLIC
|
||||
${OpenCV_LIBRARIES})
|
||||
0
README.txt
Normal file
0
README.txt
Normal file
87
main.cpp
Normal file
87
main.cpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
struct Arguments
|
||||
{
|
||||
int thread_number = 0;
|
||||
std::vector<std::string> file_names;
|
||||
};
|
||||
|
||||
Arguments parse_arguments(int argc, char **argv)
|
||||
{
|
||||
const std::string THREAD_ARGUMENT = "-t";
|
||||
const std::string IMAGE_ARGUMENT = "-i";
|
||||
|
||||
Arguments args;
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
|
||||
if (THREAD_ARGUMENT == argv[i]) {
|
||||
|
||||
if (++i == argc)
|
||||
throw std::invalid_argument("thread number isn't specified");
|
||||
|
||||
ss.str(argv[i]);
|
||||
ss >> args.thread_number;
|
||||
|
||||
if (ss.bad() || args.thread_number < 0)
|
||||
throw std::invalid_argument("thread number is invalid");
|
||||
}
|
||||
else if (IMAGE_ARGUMENT == argv[i]) {
|
||||
|
||||
if (++i == argc)
|
||||
throw std::invalid_argument("image file name isn't specified");
|
||||
|
||||
args.file_names.push_back(argv[i]);
|
||||
}
|
||||
else {
|
||||
|
||||
throw std::invalid_argument("unknown argument");
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
|
||||
Arguments args = parse_arguments(argc, argv);
|
||||
|
||||
if (0 == args.thread_number)
|
||||
args.thread_number = omp_get_max_threads();
|
||||
|
||||
for (const auto &file_name : args.file_names) {
|
||||
|
||||
auto mat = cv::imread(file_name);
|
||||
if (mat.data == NULL) {
|
||||
|
||||
std::cerr << "Image file " << file_name << " is absent or damaged, skipping" << std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::invalid_argument &e) {
|
||||
|
||||
std::cerr << "Invalid argument: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue