summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-04-29 18:34:46 +0200
committerStanislaw Halik <sthalik@misaki.pl>2019-04-29 18:34:55 +0200
commitce79d1556bf8d43665694d7dd75571a79d175615 (patch)
treeaf2863d3dd863e1d4ff598f9c9dd70c86bb1bcd3
parentf8e54403c3c30bf87491d310afd827a2d7cb7f16 (diff)
cv: gather common init code
-rw-r--r--cv/CMakeLists.txt9
-rw-r--r--cv/init.cpp23
-rw-r--r--cv/init.hpp2
-rw-r--r--cv/ocv-check.cxx7
-rw-r--r--tracker-aruco/ftnoir_tracker_aruco.cpp4
-rw-r--r--tracker-easy/tracker-easy.cpp6
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp7
7 files changed, 50 insertions, 8 deletions
diff --git a/cv/CMakeLists.txt b/cv/CMakeLists.txt
index 12935f1b..6c693acb 100644
--- a/cv/CMakeLists.txt
+++ b/cv/CMakeLists.txt
@@ -1,7 +1,16 @@
include(opentrack-opencv)
find_package(OpenCV QUIET)
if(OpenCV_FOUND)
+ try_compile(cv_use-ipp "${CMAKE_CURRENT_BINARY_DIR}"
+ SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/ocv-check.cxx"
+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${OpenCV_INCLUDE_DIRS}"
+ "-DCXX_STANDARD=17" "-DCXX_STANDARD_REQUIRED=1"
+ COMPILE_DEFINITIONS "-D_HAS_EXCEPTIONS=0"
+ OUTPUT_VARIABLE krap)
otr_module(cv STATIC)
target_link_libraries(${self} opencv_videoio opencv_core opentrack-video)
target_include_directories(${self} SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS})
+ if(cv_use-ipp)
+ target_compile_definitions(${self} PUBLIC -DOTR_HAS_CV_IPP)
+ endif()
endif()
diff --git a/cv/init.cpp b/cv/init.cpp
new file mode 100644
index 00000000..c9c4650f
--- /dev/null
+++ b/cv/init.cpp
@@ -0,0 +1,23 @@
+#include "init.hpp"
+#include <type_traits>
+#include <opencv2/core.hpp>
+
+[[noreturn]]
+static
+int error_handler(int, const char* fn, const char* msg, const char* filename, int line, void*)
+{
+ fprintf(stderr, "[%s:%d] opencv: %s at %s\n", filename, line, msg, fn);
+ fflush(stderr);
+ std::abort();
+}
+
+void opencv_init()
+{
+ cv::redirectError(error_handler);
+ cv::setBreakOnError(false);
+ cv::setNumThreads(1);
+#ifdef OTR_HAS_CV_IPP
+ cv::ipp::setUseIPP(true);
+ cv::ipp::setUseIPP_NotExact(true);
+#endif
+}
diff --git a/cv/init.hpp b/cv/init.hpp
new file mode 100644
index 00000000..4c529549
--- /dev/null
+++ b/cv/init.hpp
@@ -0,0 +1,2 @@
+#pragma once
+void opencv_init();
diff --git a/cv/ocv-check.cxx b/cv/ocv-check.cxx
new file mode 100644
index 00000000..9efe3610
--- /dev/null
+++ b/cv/ocv-check.cxx
@@ -0,0 +1,7 @@
+#include <opencv2/core.hpp>
+
+void check1()
+{
+ cv::ipp::setUseIPP(true);
+ cv::ipp::setUseIPP_NotExact(true);
+}
diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp
index d9674755..d9cb2b96 100644
--- a/tracker-aruco/ftnoir_tracker_aruco.cpp
+++ b/tracker-aruco/ftnoir_tracker_aruco.cpp
@@ -8,6 +8,7 @@
#include "ftnoir_tracker_aruco.h"
#include "compat/sleep.hpp"
#include "compat/math-imports.hpp"
+#include "cv/init.hpp"
#ifdef _MSC_VER
# pragma warning(disable : 4702)
@@ -60,8 +61,7 @@ static const resolution_tuple resolution_choices[] =
aruco_tracker::aruco_tracker()
{
- cv::setBreakOnError(true);
- cv::setNumThreads(1);
+ opencv_init();
// param 2 ignored for Otsu thresholding. it's required to use our fork of Aruco.
set_detector_params();
diff --git a/tracker-easy/tracker-easy.cpp b/tracker-easy/tracker-easy.cpp
index e13bdf37..84d14db0 100644
--- a/tracker-easy/tracker-easy.cpp
+++ b/tracker-easy/tracker-easy.cpp
@@ -10,6 +10,7 @@
#include "compat/math-imports.hpp"
#include "compat/check-visible.hpp"
#include "point-extractor.h"
+#include "cv/init.hpp"
#include <QHBoxLayout>
#include <QDebug>
@@ -33,6 +34,8 @@ using namespace options;
// We need at least 3 vertices to be able to do anything
const int KMinVertexCount = 3;
+
+
namespace EasyTracker
{
@@ -40,8 +43,7 @@ namespace EasyTracker
iSettings{ KModuleName },
iPreview{ preview_width, preview_height }
{
- cv::setBreakOnError(true);
- cv::setNumThreads(1);
+ opencv_init();
connect(iSettings.b.get(), &bundle_::saving, this, &Tracker::maybe_reopen_camera, Qt::DirectConnection);
connect(iSettings.b.get(), &bundle_::reloading, this, &Tracker::maybe_reopen_camera, Qt::DirectConnection);
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index d7484e9c..ea5346f6 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -7,13 +7,13 @@
*/
#include "ftnoir_tracker_pt.h"
+#include "pt-api.hpp"
+#include "cv/init.hpp"
#include "video/video-widget.hpp"
#include "compat/math-imports.hpp"
#include "compat/check-visible.hpp"
#include "compat/thread-name.hpp"
-#include "pt-api.hpp"
-
#include <QHBoxLayout>
#include <QDebug>
#include <QFile>
@@ -31,8 +31,7 @@ Tracker_PT::Tracker_PT(pointer<pt_runtime_traits> const& traits) :
frame { traits->make_frame() },
preview_frame { traits->make_preview(preview_width, preview_height) }
{
- cv::setBreakOnError(true);
- cv::setNumThreads(1);
+ opencv_init();
connect(s.b.get(), &bundle_::saving, this, &Tracker_PT::maybe_reopen_camera, Qt::DirectConnection);
connect(s.b.get(), &bundle_::reloading, this, &Tracker_PT::maybe_reopen_camera, Qt::DirectConnection);