Skip to content

Commit

Permalink
Рефакторинг функций для отладки
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Vorotnev authored and dvorotnev committed Mar 9, 2021
1 parent 6711f3c commit 4d9b8fa
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: cpp
dist: bionic
dist: focal
sudo: required

addons:
Expand Down
24 changes: 0 additions & 24 deletions include/Debug.h

This file was deleted.

63 changes: 63 additions & 0 deletions include/Debug.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Дополнительный функционал для отладки.
*/

#ifndef __DEBUG_HPP__
#define __DEBUG_HPP__

#include <opencv2/core.hpp>

#define ___DEBUG___ 1

#if ___DEBUG___
#include <string>
#include <filesystem>

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#endif // ___DEBUG___

// В режиме отладки: запись изображения в каталог отладки.
template<class String>
void imageWrite(const String& win_name, const cv::Mat& mat)
{
#if ___DEBUG___
namespace fs = std::filesystem;
static size_t debug_frame_counter = 0;
if (win_name == std::string("Input"))
++debug_frame_counter;

const fs::path debug_dir = "../result/";
fs::create_directory(debug_dir);
fs::path image_dir = debug_dir / win_name;
fs::create_directory(image_dir);
std::string file_name = std::to_string(debug_frame_counter) + ".png";
fs::path image_path = image_dir / file_name;
cv::imwrite(image_path, mat);
#endif // ___DEBUG___
}

// В режиме отладки: запись изображения в каталог отладки.
// В обычном режиме: вывод изображения на экран.
template<class String>
void imageShow(const String& win_name, const cv::Mat& image)
{
imshow(win_name, image);

#if ___DEBUG___
if (image.channels() == 1)
{
cv::Mat bin_image = image.clone();
const uchar BackGround = 0;
const uchar ForeGround = 255;
cv::threshold(image, bin_image, BackGround, ForeGround, cv::THRESH_BINARY);
imageWrite(win_name, bin_image);
}
else
{
imageWrite(win_name, image);
}
#endif // ___DEBUG___
}

#endif // __DEBUG_HPP__
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <Hand.h>
#include <Timer.h>
#include <Debug.h>
#include <Debug.hpp>
#include <VideoSequenceCapture.h>
#include <HandDetector.hpp>
#include <GesturesRecognition.h>
Expand Down
11 changes: 6 additions & 5 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
include(ExternalProject)

FIND_PACKAGE(PythonLibs 3 REQUIRED)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(Boost COMPONENTS python38 system REQUIRED)

add_compile_options(-Wno-unused-function -Wno-unused-variable)

file(GLOB SOURCES *.cpp)
PYTHON_ADD_MODULE(${PROJECT_NAME}_py MODULE ${SOURCES})
add_library(${PROJECT_NAME}_py MODULE ${SOURCES})

find_package(Boost COMPONENTS system python3 REQUIRED)
target_include_directories(${PROJECT_NAME}_py PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}_py PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${Python_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_py PUBLIC ${Boost_LIBRARIES} ${PROJECT_NAME}-lib)

ExternalProject_Add(pyboostcvconverter
URL https://api.github.com/repos/Algomorph/pyboostcvconverter/tarball/3338a4c
URL_HASH MD5=b02287f63b4ab543e1277de499da87b3
PATCH_COMMAND patch CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/version.patch
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release;-DPYTHON_DESIRED_VERSION=3.X"
INSTALL_COMMAND ""
)
Expand All @@ -23,7 +24,7 @@ ExternalProject_Get_Property(pyboostcvconverter SOURCE_DIR)
ExternalProject_Get_Property(pyboostcvconverter BINARY_DIR)

add_library(pyboostcvconverter_lib SHARED IMPORTED)
set_property(TARGET pyboostcvconverter_lib PROPERTY IMPORTED_LOCATION ${BINARY_DIR}/pbcvt.cpython-36m-x86_64-linux-gnu.so)
set_property(TARGET pyboostcvconverter_lib PROPERTY IMPORTED_LOCATION ${BINARY_DIR}/pbcvt.cpython-38-x86_64-linux-gnu.so)
target_include_directories(${PROJECT_NAME}_py PUBLIC ${SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME}_py PUBLIC pyboostcvconverter_lib)

Expand Down
10 changes: 10 additions & 0 deletions python/version.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 017c63b..668a33e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project("pbcvt")

#----------------------------CMAKE & GLOBAL PROPERTIES-------------------------#
2 changes: 1 addition & 1 deletion src/Contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <optional>

#include <Contour.h>
#include <Debug.h>
#include <Debug.hpp>

using namespace std;
using namespace cv;
Expand Down
70 changes: 0 additions & 70 deletions src/Debug.cpp

This file was deleted.

0 comments on commit 4d9b8fa

Please sign in to comment.