mirror of
https://github.com/opencv/opencv.git
synced 2026-07-25 21:33:04 +04:00
Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 75ed282b20 | |||
| 754956857c | |||
| a4ab60920f | |||
| a574788e89 | |||
| 22dbcf98c5 | |||
| 183bc5c281 | |||
| a1fe8f754f | |||
| dd3398416b | |||
| cf86af96ea | |||
| 780ae864a0 | |||
| 96c99c716a | |||
| 73a17baeec | |||
| c26dd5d7aa | |||
| 954969dd74 | |||
| 43002c0c1d | |||
| e580061b74 | |||
| d7540c9a3c | |||
| bea312bd65 | |||
| 3705648c9b | |||
| 53af811530 | |||
| b58a8729c2 | |||
| ee417048e5 | |||
| a4b21d9e2e | |||
| b321851e53 | |||
| 1d5a528107 | |||
| a68835f7f1 | |||
| f2bec05e6d | |||
| c371df4aa2 | |||
| 9ea8c775f8 | |||
| e8e2197032 | |||
| c4c31f5bba | |||
| 940dc1f2b7 | |||
| f54b230906 | |||
| 3bbc4e44c3 | |||
| ce6acd3ecd | |||
| 1c04a5ec47 | |||
| 2fa9bd221d | |||
| 9ca82caeb7 | |||
| 5cf84c3765 | |||
| 3d68b5baa1 | |||
| 8792bddb0a | |||
| e5afa62c3d | |||
| 33e824f5de | |||
| 6820abd67f | |||
| b5c54e447c | |||
| f81370232a | |||
| 85fad1504a | |||
| 1d10d56651 | |||
| ef5d921eac | |||
| 96c71dd3d2 | |||
| 8409aa9eba | |||
| 02d2cc58d7 | |||
| 452f0bb2ab | |||
| 10b482ff1e | |||
| 42742727d6 | |||
| ca9aa180c1 | |||
| ce46cc9852 | |||
| 47cb94e634 | |||
| 39f327acdb | |||
| 80265a0815 | |||
| 6189b47648 | |||
| dd6f5949c2 | |||
| a62539489d | |||
| 70ac734263 | |||
| b24a815ac1 | |||
| d6b2739525 | |||
| 846a500fb4 | |||
| 8b7f805642 | |||
| cc5190eb91 | |||
| 4eff798270 | |||
| 4e40e5bb88 | |||
| a456b968cf | |||
| 2dd98e7cc6 | |||
| 28fd967148 | |||
| 1196eb33fc | |||
| e6d9486a6c | |||
| 9a8e47a766 |
+4
-4
@@ -49,12 +49,12 @@ namespace {
|
||||
|
||||
enum
|
||||
{
|
||||
SHIFT = 14,
|
||||
SHIFT = 15,
|
||||
SHIFT_DELTA = 1 << (SHIFT - 1),
|
||||
|
||||
R2Y_BT601 = 4899,
|
||||
G2Y_BT601 = 9617,
|
||||
B2Y_BT601 = 1868,
|
||||
R2Y_BT601 = 9798,
|
||||
G2Y_BT601 = 19235,
|
||||
B2Y_BT601 = 3735,
|
||||
|
||||
R2Y_BT709 = 3483,
|
||||
G2Y_BT709 = 11718,
|
||||
|
||||
+3
-2
@@ -295,8 +295,8 @@ OCV_OPTION(BUILD_ANDROID_EXAMPLES "Build examples for Android platform"
|
||||
OCV_OPTION(BUILD_DOCS "Create build rules for OpenCV Documentation" OFF IF (NOT WINRT AND NOT APPLE_FRAMEWORK))
|
||||
OCV_OPTION(BUILD_EXAMPLES "Build all examples" OFF )
|
||||
OCV_OPTION(BUILD_PACKAGE "Enables 'make package_source' command" ON IF NOT WINRT)
|
||||
OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" ON IF (NOT APPLE_FRAMEWORK) )
|
||||
OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT APPLE_FRAMEWORK) )
|
||||
OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" NOT INSTALL_CREATE_DISTRIB IF (NOT APPLE_FRAMEWORK) )
|
||||
OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" NOT INSTALL_CREATE_DISTRIB IF (NOT APPLE_FRAMEWORK) )
|
||||
OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into release binaries ('OFF' means default settings)" OFF )
|
||||
OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of statically linked CRT for statically linked OpenCV" ON IF MSVC )
|
||||
OCV_OPTION(BUILD_WITH_DYNAMIC_IPP "Enables dynamic linking of IPP (only for standalone IPP)" OFF )
|
||||
@@ -461,6 +461,7 @@ else()
|
||||
ocv_update(OPENCV_OTHER_INSTALL_PATH "${CMAKE_INSTALL_DATAROOTDIR}/opencv4")
|
||||
ocv_update(OPENCV_LICENSES_INSTALL_PATH "${CMAKE_INSTALL_DATAROOTDIR}/licenses/opencv4")
|
||||
endif()
|
||||
ocv_update(OPENCV_PYTHON_INSTALL_PATH "python")
|
||||
endif()
|
||||
|
||||
ocv_update(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}")
|
||||
|
||||
@@ -78,9 +78,9 @@ endif()
|
||||
|
||||
if(INF_ENGINE_TARGET)
|
||||
if(NOT INF_ENGINE_RELEASE)
|
||||
message(WARNING "InferenceEngine version have not been set, 2018R3 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
|
||||
message(WARNING "InferenceEngine version have not been set, 2018R4 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
|
||||
endif()
|
||||
set(INF_ENGINE_RELEASE "2018030000" CACHE STRING "Force IE version, should be in form YYYYAABBCC (e.g. 2018R2.0.2 -> 2018020002)")
|
||||
set(INF_ENGINE_RELEASE "2018040000" CACHE STRING "Force IE version, should be in form YYYYAABBCC (e.g. 2018R2.0.2 -> 2018020002)")
|
||||
set_target_properties(${INF_ENGINE_TARGET} PROPERTIES
|
||||
INTERFACE_COMPILE_DEFINITIONS "HAVE_INF_ENGINE=1;INF_ENGINE_RELEASE=${INF_ENGINE_RELEASE}"
|
||||
)
|
||||
|
||||
@@ -43,7 +43,12 @@ else()
|
||||
endif()
|
||||
file(RELATIVE_PATH OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG
|
||||
"${CMAKE_INSTALL_PREFIX}/${OPENCV_SETUPVARS_INSTALL_PATH}/" "${CMAKE_INSTALL_PREFIX}/")
|
||||
ocv_path_join(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG}" "python_loader") # https://github.com/opencv/opencv/pull/12977
|
||||
if(IS_ABSOLUTE "${OPENCV_PYTHON_INSTALL_PATH}")
|
||||
set(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${OPENCV_PYTHON_INSTALL_PATH}")
|
||||
message(WARNING "CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install directory")
|
||||
else()
|
||||
ocv_path_join(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG}" "${OPENCV_PYTHON_INSTALL_PATH}")
|
||||
endif()
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/${OPENCV_SETUPVARS_TEMPLATE}" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/install/${OPENCV_SETUPVARS_FILENAME}" @ONLY)
|
||||
install(FILES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/install/${OPENCV_SETUPVARS_FILENAME}"
|
||||
DESTINATION "${OPENCV_SETUPVARS_INSTALL_PATH}"
|
||||
|
||||
@@ -605,7 +605,9 @@ macro(OCV_OPTION variable description value)
|
||||
option(${variable} "${description}" ${__value})
|
||||
endif()
|
||||
else()
|
||||
if(DEFINED ${variable} AND NOT OPENCV_HIDE_WARNING_UNSUPPORTED_OPTION)
|
||||
if(DEFINED ${variable} AND "${${variable}}" # emit warnings about turned ON options only.
|
||||
AND NOT (OPENCV_HIDE_WARNING_UNSUPPORTED_OPTION OR "$ENV{OPENCV_HIDE_WARNING_UNSUPPORTED_OPTION}")
|
||||
)
|
||||
message(WARNING "Unexpected option: ${variable} (=${${variable}})\nCondition: IF (${__condition})")
|
||||
endif()
|
||||
if(OPENCV_UNSET_UNSUPPORTED_OPTION)
|
||||
|
||||
@@ -1,18 +1,36 @@
|
||||
@ECHO OFF
|
||||
SETLOCAL EnableDelayedExpansion
|
||||
|
||||
SET "SCRIPT_DIR=%~dp0"
|
||||
|
||||
IF NOT DEFINED OPENCV_QUIET ( ECHO Setting vars for OpenCV @OPENCV_VERSION@ )
|
||||
SET "PATH=!SCRIPT_DIR!\@OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG@;%PATH%"
|
||||
SET "PATH=%SCRIPT_DIR%\@OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG@;%PATH%"
|
||||
|
||||
IF NOT DEFINED OPENCV_SKIP_PYTHON (
|
||||
SET "PYTHONPATH_OPENCV=!SCRIPT_DIR!\@OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG@"
|
||||
IF NOT DEFINED OPENCV_QUIET ( ECHO Append PYTHONPATH: !PYTHONPATH_OPENCV! )
|
||||
SET "PYTHONPATH=!PYTHONPATH_OPENCV!;%PYTHONPATH%"
|
||||
)
|
||||
IF NOT DEFINED OPENCV_SKIP_PYTHON CALL :SET_PYTHON
|
||||
|
||||
IF NOT [%1] == [] (
|
||||
%*
|
||||
EXIT /B !errorlevel!
|
||||
SET SCRIPT_DIR=
|
||||
|
||||
IF NOT [%1] == [] GOTO :RUN_COMMAND
|
||||
|
||||
GOTO :EOF
|
||||
|
||||
:RUN_COMMAND
|
||||
SET RUN_INTERACTIVE=1
|
||||
echo %CMDCMDLINE% | find /i "%~0" >nul
|
||||
IF NOT errorlevel 1 set RUN_INTERACTIVE=0
|
||||
|
||||
%*
|
||||
SET RESULT=%ERRORLEVEL%
|
||||
IF %RESULT% NEQ 0 (
|
||||
IF _%RUN_INTERACTIVE%_==_0_ ( IF NOT DEFINED OPENCV_BATCH_MODE ( pause ) )
|
||||
)
|
||||
EXIT /B %RESULT%
|
||||
|
||||
:SET_PYTHON
|
||||
SET "PYTHONPATH_OPENCV=%SCRIPT_DIR%\@OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG@"
|
||||
IF NOT DEFINED OPENCV_QUIET ( ECHO Append PYTHONPATH: %PYTHONPATH_OPENCV% )
|
||||
SET "PYTHONPATH=%PYTHONPATH_OPENCV%;%PYTHONPATH%"
|
||||
SET PYTHONPATH_OPENCV=
|
||||
EXIT /B
|
||||
|
||||
|
||||
:EOF
|
||||
|
||||
+2
-1
@@ -106,7 +106,7 @@ FILE_PATTERNS =
|
||||
RECURSIVE = YES
|
||||
EXCLUDE = @CMAKE_DOXYGEN_EXCLUDE_LIST@
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS = *.inl.hpp *.impl.hpp *_detail.hpp */cudev/**/detail/*.hpp *.m */opencl/runtime/*
|
||||
EXCLUDE_PATTERNS = *.inl.hpp *.impl.hpp *_detail.hpp */cudev/**/detail/*.hpp *.m */opencl/runtime/* */legacy/* *_c.h @DOXYGEN_EXCLUDE_PATTERNS@
|
||||
EXCLUDE_SYMBOLS = cv::DataType<*> cv::traits::* int void CV__* T __CV*
|
||||
EXAMPLE_PATH = @CMAKE_DOXYGEN_EXAMPLE_PATH@
|
||||
EXAMPLE_PATTERNS = *
|
||||
@@ -257,6 +257,7 @@ PREDEFINED = __cplusplus=1 \
|
||||
CV_SSE2=1 \
|
||||
CV__DEBUG_NS_BEGIN= \
|
||||
CV__DEBUG_NS_END= \
|
||||
CV_DEPRECATED_EXTERNAL= \
|
||||
CV_DEPRECATED=
|
||||
EXPAND_AS_DEFINED =
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
|
||||
+3
-3
@@ -79,11 +79,11 @@ using **np.ifft2()** function. The result, again, will be a complex number. You
|
||||
absolute value.
|
||||
@code{.py}
|
||||
rows, cols = img.shape
|
||||
crow,ccol = rows/2 , cols/2
|
||||
fshift[crow-30:crow+30, ccol-30:ccol+30] = 0
|
||||
crow,ccol = rows//2 , cols//2
|
||||
fshift[crow-30:crow+31, ccol-30:ccol+31] = 0
|
||||
f_ishift = np.fft.ifftshift(fshift)
|
||||
img_back = np.fft.ifft2(f_ishift)
|
||||
img_back = np.abs(img_back)
|
||||
img_back = np.real(img_back)
|
||||
|
||||
plt.subplot(131),plt.imshow(img, cmap = 'gray')
|
||||
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
|
||||
|
||||
@@ -12,7 +12,7 @@ Tutorial was written for the following versions of corresponding software:
|
||||
|
||||
- Download and install Android Studio from https://developer.android.com/studio.
|
||||
|
||||
- Get the latest pre-built OpenCV for Android release from https://github.com/opencv/opencv/releases and unpack it (for example, `opencv-3.4.3-android-sdk.zip`).
|
||||
- Get the latest pre-built OpenCV for Android release from https://github.com/opencv/opencv/releases and unpack it (for example, `opencv-3.4.4-android-sdk.zip`).
|
||||
|
||||
- Download MobileNet object detection model from https://github.com/chuanqi305/MobileNet-SSD. We need a configuration file `MobileNetSSD_deploy.prototxt` and weights `MobileNetSSD_deploy.caffemodel`.
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 140 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 173 KiB |
+411
@@ -0,0 +1,411 @@
|
||||
# Porting anisotropic image segmentation on G-API {#tutorial_gapi_anisotropic_segmentation}
|
||||
|
||||
[TOC]
|
||||
|
||||
# Introduction {#gapi_anisotropic_intro}
|
||||
|
||||
In this tutorial you will learn:
|
||||
* How an existing algorithm can be transformed into a G-API
|
||||
computation (graph);
|
||||
* How to inspect and profile G-API graphs;
|
||||
* How to customize graph execution without changing its code.
|
||||
|
||||
This tutorial is based on @ref
|
||||
tutorial_anisotropic_image_segmentation_by_a_gst.
|
||||
|
||||
# Quick start: using OpenCV backend {#gapi_anisotropic_start}
|
||||
|
||||
Before we start, let's review the original algorithm implementation:
|
||||
|
||||
@include cpp/tutorial_code/ImgProc/anisotropic_image_segmentation/anisotropic_image_segmentation.cpp
|
||||
|
||||
## Examining calcGST() {#gapi_anisotropic_calcgst}
|
||||
|
||||
The function calcGST() is clearly an image processing pipeline:
|
||||
* It is just a sequence of operations over a number of cv::Mat;
|
||||
* No logic (conditionals) and loops involved in the code;
|
||||
* All functions operate on 2D images (like cv::Sobel, cv::multiply,
|
||||
cv::boxFilter, cv::sqrt, etc).
|
||||
|
||||
Considering the above, calcGST() is a great candidate to start
|
||||
with. In the original code, its prototype is defined like this:
|
||||
|
||||
@snippet cpp/tutorial_code/ImgProc/anisotropic_image_segmentation/anisotropic_image_segmentation.cpp calcGST_proto
|
||||
|
||||
With G-API, we can define it as follows:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp calcGST_proto
|
||||
|
||||
It is important to understand that the new G-API based version of
|
||||
calcGST() will just produce a compute graph, in contrast to its
|
||||
original version, which actually calculates the values. This is a
|
||||
principial difference -- G-API based functions like this are used to
|
||||
construct graphs, not to process the actual data.
|
||||
|
||||
Let's start implementing calcGST() with calculation of \f$J\f$
|
||||
matrix. This is how the original code looks like:
|
||||
|
||||
@snippet cpp/tutorial_code/ImgProc/anisotropic_image_segmentation/anisotropic_image_segmentation.cpp calcJ_header
|
||||
|
||||
Here we need to declare output objects for every new operation (see
|
||||
img as a result for cv::Mat::convertTo, imgDiffX and others as results for
|
||||
cv::Sobel and cv::multiply).
|
||||
|
||||
The G-API analogue is listed below:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp calcGST_header
|
||||
|
||||
This snippet demonstrates the following syntactic difference between
|
||||
G-API and traditional OpenCV:
|
||||
* All standard G-API functions are by default placed in "cv::gapi"
|
||||
namespace;
|
||||
* G-API operations _return_ its results -- there's no need to pass
|
||||
extra "output" parameters to the functions.
|
||||
|
||||
Note -- this code is also using `auto` -- types of intermediate objects
|
||||
like `img`, `imgDiffX`, and so on are inferred automatically by the
|
||||
C++ compiler. In this example, the types are determined by G-API
|
||||
operation return values which all are cv::GMat.
|
||||
|
||||
G-API standard kernels are trying to follow OpenCV API conventions
|
||||
whenever possible -- so cv::gapi::sobel takes the same arguments as
|
||||
cv::Sobel, cv::gapi::mul follows cv::multiply, and so on (except
|
||||
having a return value).
|
||||
|
||||
The rest of calcGST() function can be implemented the same
|
||||
way trivially. Below is its full source code:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp calcGST
|
||||
|
||||
## Running G-API graph {#gapi_anisotropic_running}
|
||||
|
||||
After calcGST() is defined in G-API language, we can construct a graph
|
||||
based on it and finally run it -- pass input image and obtain
|
||||
result. Before we do it, let's have a look how original code looked
|
||||
like:
|
||||
|
||||
@snippet cpp/tutorial_code/ImgProc/anisotropic_image_segmentation/anisotropic_image_segmentation.cpp main_extra
|
||||
|
||||
G-API-based functions like calcGST() can't be applied to input data
|
||||
directly, since it is a _construction_ code, not the _processing_ code.
|
||||
In order to _run_ computations, a special object of class
|
||||
cv::GComputation needs to be created. This object wraps our G-API code
|
||||
(which is a composition of G-API data and operations) into a callable
|
||||
object, similar to C++11
|
||||
[std::function<>](https://en.cppreference.com/w/cpp/utility/functional/function).
|
||||
|
||||
cv::GComputation class has a number of constructors which can be used
|
||||
to define a graph. Generally, user needs to pass graph boundaries
|
||||
-- _input_ and _output_ objects, on which a GComputation is
|
||||
defined. Then G-API analyzes the call flow from _outputs_ to _inputs_
|
||||
and reconstructs the graph with operations in-between the specified
|
||||
boundaries. This may sound complex, however in fact the code looks
|
||||
like this:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp main
|
||||
|
||||
Note that this code slightly changes from the original one: forming up
|
||||
the resulting image is also a part of the pipeline (done with
|
||||
cv::gapi::addWeighted). Normalization of orientation and coherency
|
||||
images is still done by traditional OpenCV (using cv::normalize) as
|
||||
G-API doesn't provide such kernel at the moment.
|
||||
|
||||
Result of this G-API pipeline bit-exact matches the original one
|
||||
(given the same input image):
|
||||
|
||||

|
||||
|
||||
## G-API initial version: full listing {#gapi_anisotropic_ocv}
|
||||
|
||||
Below is the full listing of the initial anisotropic image
|
||||
segmentation port on G-API:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp full_sample
|
||||
|
||||
# Inspecting the initial version {#gapi_anisotropic_inspect}
|
||||
|
||||
After we have got the initial working version of our algorithm working
|
||||
with G-API, we can use it to inspect and learn how G-API works. This
|
||||
chapter covers two aspects: understanding the graph structure, and
|
||||
memory profiling.
|
||||
|
||||
## Understanding the graph structure {#gapi_anisotropic_inspect_graph}
|
||||
|
||||
G-API stands for "Graph API", but did you mention any graphs in the
|
||||
above example? It was one of the initial design goals -- G-API was
|
||||
designed with expressions in mind to make adoption and porting process
|
||||
more straightforward. People _usually_ don't think in terms of
|
||||
_Nodes_ and _Edges_ when writing ordinary code, and so G-API, while
|
||||
being a Graph API, doesn't force its users to do that.
|
||||
|
||||
However, a graph is still built implicitly when a cv::GComputation
|
||||
object is defined. It may be useful to inspect how the resulting graph
|
||||
looks like to check if it is generated correctly and if it really
|
||||
represents our alrogithm. It is also useful to learn the structure of
|
||||
the graph to see if it has any redundancies.
|
||||
|
||||
G-API allows to dump generated graphs to `.dot` files which then
|
||||
could be visualized with [Graphviz](https://www.graphviz.org/), a
|
||||
popular open graph visualization software.
|
||||
|
||||
<!-- TODO THIS VARIABLE NEEDS TO BE FIXED TO DUMP DIR ASAP! -->
|
||||
|
||||
In order to dump our graph to a `.dot` file, set `GRAPH_DUMP_PATH` to a
|
||||
file name before running the application, e.g.:
|
||||
|
||||
$ GRAPH_DUMP_PATH=segm.dot ./bin/example_tutorial_porting_anisotropic_image_segmentation_gapi
|
||||
|
||||
Now this file can be visalized with a `dot` command like this:
|
||||
|
||||
$ dot segm.dot -Tpng -o segm.png
|
||||
|
||||
or viewed instantly with `xdot` command (please refer to your
|
||||
distribution/operating system documentation on how to install these
|
||||
packages).
|
||||
|
||||

|
||||
|
||||
The above diagram demonstrates a number of interesting aspects of
|
||||
G-API's internal algorithm representation:
|
||||
1. G-API underlying graph is a bipartite graph: it consists of
|
||||
_Operation_ and _Data_ nodes such that a _Data_ node can only be
|
||||
connected to an _Operation_ node, _Operation_ node can only be
|
||||
connected to a _Data_ node, and nodes of a single kind are never
|
||||
connected directly.
|
||||
2. Graph is directed - every edge in the graph has a direction.
|
||||
3. Graph "begins" and "ends" with a _Data_ kind of nodes.
|
||||
4. A _Data_ node can have only a single writer and multiple readers.
|
||||
5. An _Operation_ node may have multiple inputs, though every input
|
||||
must have an unique _port number_ (among inputs).
|
||||
6. An _Operation_ node may have multiple outputs, and every output
|
||||
must have an unique _port number_ (among outputs).
|
||||
|
||||
## Measuring memory footprint {#gapi_anisotropic_memory_ocv}
|
||||
|
||||
Let's measure and compare memory footprint of the algorithm in its two
|
||||
versions: G-API-based and OpenCV-based. At the moment, G-API version
|
||||
is also OpenCV-based since it fallbacks to OpenCV functions inside.
|
||||
|
||||
On GNU/Linux, application memory footprint can be profiled with
|
||||
[Valgrind](http://valgrind.org/). On Debian/Ubuntu systems it can be
|
||||
installed like this (assuming you have administrator priveleges):
|
||||
|
||||
$ sudo apt-get install valgrind massif-visualizer
|
||||
|
||||
Once installed, we can collect memory profiles easily for our two
|
||||
algorithm versions:
|
||||
|
||||
$ valgrind --tool=massif --massif-out-file=ocv.out ./bin/example_tutorial_anisotropic_image_segmentation
|
||||
==6101== Massif, a heap profiler
|
||||
==6101== Copyright (C) 2003-2015, and GNU GPL'd, by Nicholas Nethercote
|
||||
==6101== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
|
||||
==6101== Command: ./bin/example_tutorial_anisotropic_image_segmentation
|
||||
==6101==
|
||||
==6101==
|
||||
$ valgrind --tool=massif --massif-out-file=gapi.out ./bin/example_tutorial_porting_anisotropic_image_segmentation_gapi
|
||||
==6117== Massif, a heap profiler
|
||||
==6117== Copyright (C) 2003-2015, and GNU GPL'd, by Nicholas Nethercote
|
||||
==6117== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
|
||||
==6117== Command: ./bin/example_tutorial_porting_anisotropic_image_segmentation_gapi
|
||||
==6117==
|
||||
==6117==
|
||||
|
||||
Once done, we can inspect the collected profiles with
|
||||
[Massif Visualizer](@https://github.com/KDE/massif-visualizer)
|
||||
(installed in the above step).
|
||||
|
||||
Below is the visualized memory profile of the original OpenCV version
|
||||
of the algorithm:
|
||||
|
||||

|
||||
|
||||
We see that memory is allocated as the application
|
||||
executes, reaching its peak in the calcGST() function; then the
|
||||
footprint drops as calcGST() completes its execution and all temporary
|
||||
buffers are freed. Massif reports us peak memory consumption of 7.6 MiB.
|
||||
|
||||
Now let's have a look on the profile of G-API version:
|
||||
|
||||

|
||||
|
||||
Once G-API computation is created and its execution starts, G-API
|
||||
allocates all required memory at once and then the memory profile
|
||||
remains flat until the termination of the program. Massif reports us
|
||||
peak memory consumption of 10.6 MiB.
|
||||
|
||||
A reader may ask a right question at this point -- is G-API that bad?
|
||||
What is the reason in using it than?
|
||||
|
||||
Hopefully, it is not. The reason why we see here an increased memory
|
||||
consumption is because the default naive OpenCV-based backend is used to
|
||||
execute this graph. This backend serves mostly for quick prototyping
|
||||
and debugging algorithms before offload/further optimization.
|
||||
|
||||
This backend doesn't utilize any complex memory mamagement strategies yet
|
||||
since it is not its point at the moment. In the following chapter,
|
||||
we'll learn about Fluid backend and see how the same G-API code can
|
||||
run in a completely different model (and the footprint shrinked to a
|
||||
number of kilobytes).
|
||||
|
||||
# Backends and kernels {#gapi_anisotropic_backends}
|
||||
|
||||
This chapter covers how a G-API computation can be executed in a
|
||||
special way -- e.g. offloaded to another device, or scheduled with a
|
||||
special intelligence. G-API is designed to make its graphs portable --
|
||||
it means that once a graph is defined in G-API terms, no changes
|
||||
should be required in it if we want to run it on CPU or on GPU or on
|
||||
both devices at once. [G-API High-level overview](@ref gapi_hld) and
|
||||
[G-API Kernel API](@ref gapi_kernel_api) shed more light on technical
|
||||
details which make it possible. In this chapter, we will utilize G-API
|
||||
Fluid backend to make our graph cache-efficient on CPU.
|
||||
|
||||
G-API defines _backend_ as the lower-level entity which knows how to
|
||||
run kernels. Backends may have (and, in fact, do have) different
|
||||
_Kernel APIs_ which are used to program and integrate kernels for that
|
||||
backends. In this context, _kernel_ is an implementaion of an
|
||||
_operation_, which is defined on the top API level (see
|
||||
G_TYPED_KERNEL() macro).
|
||||
|
||||
Backend is a thing which is aware of device & platform specifics, and
|
||||
which executes its kernels with keeping that specifics in mind. For
|
||||
example, there may be [Halide](http://halide-lang.org/) backend which
|
||||
allows to write (implement) G-API operations in Halide language and
|
||||
then generate functional Halide code for portions of G-API graph which
|
||||
map well there.
|
||||
|
||||
## Running a graph with a Fluid backend {#gapi_anisotropic_fluid}
|
||||
|
||||
OpenCV 4.0 is bundled with two G-API backends -- the default "OpenCV"
|
||||
which we just used, and a special "Fluid" backend.
|
||||
|
||||
Fluid backend reorganizes the execution to save memory and to achieve
|
||||
near-perfect cache locality, implementing so-called "streaming" model
|
||||
of execution.
|
||||
|
||||
In order to start using Fluid kernels, we need first to include
|
||||
appropriate header files (which are not included by default):
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp fluid_includes
|
||||
|
||||
Once these headers are included, we can form up a new _kernel package_
|
||||
and specify it to G-API:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp kernel_pkg
|
||||
|
||||
In G-API, kernels (or operation implementations) are objects. Kernels are
|
||||
organized into collections, or _kernel packages_, represented by class
|
||||
cv::gapi::GKernelPackage. The main purpose of a kernel package is to
|
||||
capture which kernels we would like to use in our graph, and pass it
|
||||
as a _graph compilation option_:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp kernel_pkg_use
|
||||
|
||||
Traditional OpenCV is logically divided into modules, whith every
|
||||
module providing a set of functions. In G-API, there are also
|
||||
"modules" which are represented as kernel packages provided by a
|
||||
particular backend. In this example, we pass Fluid kernel packages to
|
||||
G-API to utilize appropriate Fluid functions in our graph.
|
||||
|
||||
Kernel packages are combinable -- in the above example, we take "Core"
|
||||
and "ImgProc" Fluid kernel packages and combine it into a single
|
||||
one. See documentation reference on cv::gapi::combine and
|
||||
cv::unite_policy on package combination options.
|
||||
|
||||
If no kernel packages are specified in options, G-API is using
|
||||
_default_ package which consists of default OpenCV implementations and
|
||||
thus G-API graphs are executed via OpenCV functions by default. OpenCV
|
||||
backend provides broader functional coverage than any other
|
||||
backend. If a kernel package is specified, like in this example, then
|
||||
it is being combined with the _default_ one with
|
||||
cv::unite_policy::REPLACE. It means that user-specified
|
||||
implementations will replace default implementations in case of
|
||||
conflict.
|
||||
|
||||
Kernel packages may contain a mix of kernels, in particular, multiple
|
||||
implementations of the same kernel. For example, a single kernel
|
||||
package may contain both OpenCV and Fluid implementations of kernel
|
||||
"Filter2D". In this case, the implementation selection preference can
|
||||
be specified with a special compilation parameter cv::gapi::lookup_order.
|
||||
|
||||
<!-- FIXME Document this process better as a part of regular -->
|
||||
<!-- documentation, not a tutorial kind of thing -->
|
||||
|
||||
## Troubleshooting and customization {#gapi_anisotropic_trouble}
|
||||
|
||||
After the above modifications, (in OpenCV 4.0) the app should crash
|
||||
with a message like this:
|
||||
|
||||
```
|
||||
$ ./bin/example_tutorial_porting_anisotropic_image_segmentation_gapi_fluid
|
||||
terminate called after throwing an instance of 'std::logic_error'
|
||||
what(): .../modules/gapi/src/backends/fluid/gfluidimgproc.cpp:436: Assertion kernelSize.width == 3 && kernelSize.height == 3 in function run failed
|
||||
|
||||
Aborted (core dumped)
|
||||
```
|
||||
|
||||
Fluid backend has a number of limitations in OpenCV 4.0 (see this
|
||||
[wiki page](https://github.com/opencv/opencv/wiki/Graph-API) for a
|
||||
more up-to-date status). In particular, the Box filter used in this
|
||||
sample supports only static 3x3 kernel size.
|
||||
|
||||
We can overcome this problem easily by avoiding G-API using Fluid
|
||||
version of Box filter kernel in this sample. It can be done by
|
||||
removing the appropriate kernel from the kernel package we've just
|
||||
created:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp kernel_hotfix
|
||||
|
||||
Now this kernel package doesn't have _any_ implementation of Box
|
||||
filter kernel interface (specified as a template parameter). As
|
||||
described above, G-API will fall-back to OpenCV to run this kernel
|
||||
now. The resulting code with this change now looks like:
|
||||
|
||||
@snippet cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp kernel_pkg_proper
|
||||
|
||||
Let's examine the memory profile for this sample after we switched to
|
||||
Fluid backend. Now it looks like this:
|
||||
|
||||

|
||||
|
||||
Now the tool reports 3.8MiB -- and we just changed a few lines in our
|
||||
code, without modifying the graph itself! It is a ~2.8X improvement of
|
||||
the previous G-API result, and 2X improvement of the original OpenCV
|
||||
version.
|
||||
|
||||
Let's also examine how the internal representation of the graph now
|
||||
looks like. Dumping the graph into `.dot` would result into a
|
||||
visualization like this:
|
||||
|
||||

|
||||
|
||||
This graph doesn't differ structually from its previous version (in
|
||||
terms of operations and data objects), though a changed layout (on the
|
||||
left side of the dump) is easily noticeable.
|
||||
|
||||
The visualization reflects how G-API deals with mixed graphs, also
|
||||
called _heterogeneous_ graphs. The majority of operations in this
|
||||
graph are implemented with Fluid backend, but Box filters are executed
|
||||
by the OpenCV backend. One can easily see that the graph is partioned
|
||||
(with rectangles). G-API groups connected operations based on their
|
||||
affinity, forming _subgraphs_ (or _islands_ in G-API terminology), and
|
||||
our top-level graph becomes a composition of multiple smaller
|
||||
subgraphs. Every backend determines how its subgraph (island) is
|
||||
executed, so Fluid backend optimizes out memory where possible, and
|
||||
six intermediate buffers accessed by OpenCV Box filters are allocated
|
||||
fully and can't be optimized out.
|
||||
|
||||
<!-- TODO: add a chapter on custom kernels -->
|
||||
<!-- TODO: make a full-fluid pipeline -->
|
||||
<!-- TODO: talk about parallelism when it is available -->
|
||||
|
||||
# Conclusion {#gapi_tutor_conclusion}
|
||||
|
||||
This tutorial demonstrates what G-API is and what its key design
|
||||
concepts are, how an algorithm can be ported to G-API, and
|
||||
how to utilize graph model benefits after that.
|
||||
|
||||
In OpenCV 4.0, G-API is still in its inception stage -- it is more a
|
||||
foundation for all future work, though ready for use even now.
|
||||
|
||||
Further, this tutorial will be extended with new chapters on custom
|
||||
kernels programming, parallelism, and more.
|
||||
@@ -0,0 +1,17 @@
|
||||
# Graph API (gapi module) {#tutorial_table_of_content_gapi}
|
||||
|
||||
In this section you will learn about graph-based image processing and
|
||||
how G-API module can be used for that.
|
||||
|
||||
- @subpage tutorial_gapi_anisotropic_segmentation
|
||||
|
||||
*Languages:* C++
|
||||
|
||||
*Compatibility:* \> OpenCV 4.0
|
||||
|
||||
*Author:* Dmitry Matveev
|
||||
|
||||
This is an end-to-end tutorial where an existing sample algorithm
|
||||
is ported on G-API, covering the basic intuition behind this
|
||||
transition process, and examining benefits which a graph model
|
||||
brings there.
|
||||
@@ -36,14 +36,14 @@ Open your Doxyfile using your favorite text editor and search for the key
|
||||
`TAGFILES`. Change it as follows:
|
||||
|
||||
@code
|
||||
TAGFILES = ./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/4.0.0-rc
|
||||
TAGFILES = ./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/4.0.0
|
||||
@endcode
|
||||
|
||||
If you had other definitions already, you can append the line using a `\`:
|
||||
|
||||
@code
|
||||
TAGFILES = ./docs/doxygen-tags/libstdc++.tag=https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen \
|
||||
./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/4.0.0-rc
|
||||
./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/4.0.0
|
||||
@endcode
|
||||
|
||||
Doxygen can now use the information from the tag file to link to the OpenCV
|
||||
|
||||
@@ -67,6 +67,10 @@ As always, we would be happy to hear your comments and receive your contribution
|
||||
Use the powerful
|
||||
machine learning classes for statistical classification, regression and clustering of data.
|
||||
|
||||
- @subpage tutorial_table_of_content_gapi
|
||||
|
||||
Learn how to use Graph API (G-API) and port algorithms from "traditional" OpenCV to a graph model.
|
||||
|
||||
- @subpage tutorial_table_of_content_photo
|
||||
|
||||
Use OpenCV for
|
||||
|
||||
@@ -78,5 +78,5 @@ there are two flags that should be used to set/get property of the needed genera
|
||||
flag value is assumed by default if neither of the two possible values of the property is set.
|
||||
|
||||
For more information please refer to the example of usage
|
||||
[intelperc_capture.cpp](https://github.com/opencv/opencv/tree/master/samples/cpp/intelperc_capture.cpp)
|
||||
[videocapture_intelperc.cpp](https://github.com/opencv/opencv/tree/master/samples/cpp/videocapture_intelperc.cpp)
|
||||
in opencv/samples/cpp folder.
|
||||
|
||||
@@ -134,5 +134,5 @@ property. The following properties of cameras available through OpenNI interface
|
||||
- CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_REGISTRATION
|
||||
|
||||
For more information please refer to the example of usage
|
||||
[openni_capture.cpp](https://github.com/opencv/opencv/tree/master/samples/cpp/openni_capture.cpp) in
|
||||
[videocapture_openni.cpp](https://github.com/opencv/opencv/tree/master/samples/cpp/videocapture_openni.cpp) in
|
||||
opencv/samples/cpp folder.
|
||||
|
||||
@@ -86,3 +86,47 @@ ocv_add_accuracy_tests()
|
||||
ocv_add_perf_tests()
|
||||
|
||||
ocv_install_3rdparty_licenses(SoftFloat "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/SoftFloat/COPYING.txt")
|
||||
|
||||
|
||||
# generate data (samples data) config file
|
||||
set(OPENCV_DATA_CONFIG_FILE "${CMAKE_BINARY_DIR}/opencv_data_config.hpp")
|
||||
set(OPENCV_DATA_CONFIG_STR "")
|
||||
|
||||
if(CMAKE_INSTALL_PREFIX)
|
||||
set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
|
||||
#define OPENCV_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\"
|
||||
")
|
||||
endif()
|
||||
if(OPENCV_OTHER_INSTALL_PATH)
|
||||
set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
|
||||
#define OPENCV_DATA_INSTALL_PATH \"${OPENCV_OTHER_INSTALL_PATH}\"
|
||||
")
|
||||
endif()
|
||||
|
||||
set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
|
||||
#define OPENCV_BUILD_DIR \"${CMAKE_BINARY_DIR}\"
|
||||
")
|
||||
|
||||
file(RELATIVE_PATH SOURCE_DIR_RELATIVE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
|
||||
set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
|
||||
#define OPENCV_DATA_BUILD_DIR_SEARCH_PATHS \\
|
||||
\"${SOURCE_DIR_RELATIVE}/\"
|
||||
")
|
||||
|
||||
if(WIN32)
|
||||
file(RELATIVE_PATH INSTALL_DATA_DIR_RELATIVE "${CMAKE_INSTALL_PREFIX}/${OPENCV_BIN_INSTALL_PATH}" "${CMAKE_INSTALL_PREFIX}/${OPENCV_OTHER_INSTALL_PATH}")
|
||||
else()
|
||||
file(RELATIVE_PATH INSTALL_DATA_DIR_RELATIVE "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}" "${CMAKE_INSTALL_PREFIX}/${OPENCV_OTHER_INSTALL_PATH}")
|
||||
endif()
|
||||
list(APPEND OPENCV_INSTALL_DATA_DIR_RELATIVE "${INSTALL_DATA_DIR_RELATIVE}")
|
||||
string(REPLACE ";" "\",\\\n \"" OPENCV_INSTALL_DATA_DIR_RELATIVE_STR "\"${OPENCV_INSTALL_DATA_DIR_RELATIVE}\"")
|
||||
set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
|
||||
#define OPENCV_INSTALL_DATA_DIR_RELATIVE ${OPENCV_INSTALL_DATA_DIR_RELATIVE_STR}
|
||||
")
|
||||
|
||||
if(EXISTS "${OPENCV_DATA_CONFIG_FILE}")
|
||||
file(READ "${OPENCV_DATA_CONFIG_FILE}" __content)
|
||||
endif()
|
||||
if(NOT OPENCV_DATA_CONFIG_STR STREQUAL "${__content}")
|
||||
file(WRITE "${OPENCV_DATA_CONFIG_FILE}" "${OPENCV_DATA_CONFIG_STR}")
|
||||
endif()
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
@defgroup core_utils_sse SSE utilities
|
||||
@defgroup core_utils_neon NEON utilities
|
||||
@defgroup core_utils_softfloat Softfloat support
|
||||
@defgroup core_utils_samples Utility functions for OpenCV samples
|
||||
@}
|
||||
@defgroup core_opengl OpenGL interoperability
|
||||
@defgroup core_ipp Intel IPP Asynchronous C/C++ Converters
|
||||
|
||||
@@ -349,6 +349,15 @@ Cv64suf;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CV_DEPRECATED_EXTERNAL
|
||||
# if defined(__OPENCV_BUILD)
|
||||
# define CV_DEPRECATED_EXTERNAL /* nothing */
|
||||
# else
|
||||
# define CV_DEPRECATED_EXTERNAL CV_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef CV_EXTERN_C
|
||||
# ifdef __cplusplus
|
||||
# define CV_EXTERN_C extern "C"
|
||||
|
||||
@@ -1363,25 +1363,22 @@ inline v_float64x4 v_cvt_f64_high(const v_float32x8& a)
|
||||
|
||||
inline v_int32x8 v_lut(const int* tab, const v_int32x8& idxvec)
|
||||
{
|
||||
int CV_DECL_ALIGNED(32) idx[8];
|
||||
v_store_aligned(idx, idxvec);
|
||||
return v_int32x8(_mm256_setr_epi32(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]],
|
||||
tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]));
|
||||
return v_int32x8(_mm256_i32gather_epi32(tab, idxvec.val, 4));
|
||||
}
|
||||
|
||||
inline v_uint32x8 v_lut(const unsigned* tab, const v_int32x8& idxvec)
|
||||
{
|
||||
return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec));
|
||||
}
|
||||
|
||||
inline v_float32x8 v_lut(const float* tab, const v_int32x8& idxvec)
|
||||
{
|
||||
int CV_DECL_ALIGNED(32) idx[8];
|
||||
v_store_aligned(idx, idxvec);
|
||||
return v_float32x8(_mm256_setr_ps(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]],
|
||||
tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]));
|
||||
return v_float32x8(_mm256_i32gather_ps(tab, idxvec.val, 4));
|
||||
}
|
||||
|
||||
inline v_float64x4 v_lut(const double* tab, const v_int32x8& idxvec)
|
||||
{
|
||||
int CV_DECL_ALIGNED(32) idx[8];
|
||||
v_store_aligned(idx, idxvec);
|
||||
return v_float64x4(_mm256_setr_pd(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]));
|
||||
return v_float64x4(_mm256_i32gather_pd(tab, _mm256_castsi256_si128(idxvec.val), 8));
|
||||
}
|
||||
|
||||
inline void v_lut_deinterleave(const float* tab, const v_int32x8& idxvec, v_float32x8& x, v_float32x8& y)
|
||||
|
||||
@@ -642,8 +642,6 @@ public:
|
||||
|
||||
//! returns the currently observed element
|
||||
FileNode operator *() const;
|
||||
//! accesses the currently observed element methods
|
||||
FileNode operator ->() const;
|
||||
|
||||
//! moves iterator to the next node
|
||||
FileNodeIterator& operator ++ ();
|
||||
|
||||
@@ -794,6 +794,82 @@ CV_EXPORTS InstrNode* getCurrentNode();
|
||||
#define CV_INSTRUMENT_REGION(); CV_INSTRUMENT_REGION_();
|
||||
#endif
|
||||
|
||||
namespace cv {
|
||||
|
||||
namespace utils {
|
||||
|
||||
//! @addtogroup core_utils
|
||||
//! @{
|
||||
|
||||
/** @brief Try to find requested data file
|
||||
|
||||
Search directories:
|
||||
|
||||
1. Directories passed via `addDataSearchPath()`
|
||||
2. Check path specified by configuration parameter with "_HINT" suffix (name of environment variable).
|
||||
3. Check path specified by configuration parameter (name of environment variable).
|
||||
If parameter value is not empty and nothing is found then stop searching.
|
||||
4. Detects build/install path based on:
|
||||
a. current working directory (CWD)
|
||||
b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage)
|
||||
5. Scan `<source>/{,data}` directories if build directory is detected or the current directory is in source tree.
|
||||
6. Scan `<install>/share/OpenCV` directory if install directory is detected.
|
||||
|
||||
@param relative_path Relative path to data file
|
||||
@param required Specify "file not found" handling.
|
||||
If true, function prints information message and raises cv::Exception.
|
||||
If false, function returns empty result
|
||||
@param configuration_parameter specify configuration parameter name. Default NULL value means "OPENCV_DATA_PATH".
|
||||
@return Returns path (absolute or relative to the current directory) or empty string if file is not found
|
||||
|
||||
@note Implementation is not thread-safe.
|
||||
*/
|
||||
CV_EXPORTS
|
||||
cv::String findDataFile(const cv::String& relative_path, bool required = true,
|
||||
const char* configuration_parameter = NULL);
|
||||
|
||||
/** @overload
|
||||
@param relative_path Relative path to data file
|
||||
@param configuration_parameter specify configuration parameter name. Default NULL value means "OPENCV_DATA_PATH".
|
||||
@param search_paths override addDataSearchPath() settings.
|
||||
@param subdir_paths override addDataSearchSubDirectory() settings.
|
||||
@return Returns path (absolute or relative to the current directory) or empty string if file is not found
|
||||
|
||||
@note Implementation is not thread-safe.
|
||||
*/
|
||||
CV_EXPORTS
|
||||
cv::String findDataFile(const cv::String& relative_path,
|
||||
const char* configuration_parameter,
|
||||
const std::vector<String>* search_paths,
|
||||
const std::vector<String>* subdir_paths);
|
||||
|
||||
/** @brief Override default search data path by adding new search location
|
||||
|
||||
Use this only to override default behavior
|
||||
Passed paths are used in LIFO order.
|
||||
|
||||
@param path Path to used samples data
|
||||
|
||||
@note Implementation is not thread-safe.
|
||||
*/
|
||||
CV_EXPORTS void addDataSearchPath(const cv::String& path);
|
||||
|
||||
/** @brief Append default search data sub directory
|
||||
|
||||
General usage is to add OpenCV modules name (`<opencv_contrib>/modules/<name>/data` -> `modules/<name>/data` + `<name>/data`).
|
||||
Passed subdirectories are used in LIFO order.
|
||||
|
||||
@param subdir samples data sub directory
|
||||
|
||||
@note Implementation is not thread-safe.
|
||||
*/
|
||||
CV_EXPORTS void addDataSearchSubDirectory(const cv::String& subdir);
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace cv
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif // OPENCV_CORE_PRIVATE_HPP
|
||||
|
||||
@@ -1234,8 +1234,75 @@ enum FLAGS
|
||||
CV_EXPORTS void setFlags(FLAGS modeFlags);
|
||||
static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); }
|
||||
CV_EXPORTS FLAGS getFlags();
|
||||
|
||||
} // namespace instr
|
||||
|
||||
|
||||
namespace samples {
|
||||
|
||||
//! @addtogroup core_utils_samples
|
||||
// This section describes utility functions for OpenCV samples.
|
||||
//
|
||||
// @note Implementation of these utilities is not thread-safe.
|
||||
//
|
||||
//! @{
|
||||
|
||||
/** @brief Try to find requested data file
|
||||
|
||||
Search directories:
|
||||
|
||||
1. Directories passed via `addSamplesDataSearchPath()`
|
||||
2. OPENCV_SAMPLES_DATA_PATH_HINT environment variable
|
||||
3. OPENCV_SAMPLES_DATA_PATH environment variable
|
||||
If parameter value is not empty and nothing is found then stop searching.
|
||||
4. Detects build/install path based on:
|
||||
a. current working directory (CWD)
|
||||
b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage)
|
||||
5. Scan `<source>/{,data,samples/data}` directories if build directory is detected or the current directory is in source tree.
|
||||
6. Scan `<install>/share/OpenCV` directory if install directory is detected.
|
||||
|
||||
@see cv::utils::findDataFile
|
||||
|
||||
@param relative_path Relative path to data file
|
||||
@param required Specify "file not found" handling.
|
||||
If true, function prints information message and raises cv::Exception.
|
||||
If false, function returns empty result
|
||||
@param silentMode Disables messages
|
||||
@return Returns path (absolute or relative to the current directory) or empty string if file is not found
|
||||
*/
|
||||
CV_EXPORTS_W cv::String findFile(const cv::String& relative_path, bool required = true, bool silentMode = false);
|
||||
|
||||
CV_EXPORTS_W cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode = false);
|
||||
|
||||
inline cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode)
|
||||
{
|
||||
cv::String res = findFile(relative_path, false, silentMode);
|
||||
if (res.empty())
|
||||
return relative_path;
|
||||
return res;
|
||||
}
|
||||
|
||||
/** @brief Override search data path by adding new search location
|
||||
|
||||
Use this only to override default behavior
|
||||
Passed paths are used in LIFO order.
|
||||
|
||||
@param path Path to used samples data
|
||||
*/
|
||||
CV_EXPORTS_W void addSamplesDataSearchPath(const cv::String& path);
|
||||
|
||||
/** @brief Append samples search data sub directory
|
||||
|
||||
General usage is to add OpenCV modules name (`<opencv_contrib>/modules/<name>/samples/data` -> `<name>/samples/data` + `modules/<name>/samples/data`).
|
||||
Passed subdirectories are used in LIFO order.
|
||||
|
||||
@param subdir samples data sub directory
|
||||
*/
|
||||
CV_EXPORTS_W void addSamplesDataSearchSubDirectory(const cv::String& subdir);
|
||||
|
||||
//! @}
|
||||
} // namespace samples
|
||||
|
||||
namespace utils {
|
||||
|
||||
CV_EXPORTS int getThreadID();
|
||||
|
||||
@@ -16,6 +16,13 @@ CV_EXPORTS void remove_all(const cv::String& path);
|
||||
|
||||
CV_EXPORTS cv::String getcwd();
|
||||
|
||||
/** @brief Converts path p to a canonical absolute path
|
||||
* Symlinks are processed if there is support for them on running platform.
|
||||
*
|
||||
* @param path input path. Target file/directory should exist.
|
||||
*/
|
||||
CV_EXPORTS cv::String canonical(const cv::String& path);
|
||||
|
||||
/** Join path components */
|
||||
CV_EXPORTS cv::String join(const cv::String& base, const cv::String& path);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define CV_VERSION_MAJOR 4
|
||||
#define CV_VERSION_MINOR 0
|
||||
#define CV_VERSION_REVISION 0
|
||||
#define CV_VERSION_STATUS "-rc"
|
||||
#define CV_VERSION_STATUS ""
|
||||
|
||||
#define CVAUX_STR_EXP(__A) #__A
|
||||
#define CVAUX_STR(__A) CVAUX_STR_EXP(__A)
|
||||
|
||||
@@ -297,19 +297,21 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
nidx = Scalar::all(-1);
|
||||
}
|
||||
|
||||
|
||||
if( crosscheck )
|
||||
{
|
||||
CV_Assert( K == 1 && update == 0 && mask.empty() );
|
||||
CV_Assert(!nidx.empty());
|
||||
Mat tdist, tidx;
|
||||
Mat tdist, tidx, sdist, sidx;
|
||||
batchDistance(src2, src1, tdist, dtype, tidx, normType, K, mask, 0, false);
|
||||
batchDistance(src1, src2, sdist, dtype, sidx, normType, K, mask, 0, false);
|
||||
|
||||
// if an idx-th element from src1 appeared to be the nearest to i-th element of src2,
|
||||
// we update the minimum mutual distance between idx-th element of src1 and the whole src2 set.
|
||||
// As a result, if nidx[idx] = i*, it means that idx-th element of src1 is the nearest
|
||||
// to i*-th element of src2 and i*-th element of src2 is the closest to idx-th element of src1.
|
||||
// If nidx[idx] = -1, it means that there is no such ideal couple for it in src2.
|
||||
// This O(N) procedure is called cross-check and it helps to eliminate some false matches.
|
||||
// This O(2N) procedure is called cross-check and it helps to eliminate some false matches.
|
||||
if( dtype == CV_32S )
|
||||
{
|
||||
for( int i = 0; i < tdist.rows; i++ )
|
||||
@@ -336,6 +338,13 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
}
|
||||
}
|
||||
}
|
||||
for( int i = 0; i < sdist.rows; i++ )
|
||||
{
|
||||
if( tidx.at<int>(sidx.at<int>(i)) != i )
|
||||
{
|
||||
nidx.at<int>(i) = -1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1183,9 +1183,9 @@ void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 );
|
||||
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 && _src.dims() <= 2);
|
||||
|
||||
CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2,
|
||||
CV_OCL_RUN(_dst.isUMat(),
|
||||
ocl_copyMakeBorder(_src, _dst, top, bottom, left, right, borderType, value))
|
||||
|
||||
Mat src = _src.getMat();
|
||||
|
||||
@@ -1699,7 +1699,7 @@ transform_( const T* src, T* dst, const WT* m, int len, int scn, int dcn )
|
||||
}
|
||||
}
|
||||
|
||||
#if CV_SIMD128
|
||||
#if CV_SIMD128 && !defined(__aarch64__)
|
||||
static inline void
|
||||
load3x3Matrix(const float* m, v_float32x4& m0, v_float32x4& m1, v_float32x4& m2, v_float32x4& m3)
|
||||
{
|
||||
@@ -1708,7 +1708,9 @@ load3x3Matrix(const float* m, v_float32x4& m0, v_float32x4& m1, v_float32x4& m2,
|
||||
m2 = v_float32x4(m[2], m[6], m[10], 0);
|
||||
m3 = v_float32x4(m[3], m[7], m[11], 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CV_SIMD128
|
||||
static inline v_int16x8
|
||||
v_matmulvec(const v_int16x8 &v0, const v_int16x8 &m0, const v_int16x8 &m1, const v_int16x8 &m2, const v_int32x4 &m3, const int BITS)
|
||||
{
|
||||
|
||||
@@ -2388,11 +2388,6 @@ FileNode FileNodeIterator::operator *() const
|
||||
return FileNode(idx < nodeNElems ? fs : 0, blockIdx, ofs);
|
||||
}
|
||||
|
||||
FileNode FileNodeIterator::operator ->() const
|
||||
{
|
||||
return FileNode(idx < nodeNElems ? fs : 0, blockIdx, ofs);
|
||||
}
|
||||
|
||||
FileNodeIterator& FileNodeIterator::operator ++ ()
|
||||
{
|
||||
if( idx == nodeNElems || !fs )
|
||||
|
||||
@@ -0,0 +1,398 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "../precomp.hpp"
|
||||
|
||||
#include "opencv_data_config.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
#include <opencv2/core/utils/logger.defines.hpp>
|
||||
#undef CV_LOG_STRIP_LEVEL
|
||||
#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE + 1
|
||||
#include "opencv2/core/utils/logger.hpp"
|
||||
#include "opencv2/core/utils/filesystem.hpp"
|
||||
|
||||
#include <opencv2/core/utils/configuration.private.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#undef small
|
||||
#undef min
|
||||
#undef max
|
||||
#undef abs
|
||||
#elif defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#if TARGET_OS_MAC
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace cv { namespace utils {
|
||||
|
||||
static cv::Ptr< std::vector<cv::String> > g_data_search_path;
|
||||
static cv::Ptr< std::vector<cv::String> > g_data_search_subdir;
|
||||
|
||||
static std::vector<cv::String>& _getDataSearchPath()
|
||||
{
|
||||
if (g_data_search_path.empty())
|
||||
g_data_search_path.reset(new std::vector<cv::String>());
|
||||
return *(g_data_search_path.get());
|
||||
}
|
||||
|
||||
static std::vector<cv::String>& _getDataSearchSubDirectory()
|
||||
{
|
||||
if (g_data_search_subdir.empty())
|
||||
{
|
||||
g_data_search_subdir.reset(new std::vector<cv::String>());
|
||||
g_data_search_subdir->push_back("data");
|
||||
g_data_search_subdir->push_back("");
|
||||
}
|
||||
return *(g_data_search_subdir.get());
|
||||
}
|
||||
|
||||
|
||||
CV_EXPORTS void addDataSearchPath(const cv::String& path)
|
||||
{
|
||||
if (utils::fs::isDirectory(path))
|
||||
_getDataSearchPath().push_back(path);
|
||||
}
|
||||
CV_EXPORTS void addDataSearchSubDirectory(const cv::String& subdir)
|
||||
{
|
||||
_getDataSearchSubDirectory().push_back(subdir);
|
||||
}
|
||||
|
||||
static bool isPathSep(char c)
|
||||
{
|
||||
return c == '/' || c == '\\';
|
||||
}
|
||||
static bool isSubDirectory_(const cv::String& base_path, const cv::String& path)
|
||||
{
|
||||
size_t N = base_path.size();
|
||||
if (N == 0)
|
||||
return false;
|
||||
if (isPathSep(base_path[N - 1]))
|
||||
N--;
|
||||
if (path.size() < N)
|
||||
return false;
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
if (path[i] == base_path[i])
|
||||
continue;
|
||||
if (isPathSep(path[i]) && isPathSep(base_path[i]))
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
size_t M = path.size();
|
||||
if (M > N)
|
||||
{
|
||||
if (!isPathSep(path[N]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool isSubDirectory(const cv::String& base_path, const cv::String& path)
|
||||
{
|
||||
bool res = isSubDirectory_(base_path, path);
|
||||
CV_LOG_VERBOSE(NULL, 0, "isSubDirectory(): base: " << base_path << " path: " << path << " => result: " << (res ? "TRUE" : "FALSE"));
|
||||
return res;
|
||||
}
|
||||
|
||||
static cv::String getModuleLocation(const void* addr)
|
||||
{
|
||||
CV_UNUSED(addr);
|
||||
#ifdef _WIN32
|
||||
HMODULE m = 0;
|
||||
#if _WIN32_WINNT >= 0x0501
|
||||
::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
reinterpret_cast<LPCTSTR>(addr),
|
||||
&m);
|
||||
#endif
|
||||
if (m)
|
||||
{
|
||||
char path[MAX_PATH];
|
||||
const size_t path_size = sizeof(path)/sizeof(*path);
|
||||
size_t sz = GetModuleFileNameA(m, path, path_size); // no unicode support
|
||||
if (sz > 0 && sz < path_size)
|
||||
{
|
||||
path[sz] = '\0';
|
||||
return cv::String(path);
|
||||
}
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
std::ifstream fs("/proc/self/maps");
|
||||
std::string line;
|
||||
while (std::getline(fs, line, '\n'))
|
||||
{
|
||||
long long int addr_begin = 0, addr_end = 0;
|
||||
if (2 == sscanf(line.c_str(), "%llx-%llx", &addr_begin, &addr_end))
|
||||
{
|
||||
if ((intptr_t)addr >= (intptr_t)addr_begin && (intptr_t)addr < (intptr_t)addr_end)
|
||||
{
|
||||
size_t pos = line.rfind(" "); // 2 spaces
|
||||
if (pos == cv::String::npos)
|
||||
pos = line.rfind(' '); // 1 spaces
|
||||
else
|
||||
pos++;
|
||||
if (pos == cv::String::npos)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "Can't parse module path: '" << line << '\'');
|
||||
}
|
||||
return line.substr(pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
# if TARGET_OS_MAC
|
||||
Dl_info info;
|
||||
if (0 != dladdr(addr, &info))
|
||||
{
|
||||
return cv::String(info.dli_fname);
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
// not supported, skip
|
||||
#endif
|
||||
return cv::String();
|
||||
}
|
||||
|
||||
cv::String findDataFile(const cv::String& relative_path,
|
||||
const char* configuration_parameter,
|
||||
const std::vector<String>* search_paths,
|
||||
const std::vector<String>* subdir_paths)
|
||||
{
|
||||
configuration_parameter = configuration_parameter ? configuration_parameter : "OPENCV_DATA_PATH";
|
||||
CV_LOG_DEBUG(NULL, cv::format("utils::findDataFile('%s', %s)", relative_path.c_str(), configuration_parameter));
|
||||
|
||||
#define TRY_FILE_WITH_PREFIX(prefix) \
|
||||
{ \
|
||||
cv::String path = utils::fs::join(prefix, relative_path); \
|
||||
CV_LOG_DEBUG(NULL, cv::format("... Line %d: trying open '%s'", __LINE__, path.c_str())); \
|
||||
FILE* f = fopen(path.c_str(), "rb"); \
|
||||
if(f) { \
|
||||
fclose(f); \
|
||||
return path; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
// Step 0: check current directory or absolute path at first
|
||||
TRY_FILE_WITH_PREFIX("");
|
||||
|
||||
|
||||
// Step 1
|
||||
const std::vector<cv::String>& search_path = search_paths ? *search_paths : _getDataSearchPath();
|
||||
for(size_t i = search_path.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& prefix = search_path[i - 1];
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
|
||||
const std::vector<cv::String>& search_subdir = subdir_paths ? *subdir_paths : _getDataSearchSubDirectory();
|
||||
|
||||
|
||||
// Step 2
|
||||
const cv::String configuration_parameter_s(configuration_parameter ? configuration_parameter : "");
|
||||
const cv::utils::Paths& search_hint = configuration_parameter_s.empty() ? cv::utils::Paths()
|
||||
: getConfigurationParameterPaths((configuration_parameter_s + "_HINT").c_str());
|
||||
for (size_t k = 0; k < search_hint.size(); k++)
|
||||
{
|
||||
cv::String datapath = search_hint[k];
|
||||
if (datapath.empty())
|
||||
continue;
|
||||
if (utils::fs::isDirectory(datapath))
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): trying " << configuration_parameter << "_HINT=" << datapath);
|
||||
for(size_t i = search_subdir.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& subdir = search_subdir[i - 1];
|
||||
cv::String prefix = utils::fs::join(datapath, subdir);
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_LOG_WARNING(NULL, configuration_parameter << "_HINT is specified but it is not a directory: " << datapath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Step 3
|
||||
const cv::utils::Paths& override_paths = configuration_parameter_s.empty() ? cv::utils::Paths()
|
||||
: getConfigurationParameterPaths(configuration_parameter);
|
||||
for (size_t k = 0; k < override_paths.size(); k++)
|
||||
{
|
||||
cv::String datapath = override_paths[k];
|
||||
if (datapath.empty())
|
||||
continue;
|
||||
if (utils::fs::isDirectory(datapath))
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): trying " << configuration_parameter << "=" << datapath);
|
||||
for(size_t i = search_subdir.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& subdir = search_subdir[i - 1];
|
||||
cv::String prefix = utils::fs::join(datapath, subdir);
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_LOG_WARNING(NULL, configuration_parameter << " is specified but it is not a directory: " << datapath);
|
||||
}
|
||||
}
|
||||
if (!override_paths.empty())
|
||||
{
|
||||
CV_LOG_INFO(NULL, "utils::findDataFile(): can't find data file via " << configuration_parameter << " configuration override: " << relative_path);
|
||||
return cv::String();
|
||||
}
|
||||
|
||||
|
||||
// Steps: 4, 5, 6
|
||||
cv::String cwd = utils::fs::getcwd();
|
||||
cv::String build_dir(OPENCV_BUILD_DIR);
|
||||
bool has_tested_build_directory = false;
|
||||
if (isSubDirectory(build_dir, cwd) || isSubDirectory(utils::fs::canonical(build_dir), utils::fs::canonical(cwd)))
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): the current directory is build sub-directory: " << cwd);
|
||||
const char* build_subdirs[] = { OPENCV_DATA_BUILD_DIR_SEARCH_PATHS };
|
||||
for (size_t k = 0; k < sizeof(build_subdirs)/sizeof(build_subdirs[0]); k++)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): <build>/" << build_subdirs[k]);
|
||||
cv::String datapath = utils::fs::join(build_dir, build_subdirs[k]);
|
||||
if (utils::fs::isDirectory(datapath))
|
||||
{
|
||||
for(size_t i = search_subdir.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& subdir = search_subdir[i - 1];
|
||||
cv::String prefix = utils::fs::join(datapath, subdir);
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
has_tested_build_directory = true;
|
||||
}
|
||||
|
||||
cv::String source_dir;
|
||||
cv::String try_source_dir = cwd;
|
||||
for (int levels = 0; levels < 3; ++levels)
|
||||
{
|
||||
if (utils::fs::exists(utils::fs::join(try_source_dir, "modules/core/include/opencv2/core/version.hpp")))
|
||||
{
|
||||
source_dir = try_source_dir;
|
||||
break;
|
||||
}
|
||||
try_source_dir = utils::fs::join(try_source_dir, "/..");
|
||||
}
|
||||
if (!source_dir.empty())
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): the current directory is source sub-directory: " << source_dir);
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): <source>" << source_dir);
|
||||
cv::String datapath = source_dir;
|
||||
if (utils::fs::isDirectory(datapath))
|
||||
{
|
||||
for(size_t i = search_subdir.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& subdir = search_subdir[i - 1];
|
||||
cv::String prefix = utils::fs::join(datapath, subdir);
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cv::String module_path = getModuleLocation((void*)getModuleLocation); // use code addr, doesn't work with static linkage!
|
||||
CV_LOG_DEBUG(NULL, "Detected module path: '" << module_path << '\'');
|
||||
|
||||
if (!has_tested_build_directory &&
|
||||
(isSubDirectory(build_dir, module_path) || isSubDirectory(utils::fs::canonical(build_dir), utils::fs::canonical(module_path)))
|
||||
)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): the binary module directory is build sub-directory: " << module_path);
|
||||
const char* build_subdirs[] = { OPENCV_DATA_BUILD_DIR_SEARCH_PATHS };
|
||||
for (size_t k = 0; k < sizeof(build_subdirs)/sizeof(build_subdirs[0]); k++)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): <build>/" << build_subdirs[k]);
|
||||
cv::String datapath = utils::fs::join(build_dir, build_subdirs[k]);
|
||||
if (utils::fs::isDirectory(datapath))
|
||||
{
|
||||
for(size_t i = search_subdir.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& subdir = search_subdir[i - 1];
|
||||
cv::String prefix = utils::fs::join(datapath, subdir);
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined OPENCV_INSTALL_DATA_DIR_RELATIVE
|
||||
if (!module_path.empty()) // require module path
|
||||
{
|
||||
size_t pos = module_path.rfind('/');
|
||||
if (pos == cv::String::npos)
|
||||
pos = module_path.rfind('\\');
|
||||
cv::String module_dir = (pos == cv::String::npos) ? module_path : module_path.substr(0, pos);
|
||||
const char* install_subdirs[] = { OPENCV_INSTALL_DATA_DIR_RELATIVE };
|
||||
for (size_t k = 0; k < sizeof(install_subdirs)/sizeof(install_subdirs[0]); k++)
|
||||
{
|
||||
cv::String datapath = utils::fs::join(module_dir, install_subdirs[k]);
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): trying install path (from binary path): " << datapath);
|
||||
if (utils::fs::isDirectory(datapath))
|
||||
{
|
||||
for(size_t i = search_subdir.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& subdir = search_subdir[i - 1];
|
||||
cv::String prefix = utils::fs::join(datapath, subdir);
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): ... skip, not a valid directory: " << datapath);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined OPENCV_INSTALL_PREFIX && defined OPENCV_DATA_INSTALL_PATH
|
||||
cv::String install_dir(OPENCV_INSTALL_PREFIX);
|
||||
// use core/world module path and verify that library is running from installation directory
|
||||
// It is neccessary to avoid touching of unrelated common /usr/local path
|
||||
if (module_path.empty()) // can't determine
|
||||
module_path = install_dir;
|
||||
if (isSubDirectory(install_dir, module_path) || isSubDirectory(utils::fs::canonical(install_dir), utils::fs::canonical(module_path)))
|
||||
{
|
||||
cv::String datapath = utils::fs::join(install_dir, OPENCV_DATA_INSTALL_PATH);
|
||||
if (utils::fs::isDirectory(datapath))
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "utils::findDataFile(): trying install path: " << datapath);
|
||||
for(size_t i = search_subdir.size(); i > 0; i--)
|
||||
{
|
||||
const cv::String& subdir = search_subdir[i - 1];
|
||||
cv::String prefix = utils::fs::join(datapath, subdir);
|
||||
TRY_FILE_WITH_PREFIX(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return cv::String(); // not found
|
||||
}
|
||||
|
||||
cv::String findDataFile(const cv::String& relative_path, bool required, const char* configuration_parameter)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, cv::format("cv::utils::findDataFile('%s', %s, %s)",
|
||||
relative_path.c_str(), required ? "true" : "false",
|
||||
configuration_parameter ? configuration_parameter : "NULL"));
|
||||
cv::String result = cv::utils::findDataFile(relative_path,
|
||||
configuration_parameter,
|
||||
NULL,
|
||||
NULL);
|
||||
if (result.empty() && required)
|
||||
CV_Error(cv::Error::StsError, cv::format("OpenCV: Can't find required data file: %s", relative_path.c_str()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -85,6 +85,23 @@ cv::String join(const cv::String& base, const cv::String& path)
|
||||
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
|
||||
cv::String canonical(const cv::String& path)
|
||||
{
|
||||
cv::String result;
|
||||
#ifdef _WIN32
|
||||
const char* result_str = _fullpath(NULL, path.c_str(), 0);
|
||||
#else
|
||||
const char* result_str = realpath(path.c_str(), NULL);
|
||||
#endif
|
||||
if (result_str)
|
||||
{
|
||||
result = cv::String(result_str);
|
||||
free((void*)result_str);
|
||||
}
|
||||
return result.empty() ? path : result;
|
||||
}
|
||||
|
||||
|
||||
bool exists(const cv::String& path)
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
@@ -543,11 +560,12 @@ cv::String getCacheDirectory(const char* sub_directory_name, const char* configu
|
||||
|
||||
#else
|
||||
#define NOT_IMPLEMENTED CV_Error(Error::StsNotImplemented, "");
|
||||
CV_EXPORTS bool exists(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
CV_EXPORTS void remove_all(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
CV_EXPORTS bool createDirectory(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
CV_EXPORTS bool createDirectories(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
CV_EXPORTS cv::String getCacheDirectory(const char* /*sub_directory_name*/, const char* /*configuration_name = NULL*/) { NOT_IMPLEMENTED }
|
||||
cv::String canonical(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
bool exists(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
void remove_all(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
bool createDirectory(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
bool createDirectories(const cv::String& /*path*/) { NOT_IMPLEMENTED }
|
||||
cv::String getCacheDirectory(const char* /*sub_directory_name*/, const char* /*configuration_name = NULL*/) { NOT_IMPLEMENTED }
|
||||
#undef NOT_IMPLEMENTED
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "../precomp.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <opencv2/core/utils/logger.defines.hpp>
|
||||
#undef CV_LOG_STRIP_LEVEL
|
||||
#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE + 1
|
||||
#include "opencv2/core/utils/logger.hpp"
|
||||
#include "opencv2/core/utils/filesystem.hpp"
|
||||
|
||||
namespace cv { namespace samples {
|
||||
|
||||
static cv::Ptr< std::vector<cv::String> > g_data_search_path;
|
||||
static cv::Ptr< std::vector<cv::String> > g_data_search_subdir;
|
||||
|
||||
static std::vector<cv::String>& _getDataSearchPath()
|
||||
{
|
||||
if (g_data_search_path.empty())
|
||||
g_data_search_path.reset(new std::vector<cv::String>());
|
||||
return *(g_data_search_path.get());
|
||||
}
|
||||
|
||||
static std::vector<cv::String>& _getDataSearchSubDirectory()
|
||||
{
|
||||
if (g_data_search_subdir.empty())
|
||||
{
|
||||
g_data_search_subdir.reset(new std::vector<cv::String>());
|
||||
g_data_search_subdir->push_back("samples/data");
|
||||
g_data_search_subdir->push_back("data");
|
||||
g_data_search_subdir->push_back("");
|
||||
}
|
||||
return *(g_data_search_subdir.get());
|
||||
}
|
||||
|
||||
|
||||
CV_EXPORTS void addSamplesDataSearchPath(const cv::String& path)
|
||||
{
|
||||
if (utils::fs::isDirectory(path))
|
||||
_getDataSearchPath().push_back(path);
|
||||
}
|
||||
CV_EXPORTS void addSamplesDataSearchSubDirectory(const cv::String& subdir)
|
||||
{
|
||||
_getDataSearchSubDirectory().push_back(subdir);
|
||||
}
|
||||
|
||||
cv::String findFile(const cv::String& relative_path, bool required, bool silentMode)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, cv::format("cv::samples::findFile('%s', %s)", relative_path.c_str(), required ? "true" : "false"));
|
||||
cv::String result = cv::utils::findDataFile(relative_path,
|
||||
"OPENCV_SAMPLES_DATA_PATH",
|
||||
&_getDataSearchPath(),
|
||||
&_getDataSearchSubDirectory());
|
||||
if (result != relative_path && !silentMode)
|
||||
{
|
||||
CV_LOG_WARNING(NULL, "cv::samples::findFile('" << relative_path << "') => '" << result << "'");
|
||||
}
|
||||
if (result.empty() && required)
|
||||
CV_Error(cv::Error::StsError, cv::format("OpenCV samples: Can't find required data file: %s", relative_path.c_str()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}} // namespace
|
||||
@@ -2,6 +2,7 @@
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/core/utils/logger.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
@@ -283,4 +284,21 @@ TEST(CommandLineParser, testScalar)
|
||||
EXPECT_EQ(parser.get<Scalar>("s5"), Scalar(5, -4, 3, 2));
|
||||
}
|
||||
|
||||
TEST(Samples, findFile)
|
||||
{
|
||||
cv::utils::logging::LogLevel prev = cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE);
|
||||
cv::String path;
|
||||
ASSERT_NO_THROW(path = samples::findFile("lena.jpg", false));
|
||||
EXPECT_NE(std::string(), path.c_str());
|
||||
cv::utils::logging::setLogLevel(prev);
|
||||
}
|
||||
|
||||
TEST(Samples, findFile_missing)
|
||||
{
|
||||
cv::utils::logging::LogLevel prev = cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE);
|
||||
cv::String path;
|
||||
ASSERT_ANY_THROW(path = samples::findFile("non-existed.file", true));
|
||||
cv::utils::logging::setLogLevel(prev);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
@@ -20,11 +20,6 @@ else()
|
||||
ocv_cmake_hook_append(INIT_MODULE_SOURCES_opencv_dnn "${CMAKE_CURRENT_LIST_DIR}/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake")
|
||||
endif()
|
||||
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-shadow -Wno-parentheses -Wmaybe-uninitialized -Wsign-promo
|
||||
-Wmissing-declarations -Wmissing-prototypes
|
||||
)
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4701 /wd4100)
|
||||
|
||||
if(MSVC)
|
||||
add_definitions( -D_CRT_SECURE_NO_WARNINGS=1 )
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
|
||||
@@ -33,12 +28,14 @@ if(MSVC)
|
||||
)
|
||||
else()
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow
|
||||
-Wunused-parameter -Wunused-local-typedefs -Wsign-compare -Wsign-promo
|
||||
-Wundef -Wtautological-undefined-compare -Wignored-qualifiers -Wextra
|
||||
-Wunused-function -Wunused-const-variable -Wdeprecated-declarations
|
||||
-Wunused-parameter -Wsign-compare
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_CXX11)
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-undef) # LANG_CXX11 from protobuf files
|
||||
endif()
|
||||
|
||||
if(APPLE_FRAMEWORK)
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshorten-64-to-32)
|
||||
endif()
|
||||
@@ -55,8 +52,6 @@ add_definitions(-DHAVE_PROTOBUF=1)
|
||||
|
||||
#suppress warnings in autogenerated caffe.pb.* files
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS
|
||||
-Wunused-parameter -Wundef -Wignored-qualifiers -Wno-enum-compare
|
||||
-Wdeprecated-declarations
|
||||
/wd4125 /wd4267 /wd4127 /wd4244 /wd4512 /wd4702
|
||||
/wd4456 /wd4510 /wd4610 /wd4800
|
||||
/wd4701 /wd4703 # potentially uninitialized local/pointer variable 'value' used
|
||||
|
||||
@@ -236,7 +236,7 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
int type;
|
||||
Size kernel, stride;
|
||||
int pad_l, pad_t, pad_r, pad_b;
|
||||
CV_DEPRECATED Size pad;
|
||||
CV_DEPRECATED_EXTERNAL Size pad;
|
||||
bool globalPooling;
|
||||
bool computeMaxIdx;
|
||||
String padMode;
|
||||
@@ -578,7 +578,7 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
{
|
||||
public:
|
||||
float pnorm, epsilon;
|
||||
CV_DEPRECATED bool acrossSpatial;
|
||||
CV_DEPRECATED_EXTERNAL bool acrossSpatial;
|
||||
|
||||
static Ptr<NormalizeBBoxLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
@@ -60,12 +60,13 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
struct CV_EXPORTS_W DictValue
|
||||
{
|
||||
DictValue(const DictValue &r);
|
||||
DictValue(bool i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i ? 1 : 0; } //!< Constructs integer scalar
|
||||
DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
|
||||
CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
|
||||
CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
|
||||
DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = p; } //!< Constructs integer scalar
|
||||
CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer<double,1>) { (*pd)[0] = p; } //!< Constructs floating point scalar
|
||||
CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< Constructs string scalar
|
||||
DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload
|
||||
DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload
|
||||
|
||||
template<typename TypeIter>
|
||||
static DictValue arrayInt(TypeIter begin, int size); //!< Constructs integer array
|
||||
|
||||
@@ -181,7 +181,8 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
* If this method is called after network has allocated all memory for input and output blobs
|
||||
* and before inferencing.
|
||||
*/
|
||||
CV_DEPRECATED virtual void finalize(const std::vector<Mat*> &input, std::vector<Mat> &output);
|
||||
CV_DEPRECATED_EXTERNAL
|
||||
virtual void finalize(const std::vector<Mat*> &input, std::vector<Mat> &output);
|
||||
|
||||
/** @brief Computes and sets internal parameters according to inputs, outputs and blobs.
|
||||
* @param[in] inputs vector of already allocated input blobs
|
||||
@@ -198,7 +199,8 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
* @param[out] output allocated output blobs, which will store results of the computation.
|
||||
* @param[out] internals allocated internal blobs
|
||||
*/
|
||||
CV_DEPRECATED virtual void forward(std::vector<Mat*> &input, std::vector<Mat> &output, std::vector<Mat> &internals);
|
||||
CV_DEPRECATED_EXTERNAL
|
||||
virtual void forward(std::vector<Mat*> &input, std::vector<Mat> &output, std::vector<Mat> &internals);
|
||||
|
||||
/** @brief Given the @p input blobs, computes the output @p blobs.
|
||||
* @param[in] inputs the input blobs.
|
||||
@@ -218,7 +220,8 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
* @overload
|
||||
* @deprecated Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead
|
||||
*/
|
||||
CV_DEPRECATED void finalize(const std::vector<Mat> &inputs, CV_OUT std::vector<Mat> &outputs);
|
||||
CV_DEPRECATED_EXTERNAL
|
||||
void finalize(const std::vector<Mat> &inputs, CV_OUT std::vector<Mat> &outputs);
|
||||
|
||||
/** @brief
|
||||
* @overload
|
||||
|
||||
@@ -175,8 +175,7 @@ PERF_TEST_P_(DNNTestNetwork, MobileNet_SSD_v2_TensorFlow)
|
||||
PERF_TEST_P_(DNNTestNetwork, DenseNet_121)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && (target == DNN_TARGET_OPENCL_FP16 ||
|
||||
target == DNN_TARGET_MYRIAD))
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)))
|
||||
throw SkipTestException("");
|
||||
processNet("dnn/DenseNet_121.caffemodel", "dnn/DenseNet_121.prototxt", "",
|
||||
Mat(cv::Size(224, 224), CV_32FC3));
|
||||
@@ -185,7 +184,7 @@ PERF_TEST_P_(DNNTestNetwork, DenseNet_121)
|
||||
PERF_TEST_P_(DNNTestNetwork, OpenPose_pose_coco)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
processNet("dnn/openpose_pose_coco.caffemodel", "dnn/openpose_pose_coco.prototxt", "",
|
||||
Mat(cv::Size(368, 368), CV_32FC3));
|
||||
@@ -194,7 +193,7 @@ PERF_TEST_P_(DNNTestNetwork, OpenPose_pose_coco)
|
||||
PERF_TEST_P_(DNNTestNetwork, OpenPose_pose_mpi)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
processNet("dnn/openpose_pose_mpi.caffemodel", "dnn/openpose_pose_mpi.prototxt", "",
|
||||
Mat(cv::Size(368, 368), CV_32FC3));
|
||||
@@ -203,7 +202,7 @@ PERF_TEST_P_(DNNTestNetwork, OpenPose_pose_mpi)
|
||||
PERF_TEST_P_(DNNTestNetwork, OpenPose_pose_mpi_faster_4_stages)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
// The same .caffemodel but modified .prototxt
|
||||
// See https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/src/openpose/pose/poseParameters.cpp
|
||||
@@ -230,7 +229,7 @@ PERF_TEST_P_(DNNTestNetwork, Inception_v2_SSD_TensorFlow)
|
||||
PERF_TEST_P_(DNNTestNetwork, YOLOv3)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
Mat sample = imread(findDataFile("dnn/dog416.png", false));
|
||||
Mat inp;
|
||||
@@ -241,7 +240,7 @@ PERF_TEST_P_(DNNTestNetwork, YOLOv3)
|
||||
PERF_TEST_P_(DNNTestNetwork, EAST_text_detection)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
processNet("dnn/frozen_east_text_detection.pb", "", "", Mat(cv::Size(320, 320), CV_32FC3));
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ bool UpgradeV0LayerParameter(V1LayerParameter* v0_layer_connection_,
|
||||
PoolingParameter_PoolMethod_STOCHASTIC);
|
||||
break;
|
||||
default:
|
||||
LOG(ERROR) << "Unknown pool method " << pool;
|
||||
LOG(ERROR) << "Unknown pool method " << (int)pool;
|
||||
is_fully_compatible = false;
|
||||
}
|
||||
} else {
|
||||
@@ -863,7 +863,7 @@ bool UpgradeV1LayerParameter(V1LayerParameter* v1_layer_param_,
|
||||
while (layer_param->param_size() <= i) { layer_param->add_param(); }
|
||||
layer_param->mutable_param(i)->set_name(v1_layer_param.param(i));
|
||||
}
|
||||
ParamSpec_DimCheckMode mode;
|
||||
ParamSpec_DimCheckMode mode = ParamSpec_DimCheckMode_STRICT;
|
||||
for (int i = 0; i < v1_layer_param.blob_share_mode_size(); ++i) {
|
||||
while (layer_param->param_size() <= i) { layer_param->add_param(); }
|
||||
switch (v1_layer_param.blob_share_mode(i)) {
|
||||
@@ -875,8 +875,8 @@ bool UpgradeV1LayerParameter(V1LayerParameter* v1_layer_param_,
|
||||
break;
|
||||
default:
|
||||
LOG(FATAL) << "Unknown blob_share_mode: "
|
||||
<< v1_layer_param.blob_share_mode(i);
|
||||
break;
|
||||
<< (int)v1_layer_param.blob_share_mode(i);
|
||||
CV_Error_(Error::StsError, ("Unknown blob_share_mode: %d", (int)v1_layer_param.blob_share_mode(i)));
|
||||
}
|
||||
layer_param->mutable_param(i)->set_share_mode(mode);
|
||||
}
|
||||
@@ -1102,12 +1102,12 @@ const char* UpgradeV1LayerType(const V1LayerParameter_LayerType type) {
|
||||
case V1LayerParameter_LayerType_THRESHOLD:
|
||||
return "Threshold";
|
||||
default:
|
||||
LOG(FATAL) << "Unknown V1LayerParameter layer type: " << type;
|
||||
LOG(FATAL) << "Unknown V1LayerParameter layer type: " << (int)type;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const int kProtoReadBytesLimit = INT_MAX; // Max size of 2 GB minus 1 byte.
|
||||
static const int kProtoReadBytesLimit = INT_MAX; // Max size of 2 GB minus 1 byte.
|
||||
|
||||
bool ReadProtoFromBinary(ZeroCopyInputStream* input, Message *proto) {
|
||||
CodedInputStream coded_input(input);
|
||||
|
||||
+24
-4
@@ -353,7 +353,7 @@ struct LayerPin
|
||||
|
||||
bool operator<(const LayerPin &r) const
|
||||
{
|
||||
return lid < r.lid || lid == r.lid && oid < r.oid;
|
||||
return lid < r.lid || (lid == r.lid && oid < r.oid);
|
||||
}
|
||||
|
||||
bool operator ==(const LayerPin &r) const
|
||||
@@ -428,7 +428,7 @@ struct DataLayer : public Layer
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && inputsData.size() == 1;
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && inputsData.size() == 1);
|
||||
}
|
||||
|
||||
void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE
|
||||
@@ -1665,6 +1665,23 @@ struct Net::Impl
|
||||
|
||||
if (!ieNode->net->isInitialized())
|
||||
{
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
// For networks which is built in runtime we need to specify a
|
||||
// version of it's hyperparameters.
|
||||
std::string versionTrigger = "<net name=\"TestInput\" version=\"3\" batch=\"1\">"
|
||||
"<layers>"
|
||||
"<layer name=\"data\" type=\"Input\" precision=\"FP32\" id=\"0\">"
|
||||
"<output>"
|
||||
"<port id=\"0\">"
|
||||
"<dim>1</dim>"
|
||||
"</port>"
|
||||
"</output>"
|
||||
"</layer>"
|
||||
"</layers>"
|
||||
"</net>";
|
||||
InferenceEngine::CNNNetReader reader;
|
||||
reader.ReadNetwork(versionTrigger.data(), versionTrigger.size());
|
||||
#endif
|
||||
ieNode->net->init(preferableTarget);
|
||||
ld.skip = false;
|
||||
}
|
||||
@@ -1787,8 +1804,8 @@ struct Net::Impl
|
||||
|
||||
void fuseLayers(const std::vector<LayerPin>& blobsToKeep_)
|
||||
{
|
||||
if( !fusion || preferableBackend != DNN_BACKEND_OPENCV &&
|
||||
preferableBackend != DNN_BACKEND_INFERENCE_ENGINE)
|
||||
if( !fusion || (preferableBackend != DNN_BACKEND_OPENCV &&
|
||||
preferableBackend != DNN_BACKEND_INFERENCE_ENGINE))
|
||||
return;
|
||||
|
||||
CV_TRACE_FUNCTION();
|
||||
@@ -1996,6 +2013,9 @@ struct Net::Impl
|
||||
}
|
||||
}
|
||||
|
||||
if (preferableBackend != DNN_BACKEND_OPENCV)
|
||||
continue; // Go to the next layer.
|
||||
|
||||
// the optimization #2. if there is no layer that takes max pooling layer's computed
|
||||
// max indices (and only some semantical segmentation networks might need this;
|
||||
// many others only take the maximum values), then we switch the max pooling
|
||||
|
||||
@@ -10,6 +10,7 @@ Implementation of Batch Normalization layer.
|
||||
*/
|
||||
|
||||
#include "../precomp.hpp"
|
||||
#include "layers_common.hpp"
|
||||
#include "../op_halide.hpp"
|
||||
#include "../op_inf_engine.hpp"
|
||||
#include <opencv2/dnn/shape_utils.hpp>
|
||||
@@ -150,8 +151,8 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE && haveHalide() ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine();
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide()) ||
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine());
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
@@ -284,10 +285,10 @@ public:
|
||||
v_float32x4 x1 = v_load(srcptr + i + 4);
|
||||
v_float32x4 x2 = v_load(srcptr + i + 8);
|
||||
v_float32x4 x3 = v_load(srcptr + i + 12);
|
||||
x0 = v_muladd(x0, w, b);
|
||||
x1 = v_muladd(x1, w, b);
|
||||
x2 = v_muladd(x2, w, b);
|
||||
x3 = v_muladd(x3, w, b);
|
||||
x0 = v_muladd(x0, wV, bV);
|
||||
x1 = v_muladd(x1, wV, bV);
|
||||
x2 = v_muladd(x2, wV, bV);
|
||||
x3 = v_muladd(x3, wV, bV);
|
||||
v_store(dstptr + i, x0);
|
||||
v_store(dstptr + i + 4, x1);
|
||||
v_store(dstptr + i + 8, x2);
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine();
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine());
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
@@ -107,14 +107,21 @@ public:
|
||||
inputs[i].copyTo(outputs[i]);
|
||||
}
|
||||
|
||||
virtual Ptr<BackendNode> initInfEngine(const std::vector<Ptr<BackendWrapper> >&) CV_OVERRIDE
|
||||
virtual Ptr<BackendNode> initInfEngine(const std::vector<Ptr<BackendWrapper> >& inputs) CV_OVERRIDE
|
||||
{
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
InferenceEngine::DataPtr input = infEngineDataNode(inputs[0]);
|
||||
CV_Assert(!input->dims.empty());
|
||||
|
||||
InferenceEngine::LayerParams lp;
|
||||
lp.name = name;
|
||||
lp.type = "Split";
|
||||
lp.precision = InferenceEngine::Precision::FP32;
|
||||
std::shared_ptr<InferenceEngine::SplitLayer> ieLayer(new InferenceEngine::SplitLayer(lp));
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
ieLayer->params["axis"] = format("%d", input->dims.size() - 1);
|
||||
ieLayer->params["out_sizes"] = format("%d", input->dims[0]);
|
||||
#endif
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
|
||||
@@ -105,9 +105,9 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE && haveHalide() && axis == 1 && !padding || // By channels
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() && !padding ||
|
||||
backendId == DNN_BACKEND_VKCOM && haveVulkan() && !padding;
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide() && axis == 1 && !padding) || // By channels
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() && !padding) ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan() && !padding);
|
||||
}
|
||||
|
||||
class ChannelConcatInvoker : public ParallelLoopBody
|
||||
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
else
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE ||
|
||||
backendId == DNN_BACKEND_VKCOM && haveVulkan();
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan());
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
@@ -530,6 +530,12 @@ public:
|
||||
ieLayer->_pads_end.insert(InferenceEngine::Y_AXIS, pad.height);
|
||||
ieLayer->_dilation.insert(InferenceEngine::X_AXIS, dilation.width);
|
||||
ieLayer->_dilation.insert(InferenceEngine::Y_AXIS, dilation.height);
|
||||
ieLayer->params["output"] = format("%d", outCn);
|
||||
ieLayer->params["kernel"] = format("%d,%d,%d,%d", outCn, inpGroupCn, kernel.height, kernel.width);
|
||||
ieLayer->params["pads_begin"] = format("%d,%d", pad.height, pad.width);
|
||||
ieLayer->params["pads_end"] = format("%d,%d", pad.height, pad.width);
|
||||
ieLayer->params["strides"] = format("%d,%d", stride.height, stride.width);
|
||||
ieLayer->params["dilations"] = format("%d,%d", dilation.height, dilation.width);
|
||||
#else
|
||||
ieLayer->_kernel_x = kernel.width;
|
||||
ieLayer->_kernel_y = kernel.height;
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && crop_ranges.size() == 4;
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && crop_ranges.size() == 4);
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
@@ -156,6 +156,14 @@ public:
|
||||
|
||||
CV_Assert(crop_ranges.size() == 4);
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
ieLayer->axis.push_back(i);
|
||||
ieLayer->offset.push_back(crop_ranges[i].start);
|
||||
ieLayer->dim.push_back(crop_ranges[i].end - crop_ranges[i].start);
|
||||
}
|
||||
#else
|
||||
ieLayer->axis.push_back(0); // batch
|
||||
ieLayer->offset.push_back(crop_ranges[0].start);
|
||||
ieLayer->dim.push_back(crop_ranges[0].end - crop_ranges[0].start);
|
||||
@@ -171,7 +179,7 @@ public:
|
||||
ieLayer->axis.push_back(2); // width
|
||||
ieLayer->offset.push_back(crop_ranges[3].start);
|
||||
ieLayer->dim.push_back(crop_ranges[3].end - crop_ranges[3].start);
|
||||
|
||||
#endif
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
|
||||
@@ -198,7 +198,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized && !_clip;
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized && !_clip);
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#include "../op_halide.hpp"
|
||||
#include "../op_inf_engine.hpp"
|
||||
#include "../op_vkcom.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <opencv2/dnn/shape_utils.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && (op != SUM || coeffs.empty());
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && (op != SUM || coeffs.empty()));
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine();
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine());
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -123,8 +123,8 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE && haveHalide() && axis == 1 ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() && axis == 1;
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide() && axis == 1) ||
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() && axis == 1);
|
||||
}
|
||||
|
||||
virtual bool setActivation(const Ptr<ActivationLayer>& layer) CV_OVERRIDE
|
||||
@@ -449,6 +449,9 @@ public:
|
||||
std::shared_ptr<InferenceEngine::FullyConnectedLayer> ieLayer(new InferenceEngine::FullyConnectedLayer(lp));
|
||||
|
||||
ieLayer->_out_num = blobs[0].size[0];
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
ieLayer->params["out-size"] = format("%d", blobs[0].size[0]);
|
||||
#endif
|
||||
ieLayer->_weights = wrapToInfEngineBlob(blobs[0], {(size_t)blobs[0].size[0], (size_t)blobs[0].size[1], 1, 1}, InferenceEngine::Layout::OIHW);
|
||||
if (blobs.size() > 1)
|
||||
ieLayer->_biases = wrapToInfEngineBlob(blobs[1], {(size_t)ieLayer->_out_num}, InferenceEngine::Layout::C);
|
||||
|
||||
@@ -93,8 +93,8 @@ public:
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && (preferableTarget != DNN_TARGET_MYRIAD || type == CHANNEL_NRM) ||
|
||||
backendId == DNN_BACKEND_VKCOM && haveVulkan() && (size % 2 == 1) && (type == CHANNEL_NRM);
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && (preferableTarget != DNN_TARGET_MYRIAD || type == CHANNEL_NRM)) ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan() && (size % 2 == 1) && (type == CHANNEL_NRM));
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
@@ -35,8 +35,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE && haveHalide() &&
|
||||
!poolPad.width && !poolPad.height;
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide() && !poolPad.width && !poolPad.height);
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE && haveHalide() && dstRanges.size() == 4;
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide() && dstRanges.size() == 4);
|
||||
}
|
||||
|
||||
void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE
|
||||
|
||||
@@ -106,8 +106,8 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() ||
|
||||
backendId == DNN_BACKEND_VKCOM && haveVulkan();
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine()) ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan());
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -155,10 +155,10 @@ public:
|
||||
}
|
||||
else
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE && haveHalide() &&
|
||||
(type == MAX || type == AVE && !pad_t && !pad_l && !pad_b && !pad_r) ||
|
||||
backendId == DNN_BACKEND_VKCOM && haveVulkan() &&
|
||||
(type == MAX || type == AVE);
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide() &&
|
||||
(type == MAX || (type == AVE && !pad_t && !pad_l && !pad_b && !pad_r))) ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan() &&
|
||||
(type == MAX || type == AVE));
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
@@ -313,6 +313,10 @@ public:
|
||||
poolLayer->_padding.insert(InferenceEngine::Y_AXIS, pad_t);
|
||||
poolLayer->_pads_end.insert(InferenceEngine::X_AXIS, pad_r);
|
||||
poolLayer->_pads_end.insert(InferenceEngine::Y_AXIS, pad_b);
|
||||
poolLayer->params["kernel"] = format("%d,%d", kernel.height, kernel.width);
|
||||
poolLayer->params["pads_begin"] = format("%d,%d", pad_t, pad_l);
|
||||
poolLayer->params["pads_end"] = format("%d,%d", pad_b, pad_r);
|
||||
poolLayer->params["strides"] = format("%d,%d", stride.height, stride.width);
|
||||
#else
|
||||
poolLayer->_kernel_x = kernel.width;
|
||||
poolLayer->_kernel_y = kernel.height;
|
||||
@@ -380,8 +384,8 @@ public:
|
||||
src.isContinuous(), dst.isContinuous(),
|
||||
src.type() == CV_32F, src.type() == dst.type(),
|
||||
src.dims == 4, dst.dims == 4,
|
||||
((poolingType == ROI || poolingType == PSROI) && dst.size[0] ==rois.size[0] || src.size[0] == dst.size[0]),
|
||||
poolingType == PSROI || src.size[1] == dst.size[1],
|
||||
(((poolingType == ROI || poolingType == PSROI) && dst.size[0] == rois.size[0]) || src.size[0] == dst.size[0]),
|
||||
poolingType == PSROI || src.size[1] == dst.size[1],
|
||||
(mask.empty() || (mask.type() == src.type() && mask.size == dst.size)));
|
||||
|
||||
PoolingInvoker p;
|
||||
|
||||
@@ -272,8 +272,8 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() ||
|
||||
backendId == DNN_BACKEND_VKCOM && haveVulkan();
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine()) ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan());
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && preferableTarget != DNN_TARGET_MYRIAD;
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && preferableTarget != DNN_TARGET_MYRIAD);
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -175,7 +175,7 @@ public:
|
||||
std::vector<MatShape> &outputs,
|
||||
std::vector<MatShape> &internals) const CV_OVERRIDE
|
||||
{
|
||||
CV_Assert(!usePeephole && blobs.size() == 3 || usePeephole && blobs.size() == 6);
|
||||
CV_Assert((!usePeephole && blobs.size() == 3) || (usePeephole && blobs.size() == 6));
|
||||
CV_Assert(inputs.size() == 1);
|
||||
const MatShape& inp0 = inputs[0];
|
||||
|
||||
@@ -221,7 +221,7 @@ public:
|
||||
std::vector<Mat> input;
|
||||
inputs_arr.getMatVector(input);
|
||||
|
||||
CV_Assert(!usePeephole && blobs.size() == 3 || usePeephole && blobs.size() == 6);
|
||||
CV_Assert((!usePeephole && blobs.size() == 3) || (usePeephole && blobs.size() == 6));
|
||||
CV_Assert(input.size() == 1);
|
||||
const Mat& inp0 = input[0];
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine();
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine());
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -51,9 +51,14 @@ public:
|
||||
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE)
|
||||
return interpolation == "nearest" && preferableTarget != DNN_TARGET_MYRIAD;
|
||||
{
|
||||
return (interpolation == "nearest" && preferableTarget != DNN_TARGET_MYRIAD) ||
|
||||
(interpolation == "bilinear" && INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R4));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return backendId == DNN_BACKEND_OPENCV;
|
||||
}
|
||||
|
||||
@@ -160,15 +165,27 @@ public:
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
InferenceEngine::LayerParams lp;
|
||||
lp.name = name;
|
||||
lp.type = "Resample";
|
||||
lp.precision = InferenceEngine::Precision::FP32;
|
||||
|
||||
std::shared_ptr<InferenceEngine::CNNLayer> ieLayer(new InferenceEngine::CNNLayer(lp));
|
||||
ieLayer->params["type"] = "caffe.ResampleParameter.NEAREST";
|
||||
ieLayer->params["antialias"] = "0";
|
||||
std::shared_ptr<InferenceEngine::CNNLayer> ieLayer;
|
||||
if (interpolation == "nearest")
|
||||
{
|
||||
lp.type = "Resample";
|
||||
ieLayer = std::shared_ptr<InferenceEngine::CNNLayer>(new InferenceEngine::CNNLayer(lp));
|
||||
ieLayer->params["type"] = "caffe.ResampleParameter.NEAREST";
|
||||
ieLayer->params["antialias"] = "0";
|
||||
}
|
||||
else if (interpolation == "bilinear")
|
||||
{
|
||||
lp.type = "Interp";
|
||||
ieLayer = std::shared_ptr<InferenceEngine::CNNLayer>(new InferenceEngine::CNNLayer(lp));
|
||||
ieLayer->params["pad_beg"] = "0";
|
||||
ieLayer->params["pad_end"] = "0";
|
||||
ieLayer->params["align_corners"] = "0";
|
||||
}
|
||||
else
|
||||
CV_Error(Error::StsNotImplemented, "Unsupported interpolation: " + interpolation);
|
||||
ieLayer->params["width"] = cv::format("%d", outWidth);
|
||||
ieLayer->params["height"] = cv::format("%d", outHeight);
|
||||
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
|
||||
@@ -45,13 +45,13 @@ public:
|
||||
std::vector<Mat> inputs;
|
||||
inputs_arr.getMatVector(inputs);
|
||||
hasWeights = blobs.size() == 2 || (blobs.size() == 1 && !hasBias);
|
||||
CV_Assert(inputs.size() == 2 && blobs.empty() || blobs.size() == (int)hasWeights + (int)hasBias);
|
||||
CV_Assert((inputs.size() == 2 && blobs.empty()) || blobs.size() == (int)hasWeights + (int)hasBias);
|
||||
}
|
||||
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && axis == 1;
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && axis == 1);
|
||||
}
|
||||
|
||||
void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE
|
||||
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && sliceRanges.size() == 1 && sliceRanges[0].size() == 4;
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && sliceRanges.size() == 1 && sliceRanges[0].size() == 4);
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
|
||||
@@ -90,9 +90,9 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_HALIDE && haveHalide() && axisRaw == 1 ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() && !logSoftMax ||
|
||||
backendId == DNN_BACKEND_VKCOM && haveVulkan();
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide() && axisRaw == 1) ||
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() && !logSoftMax) ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan());
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
@@ -638,7 +638,7 @@ void OCL4DNNConvSpatial<Dtype>::generateKey()
|
||||
<< "p" << pad_w_ << "x" << pad_h_ << "_"
|
||||
<< "num" << num_ << "_"
|
||||
<< "M" << M_ << "_"
|
||||
<< "activ" << fused_activ_ << "_"
|
||||
<< "activ" << (int)fused_activ_ << "_"
|
||||
<< "eltwise" << fused_eltwise_ << "_"
|
||||
<< precision;
|
||||
|
||||
|
||||
@@ -508,6 +508,16 @@ void ONNXImporter::populateNet(Net dstNet)
|
||||
layerParams.set("num_output", layerParams.blobs[0].size[0]);
|
||||
layerParams.set("bias_term", node_proto.input_size() == 3);
|
||||
}
|
||||
else if (layer_type == "ConvTranspose")
|
||||
{
|
||||
CV_Assert(node_proto.input_size() >= 2);
|
||||
layerParams.type = "Deconvolution";
|
||||
for (int j = 1; j < node_proto.input_size(); j++) {
|
||||
layerParams.blobs.push_back(getBlob(node_proto, constBlobs, j));
|
||||
}
|
||||
layerParams.set("num_output", layerParams.blobs[0].size[1]);
|
||||
layerParams.set("bias_term", node_proto.input_size() == 3);
|
||||
}
|
||||
else if (layer_type == "Transpose")
|
||||
{
|
||||
layerParams.type = "Permute";
|
||||
|
||||
@@ -309,7 +309,7 @@ void InfEngineBackendNet::setTargetDevice(InferenceEngine::TargetDevice device)
|
||||
|
||||
InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() CV_NOEXCEPT
|
||||
{
|
||||
return targetDevice;
|
||||
return const_cast<const InfEngineBackendNet*>(this)->getTargetDevice();
|
||||
}
|
||||
|
||||
InferenceEngine::TargetDevice InfEngineBackendNet::getTargetDevice() const CV_NOEXCEPT
|
||||
@@ -387,6 +387,27 @@ void InfEngineBackendNet::init(int targetId)
|
||||
}
|
||||
}
|
||||
CV_Assert(!inputs.empty());
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
for (const auto& inp : inputs)
|
||||
{
|
||||
InferenceEngine::LayerParams lp;
|
||||
lp.name = inp.first;
|
||||
lp.type = "Input";
|
||||
lp.precision = InferenceEngine::Precision::FP32;
|
||||
std::shared_ptr<InferenceEngine::CNNLayer> inpLayer(new InferenceEngine::CNNLayer(lp));
|
||||
|
||||
layers.push_back(inpLayer);
|
||||
|
||||
InferenceEngine::DataPtr dataPtr = inp.second->getInputData();
|
||||
// TODO: remove precision dependency (see setInput.normalization tests)
|
||||
if (dataPtr->precision == InferenceEngine::Precision::FP32)
|
||||
{
|
||||
inpLayer->outData.assign(1, dataPtr);
|
||||
dataPtr->creatorLayer = InferenceEngine::CNNLayerWeakPtr(inpLayer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (outputs.empty())
|
||||
@@ -559,7 +580,7 @@ bool InfEngineBackendLayer::getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
bool InfEngineBackendLayer::supportBackend(int backendId)
|
||||
{
|
||||
return backendId == DNN_BACKEND_DEFAULT ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine();
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine());
|
||||
}
|
||||
|
||||
void InfEngineBackendLayer::forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs,
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
#define INF_ENGINE_RELEASE_2018R1 2018010000
|
||||
#define INF_ENGINE_RELEASE_2018R2 2018020000
|
||||
#define INF_ENGINE_RELEASE_2018R3 2018030000
|
||||
#define INF_ENGINE_RELEASE_2018R4 2018040000
|
||||
|
||||
#ifndef INF_ENGINE_RELEASE
|
||||
#warning("IE version have not been provided via command-line. Using 2018R2 by default")
|
||||
#define INF_ENGINE_RELEASE INF_ENGINE_RELEASE_2018R2
|
||||
#warning("IE version have not been provided via command-line. Using 2018R4 by default")
|
||||
#define INF_ENGINE_RELEASE INF_ENGINE_RELEASE_2018R4
|
||||
#endif
|
||||
|
||||
#define INF_ENGINE_VER_MAJOR_GT(ver) (((INF_ENGINE_RELEASE) / 10000) > ((ver) / 10000))
|
||||
|
||||
@@ -156,6 +156,7 @@ void blobFromTensor(const tensorflow::TensorProto &tensor, Mat &dstBlob)
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void printList(const tensorflow::AttrValue::ListValue &val)
|
||||
{
|
||||
std::cout << "(";
|
||||
@@ -235,6 +236,7 @@ void printLayerAttr(const tensorflow::NodeDef &layer)
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool hasLayerAttr(const tensorflow::NodeDef &layer, const std::string &name)
|
||||
{
|
||||
|
||||
@@ -37,8 +37,6 @@ using namespace tensorflow;
|
||||
using namespace ::google::protobuf;
|
||||
using namespace ::google::protobuf::io;
|
||||
|
||||
const int kProtoReadBytesLimit = INT_MAX; // Max size of 2 GB minus 1 byte.
|
||||
|
||||
void ReadTFNetParamsFromBinaryFileOrDie(const char* param_file,
|
||||
tensorflow::GraphDef* param) {
|
||||
CHECK(ReadProtoFromBinaryFile(param_file, param))
|
||||
|
||||
@@ -90,16 +90,10 @@ bool OpPool::forward(std::vector<Tensor>& ins,
|
||||
std::vector<Tensor>& blobs,
|
||||
std::vector<Tensor>& outs)
|
||||
{
|
||||
for (size_t ii = 0; ii < ins.size(); ii++)
|
||||
{
|
||||
Tensor& inpMat = ins[ii];
|
||||
int out_index = (pool_type_ == kPoolTypeMax) ? 2 : 1;
|
||||
Tensor& outMat = outs[out_index * ii];
|
||||
Tensor maskMat = (pool_type_ == kPoolTypeMax) ? outs[2 * ii + 1] : Tensor();
|
||||
if (!forward(inpMat, outMat, maskMat))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
Tensor& inpMat = ins[0];
|
||||
Tensor& outMat = outs[0];
|
||||
Tensor maskMat = outs.size() > 1 ? outs[1] : Tensor();
|
||||
return forward(inpMat, outMat, maskMat);
|
||||
}
|
||||
|
||||
bool OpPool::forward(Tensor& in, Tensor& out, Tensor& mask)
|
||||
|
||||
@@ -174,7 +174,7 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_v2_TensorFlow)
|
||||
throw SkipTestException("");
|
||||
Mat sample = imread(findDataFile("dnn/street.png", false));
|
||||
Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
|
||||
float l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.011 : 0.0;
|
||||
float l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.013 : 0.0;
|
||||
float lInf = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.062 : 0.0;
|
||||
processNet("dnn/ssd_mobilenet_v2_coco_2018_03_29.pb", "dnn/ssd_mobilenet_v2_coco_2018_03_29.pbtxt",
|
||||
inp, "detection_out", "", l1, lInf, 0.25);
|
||||
@@ -184,7 +184,7 @@ TEST_P(DNNTestNetwork, SSD_VGG16)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE && target == DNN_TARGET_CPU)
|
||||
throw SkipTestException("");
|
||||
double scoreThreshold = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.0252 : 0.0;
|
||||
double scoreThreshold = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.0325 : 0.0;
|
||||
Mat sample = imread(findDataFile("dnn/street.png", false));
|
||||
Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
|
||||
processNet("dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel",
|
||||
@@ -194,7 +194,7 @@ TEST_P(DNNTestNetwork, SSD_VGG16)
|
||||
TEST_P(DNNTestNetwork, OpenPose_pose_coco)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
processNet("dnn/openpose_pose_coco.caffemodel", "dnn/openpose_pose_coco.prototxt",
|
||||
Size(368, 368));
|
||||
@@ -203,7 +203,7 @@ TEST_P(DNNTestNetwork, OpenPose_pose_coco)
|
||||
TEST_P(DNNTestNetwork, OpenPose_pose_mpi)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
processNet("dnn/openpose_pose_mpi.caffemodel", "dnn/openpose_pose_mpi.prototxt",
|
||||
Size(368, 368));
|
||||
@@ -212,7 +212,7 @@ TEST_P(DNNTestNetwork, OpenPose_pose_mpi)
|
||||
TEST_P(DNNTestNetwork, OpenPose_pose_mpi_faster_4_stages)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
// The same .caffemodel but modified .prototxt
|
||||
// See https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/src/openpose/pose/poseParameters.cpp
|
||||
|
||||
@@ -512,7 +512,11 @@ INSTANTIATE_TEST_CASE_P(Test_Caffe, opencv_face_detector,
|
||||
|
||||
TEST_P(Test_Caffe_nets, FasterRCNN_vgg16)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE > 2018030000
|
||||
|| (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16)
|
||||
#endif
|
||||
)
|
||||
throw SkipTestException("");
|
||||
static Mat ref = (Mat_<float>(3, 7) << 0, 2, 0.949398, 99.2454, 210.141, 601.205, 462.849,
|
||||
0, 7, 0.997022, 481.841, 92.3218, 722.685, 175.953,
|
||||
|
||||
@@ -57,7 +57,7 @@ static inline void PrintTo(const cv::dnn::Backend& v, std::ostream* os)
|
||||
case DNN_BACKEND_OPENCV: *os << "OCV"; return;
|
||||
case DNN_BACKEND_VKCOM: *os << "VKCOM"; return;
|
||||
} // don't use "default:" to emit compiler warnings
|
||||
*os << "DNN_BACKEND_UNKNOWN(" << v << ")";
|
||||
*os << "DNN_BACKEND_UNKNOWN(" << (int)v << ")";
|
||||
}
|
||||
|
||||
static inline void PrintTo(const cv::dnn::Target& v, std::ostream* os)
|
||||
@@ -69,7 +69,7 @@ static inline void PrintTo(const cv::dnn::Target& v, std::ostream* os)
|
||||
case DNN_TARGET_MYRIAD: *os << "MYRIAD"; return;
|
||||
case DNN_TARGET_VULKAN: *os << "VULKAN"; return;
|
||||
} // don't use "default:" to emit compiler warnings
|
||||
*os << "DNN_TARGET_UNKNOWN(" << v << ")";
|
||||
*os << "DNN_TARGET_UNKNOWN(" << (int)v << ")";
|
||||
}
|
||||
|
||||
using opencv_test::tuple;
|
||||
@@ -237,7 +237,8 @@ namespace opencv_test {
|
||||
|
||||
using namespace cv::dnn;
|
||||
|
||||
static testing::internal::ParamGenerator<tuple<Backend, Target> > dnnBackendsAndTargets(
|
||||
static inline
|
||||
testing::internal::ParamGenerator<tuple<Backend, Target> > dnnBackendsAndTargets(
|
||||
bool withInferenceEngine = true,
|
||||
bool withHalide = false,
|
||||
bool withCpuOCV = true,
|
||||
@@ -290,4 +291,103 @@ static testing::internal::ParamGenerator<tuple<Backend, Target> > dnnBackendsAnd
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
namespace opencv_test {
|
||||
using namespace cv::dnn;
|
||||
|
||||
static inline
|
||||
testing::internal::ParamGenerator<Target> availableDnnTargets()
|
||||
{
|
||||
static std::vector<Target> targets;
|
||||
if (targets.empty())
|
||||
{
|
||||
targets.push_back(DNN_TARGET_CPU);
|
||||
#ifdef HAVE_OPENCL
|
||||
if (cv::ocl::useOpenCL())
|
||||
targets.push_back(DNN_TARGET_OPENCL);
|
||||
#endif
|
||||
}
|
||||
return testing::ValuesIn(targets);
|
||||
}
|
||||
|
||||
class DNNTestLayer : public TestWithParam<tuple<Backend, Target> >
|
||||
{
|
||||
public:
|
||||
dnn::Backend backend;
|
||||
dnn::Target target;
|
||||
double default_l1, default_lInf;
|
||||
|
||||
DNNTestLayer()
|
||||
{
|
||||
backend = (dnn::Backend)(int)get<0>(GetParam());
|
||||
target = (dnn::Target)(int)get<1>(GetParam());
|
||||
getDefaultThresholds(backend, target, &default_l1, &default_lInf);
|
||||
}
|
||||
|
||||
static void getDefaultThresholds(int backend, int target, double* l1, double* lInf)
|
||||
{
|
||||
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
|
||||
{
|
||||
*l1 = 4e-3;
|
||||
*lInf = 2e-2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*l1 = 1e-5;
|
||||
*lInf = 1e-4;
|
||||
}
|
||||
}
|
||||
|
||||
static void checkBackend(int backend, int target, Mat* inp = 0, Mat* ref = 0)
|
||||
{
|
||||
if (backend == DNN_BACKEND_OPENCV && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if (!cv::ocl::useOpenCL())
|
||||
#endif
|
||||
{
|
||||
throw SkipTestException("OpenCL is not available/disabled in OpenCV");
|
||||
}
|
||||
}
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
{
|
||||
if (!checkMyriadTarget())
|
||||
{
|
||||
throw SkipTestException("Myriad is not available/disabled in OpenCV");
|
||||
}
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE < 2018030000
|
||||
if (inp && ref && inp->size[0] != 1)
|
||||
{
|
||||
// Myriad plugin supports only batch size 1. Slice a single sample.
|
||||
if (inp->size[0] == ref->size[0])
|
||||
{
|
||||
std::vector<cv::Range> range(inp->dims, Range::all());
|
||||
range[0] = Range(0, 1);
|
||||
*inp = inp->operator()(range);
|
||||
|
||||
range = std::vector<cv::Range>(ref->dims, Range::all());
|
||||
range[0] = Range(0, 1);
|
||||
*ref = ref->operator()(range);
|
||||
}
|
||||
else
|
||||
throw SkipTestException("Myriad plugin supports only batch size 1");
|
||||
}
|
||||
#else
|
||||
if (inp && ref && inp->dims == 4 && ref->dims == 4 &&
|
||||
inp->size[0] != 1 && inp->size[0] != ref->size[0])
|
||||
throw SkipTestException("Inconsistent batch size of input and output blobs for Myriad plugin");
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void checkBackend(Mat* inp = 0, Mat* ref = 0)
|
||||
{
|
||||
checkBackend(backend, target, inp, ref);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
@@ -306,6 +306,9 @@ TEST_P(Test_Darknet_nets, TinyYoloVoc)
|
||||
// batch size 1
|
||||
testDarknetModel(config_file, weights_file, ref.rowRange(0, 2), scoreDiff, iouDiff);
|
||||
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE == 2018040000
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target != DNN_TARGET_MYRIAD)
|
||||
#endif
|
||||
// batch size 2
|
||||
testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff);
|
||||
}
|
||||
|
||||
@@ -166,6 +166,11 @@ TEST_P(Deconvolution, Accuracy)
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_CPU &&
|
||||
dilation.width == 2 && dilation.height == 2)
|
||||
throw SkipTestException("");
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE == 2018040000
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_CPU &&
|
||||
hasBias && group != 1)
|
||||
throw SkipTestException("Test is disabled for OpenVINO 2018R4");
|
||||
#endif
|
||||
|
||||
int sz[] = {inChannels, outChannels / group, kernel.height, kernel.width};
|
||||
Mat weights(4, &sz[0], CV_32F);
|
||||
|
||||
@@ -177,10 +177,20 @@ TEST_P(DNNTestOpenVINO, models)
|
||||
Target target = (dnn::Target)(int)get<0>(GetParam());
|
||||
std::string modelName = get<1>(GetParam());
|
||||
|
||||
#ifdef INF_ENGINE_RELEASE
|
||||
#if INF_ENGINE_RELEASE <= 2018030000
|
||||
if (target == DNN_TARGET_MYRIAD && (modelName == "landmarks-regression-retail-0001" ||
|
||||
modelName == "semantic-segmentation-adas-0001" ||
|
||||
modelName == "face-reidentification-retail-0001"))
|
||||
throw SkipTestException("");
|
||||
#elif INF_ENGINE_RELEASE == 2018040000
|
||||
if (modelName == "single-image-super-resolution-0034" ||
|
||||
(target == DNN_TARGET_MYRIAD && (modelName == "license-plate-recognition-barrier-0001" ||
|
||||
modelName == "landmarks-regression-retail-0009" ||
|
||||
modelName == "semantic-segmentation-adas-0001")))
|
||||
throw SkipTestException("");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
std::string precision = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? "FP16" : "FP32";
|
||||
std::string prefix = utils::fs::join("intel_models",
|
||||
|
||||
@@ -137,6 +137,10 @@ TEST_P(Test_Caffe_layers, Convolution)
|
||||
|
||||
TEST_P(Test_Caffe_layers, DeConvolution)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE == 2018040000
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_CPU)
|
||||
throw SkipTestException("Test is disabled for OpenVINO 2018R4");
|
||||
#endif
|
||||
testLayerUsingCaffeModels("layer_deconvolution", true, false);
|
||||
}
|
||||
|
||||
@@ -558,7 +562,9 @@ TEST_P(Test_Caffe_layers, FasterRCNN_Proposal)
|
||||
normAssert(outs[i].rowRange(0, numDets), ref);
|
||||
|
||||
if (numDets < outs[i].size[0])
|
||||
{
|
||||
EXPECT_EQ(countNonZero(outs[i].rowRange(numDets, outs[i].size[0])), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,9 +140,9 @@ TEST(LayerFactory, custom_layers)
|
||||
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
Mat output = net.forward();
|
||||
|
||||
if (i == 0) EXPECT_EQ(output.at<float>(0), 1);
|
||||
else if (i == 1) EXPECT_EQ(output.at<float>(0), 2);
|
||||
else if (i == 2) EXPECT_EQ(output.at<float>(0), 1);
|
||||
if (i == 0) { EXPECT_EQ(output.at<float>(0), 1); }
|
||||
else if (i == 1) { EXPECT_EQ(output.at<float>(0), 2); }
|
||||
else if (i == 2) { EXPECT_EQ(output.at<float>(0), 1); }
|
||||
}
|
||||
LayerFactory::unregisterLayer("CustomType");
|
||||
}
|
||||
|
||||
@@ -68,6 +68,12 @@ TEST_P(Test_ONNX_layers, Convolution)
|
||||
testONNXModels("two_convolution");
|
||||
}
|
||||
|
||||
TEST_P(Test_ONNX_layers, Deconvolution)
|
||||
{
|
||||
testONNXModels("deconvolution");
|
||||
testONNXModels("two_deconvolution");
|
||||
}
|
||||
|
||||
TEST_P(Test_ONNX_layers, Dropout)
|
||||
{
|
||||
testONNXModels("dropout");
|
||||
@@ -118,8 +124,8 @@ TEST_P(Test_ONNX_layers, Transpose)
|
||||
|
||||
TEST_P(Test_ONNX_layers, Multiplication)
|
||||
{
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16 ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
if ((backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) ||
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
|
||||
throw SkipTestException("");
|
||||
testONNXModels("mul");
|
||||
}
|
||||
@@ -296,7 +302,7 @@ TEST_P(Test_ONNX_nets, ResNet101_DUC_HDC)
|
||||
TEST_P(Test_ONNX_nets, TinyYolov2)
|
||||
{
|
||||
if (cvtest::skipUnstableTests ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)) {
|
||||
(backend == DNN_BACKEND_INFERENCE_ENGINE && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))) {
|
||||
throw SkipTestException("");
|
||||
}
|
||||
// output range: [-11; 8]
|
||||
|
||||
@@ -49,100 +49,4 @@
|
||||
#include "opencv2/dnn.hpp"
|
||||
#include "test_common.hpp"
|
||||
|
||||
namespace opencv_test {
|
||||
using namespace cv::dnn;
|
||||
|
||||
static testing::internal::ParamGenerator<Target> availableDnnTargets()
|
||||
{
|
||||
static std::vector<Target> targets;
|
||||
if (targets.empty())
|
||||
{
|
||||
targets.push_back(DNN_TARGET_CPU);
|
||||
#ifdef HAVE_OPENCL
|
||||
if (cv::ocl::useOpenCL())
|
||||
targets.push_back(DNN_TARGET_OPENCL);
|
||||
#endif
|
||||
}
|
||||
return testing::ValuesIn(targets);
|
||||
}
|
||||
|
||||
class DNNTestLayer : public TestWithParam<tuple<Backend, Target> >
|
||||
{
|
||||
public:
|
||||
dnn::Backend backend;
|
||||
dnn::Target target;
|
||||
double default_l1, default_lInf;
|
||||
|
||||
DNNTestLayer()
|
||||
{
|
||||
backend = (dnn::Backend)(int)get<0>(GetParam());
|
||||
target = (dnn::Target)(int)get<1>(GetParam());
|
||||
getDefaultThresholds(backend, target, &default_l1, &default_lInf);
|
||||
}
|
||||
|
||||
static void getDefaultThresholds(int backend, int target, double* l1, double* lInf)
|
||||
{
|
||||
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
|
||||
{
|
||||
*l1 = 4e-3;
|
||||
*lInf = 2e-2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*l1 = 1e-5;
|
||||
*lInf = 1e-4;
|
||||
}
|
||||
}
|
||||
|
||||
static void checkBackend(int backend, int target, Mat* inp = 0, Mat* ref = 0)
|
||||
{
|
||||
if (backend == DNN_BACKEND_OPENCV && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if (!cv::ocl::useOpenCL())
|
||||
#endif
|
||||
{
|
||||
throw SkipTestException("OpenCL is not available/disabled in OpenCV");
|
||||
}
|
||||
}
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
{
|
||||
if (!checkMyriadTarget())
|
||||
{
|
||||
throw SkipTestException("Myriad is not available/disabled in OpenCV");
|
||||
}
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE < 2018030000
|
||||
if (inp && ref && inp->size[0] != 1)
|
||||
{
|
||||
// Myriad plugin supports only batch size 1. Slice a single sample.
|
||||
if (inp->size[0] == ref->size[0])
|
||||
{
|
||||
std::vector<cv::Range> range(inp->dims, Range::all());
|
||||
range[0] = Range(0, 1);
|
||||
*inp = inp->operator()(range);
|
||||
|
||||
range = std::vector<cv::Range>(ref->dims, Range::all());
|
||||
range[0] = Range(0, 1);
|
||||
*ref = ref->operator()(range);
|
||||
}
|
||||
else
|
||||
throw SkipTestException("Myriad plugin supports only batch size 1");
|
||||
}
|
||||
#else
|
||||
if (inp && ref && inp->dims == 4 && ref->dims == 4 &&
|
||||
inp->size[0] != 1 && inp->size[0] != ref->size[0])
|
||||
throw SkipTestException("Inconsistent batch size of input and output blobs for Myriad plugin");
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void checkBackend(Mat* inp = 0, Mat* ref = 0)
|
||||
{
|
||||
checkBackend(backend, target, inp, ref);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
@@ -101,7 +101,9 @@ public:
|
||||
|
||||
string dataConfig;
|
||||
if (hasText)
|
||||
{
|
||||
ASSERT_TRUE(readFileInMemory(netConfig, dataConfig));
|
||||
}
|
||||
|
||||
net = readNetFromTensorflow(dataModel.c_str(), dataModel.size(),
|
||||
dataConfig.c_str(), dataConfig.size());
|
||||
@@ -473,7 +475,7 @@ TEST_P(Test_TensorFlow_nets, EAST_text_detection)
|
||||
double l1_geometry = default_l1, lInf_geometry = default_lInf;
|
||||
if (target == DNN_TARGET_OPENCL_FP16)
|
||||
{
|
||||
lInf_scores = 0.11;
|
||||
lInf_scores = backend == DNN_BACKEND_INFERENCE_ENGINE ? 0.16 : 0.11;
|
||||
l1_geometry = 0.28; lInf_geometry = 5.94;
|
||||
}
|
||||
else if (target == DNN_TARGET_MYRIAD)
|
||||
|
||||
@@ -136,6 +136,10 @@ TEST_P(Test_Torch_layers, run_reshape_change_batch_size)
|
||||
|
||||
TEST_P(Test_Torch_layers, run_reshape)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE == 2018040000
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
throw SkipTestException("Test is disabled for OpenVINO 2018R4");
|
||||
#endif
|
||||
runTorchNet("net_reshape_batch");
|
||||
runTorchNet("net_reshape_channels", "", false, true);
|
||||
}
|
||||
@@ -168,6 +172,10 @@ TEST_P(Test_Torch_layers, run_depth_concat)
|
||||
|
||||
TEST_P(Test_Torch_layers, run_deconv)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE == 2018040000
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
|
||||
throw SkipTestException("Test is disabled for OpenVINO 2018R4");
|
||||
#endif
|
||||
runTorchNet("net_deconv");
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Features2dTest extends OpenCVTestCase {
|
||||
writeFile(extractorCfgFile, extractorCfg);
|
||||
extractor.read(extractorCfgFile);
|
||||
|
||||
Mat imgTrain = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
|
||||
Mat imgTrain = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, Imgcodecs.IMREAD_GRAYSCALE);
|
||||
Mat imgQuery = imgTrain.submat(new Range(0, imgTrain.rows() - 100), Range.all());
|
||||
|
||||
MatOfKeyPoint trainKeypoints = new MatOfKeyPoint();
|
||||
|
||||
@@ -595,4 +595,23 @@ TEST( Features2d_FlannBasedMatcher, read_write )
|
||||
EXPECT_EQ(ymlfile, out);
|
||||
}
|
||||
|
||||
|
||||
TEST(Features2d_DMatch, issue_11855)
|
||||
{
|
||||
Mat sources = (Mat_<uchar>(2, 3) << 1, 1, 0,
|
||||
1, 1, 1);
|
||||
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
|
||||
0, 0, 0);
|
||||
|
||||
Ptr<BFMatcher> bf = BFMatcher::create(NORM_HAMMING, true);
|
||||
vector<vector<DMatch> > match;
|
||||
bf->knnMatch(sources, targets, match, 1, noArray(), true);
|
||||
|
||||
ASSERT_EQ((size_t)1, match.size());
|
||||
ASSERT_EQ((size_t)1, match[0].size());
|
||||
EXPECT_EQ(1, match[0][0].queryIdx);
|
||||
EXPECT_EQ(0, match[0][0].trainIdx);
|
||||
EXPECT_EQ(0.0f, match[0][0].distance);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
@@ -69,6 +69,7 @@ set(gapi_srcs
|
||||
src/backends/fluid/gfluidbuffer.cpp
|
||||
src/backends/fluid/gfluidbackend.cpp
|
||||
src/backends/fluid/gfluidimgproc.cpp
|
||||
src/backends/fluid/gfluidimgproc_func.dispatch.cpp
|
||||
src/backends/fluid/gfluidcore.cpp
|
||||
|
||||
# GPU Backend (currently built-in)
|
||||
@@ -77,12 +78,13 @@ set(gapi_srcs
|
||||
src/backends/gpu/ggpuimgproc.cpp
|
||||
src/backends/gpu/ggpucore.cpp
|
||||
|
||||
|
||||
# Compound
|
||||
src/backends/common/gcompoundbackend.cpp
|
||||
src/backends/common/gcompoundkernel.cpp
|
||||
)
|
||||
|
||||
ocv_add_dispatched_file(backends/fluid/gfluidimgproc_func SSE4_1 AVX2)
|
||||
|
||||
ocv_list_add_prefix(gapi_srcs "${CMAKE_CURRENT_LIST_DIR}/")
|
||||
|
||||
# For IDE users
|
||||
|
||||
@@ -4,9 +4,9 @@ if(ANDROID)
|
||||
endif()
|
||||
|
||||
set(ade_src_dir "${OpenCV_BINARY_DIR}/3rdparty/ade")
|
||||
set(ade_filename "v0.1.1c.zip")
|
||||
set(ade_subdir "ade-0.1.1c")
|
||||
set(ade_md5 "db7e6a260229ee562a1b2857df473af8")
|
||||
set(ade_filename "v0.1.1d.zip")
|
||||
set(ade_subdir "ade-0.1.1d")
|
||||
set(ade_md5 "37479d90e3a5d47f132f512b22cbe206")
|
||||
ocv_download(FILENAME ${ade_filename}
|
||||
HASH ${ade_md5}
|
||||
URL
|
||||
|
||||
@@ -12,6 +12,10 @@ specific CV algorithm. G-API provides means to define CV operations,
|
||||
construct graphs (in form of expressions) using it, and finally
|
||||
implement and run the operations for a particular backend.
|
||||
|
||||
@note G-API is a new module and now is in active development. It's API
|
||||
is volatile at the moment and there may be minor but
|
||||
compatibility-breaking changes in the future.
|
||||
|
||||
# Contents
|
||||
|
||||
G-API documentation is organized into the following chapters:
|
||||
@@ -103,7 +107,7 @@ There is a number important concepts can be outlines with this examle:
|
||||
|
||||
<!-- FIXME: The above operator|() link links to MatExpr not GAPI -->
|
||||
|
||||
See Tutorial[TBD] and Porting examples[TBD] to learn more on various
|
||||
G-API features and concepts.
|
||||
See [tutorials and porting examples](@ref tutorial_table_of_content_gapi)
|
||||
to learn more on various G-API features and concepts.
|
||||
|
||||
<!-- TODO Add chapter on declaration, compilation, execution -->
|
||||
|
||||
@@ -10,6 +10,18 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
/** \defgroup gapi G-API framework
|
||||
@{
|
||||
@defgroup gapi_main_classes G-API Main Classes
|
||||
@defgroup gapi_data_objects G-API Data Objects
|
||||
@{
|
||||
@defgroup gapi_meta_args G-API Metadata Descriptors
|
||||
@}
|
||||
@defgroup gapi_std_backends G-API Standard backends
|
||||
@defgroup gapi_compile_args G-API Graph Compilation Arguments
|
||||
@}
|
||||
*/
|
||||
|
||||
#include "opencv2/gapi/gmat.hpp"
|
||||
#include "opencv2/gapi/garray.hpp"
|
||||
#include "opencv2/gapi/gcomputation.hpp"
|
||||
|
||||
@@ -144,6 +144,12 @@ namespace core {
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GPhase, <GMat(GMat, GMat, bool)>, "org.opencv.core.math.phase") {
|
||||
static GMatDesc outMeta(const GMatDesc &inx, const GMatDesc &, bool) {
|
||||
return inx;
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GMask, <GMat(GMat,GMat)>, "org.opencv.core.pixelwise.mask") {
|
||||
static GMatDesc outMeta(GMatDesc in, GMatDesc) {
|
||||
return in;
|
||||
@@ -447,6 +453,12 @@ namespace core {
|
||||
return rdepth < 0 ? in : in.withDepth(rdepth);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GSqrt, <GMat(GMat)>, "org.opencv.core.math.sqrt") {
|
||||
static GMatDesc outMeta(GMatDesc in) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//! @addtogroup gapi_math
|
||||
@@ -738,6 +750,35 @@ in radians (which is by default), or in degrees.
|
||||
*/
|
||||
GAPI_EXPORTS std::tuple<GMat, GMat> cartToPolar(const GMat& x, const GMat& y,
|
||||
bool angleInDegrees = false);
|
||||
|
||||
/** @brief Calculates the rotation angle of 2D vectors.
|
||||
|
||||
The function cv::phase calculates the rotation angle of each 2D vector that
|
||||
is formed from the corresponding elements of x and y :
|
||||
\f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f]
|
||||
|
||||
The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 ,
|
||||
the corresponding angle(I) is set to 0.
|
||||
@param x input floating-point array of x-coordinates of 2D vectors.
|
||||
@param y input array of y-coordinates of 2D vectors; it must have the
|
||||
same size and the same type as x.
|
||||
@param angleInDegrees when true, the function calculates the angle in
|
||||
degrees, otherwise, they are measured in radians.
|
||||
@return array of vector angles; it has the same size and same type as x.
|
||||
*/
|
||||
GAPI_EXPORTS GMat phase(const GMat& x, const GMat &y, bool angleInDegrees = false);
|
||||
|
||||
/** @brief Calculates a square root of array elements.
|
||||
|
||||
The function cv::gapi::sqrt calculates a square root of each input array element.
|
||||
In case of multi-channel arrays, each channel is processed
|
||||
independently. The accuracy is approximately the same as of the built-in
|
||||
std::sqrt .
|
||||
@param src input floating-point array.
|
||||
@return output array of the same size and type as src.
|
||||
*/
|
||||
GAPI_EXPORTS GMat sqrt(const GMat &src);
|
||||
|
||||
//! @} gapi_math
|
||||
//!
|
||||
//! @addtogroup gapi_pixelwise
|
||||
|
||||
@@ -33,7 +33,37 @@ namespace gapi
|
||||
{
|
||||
namespace cpu
|
||||
{
|
||||
/**
|
||||
* \addtogroup gapi_std_backends
|
||||
* @{
|
||||
*
|
||||
* @brief G-API backends available in this OpenCV version
|
||||
*
|
||||
* G-API backends play a corner stone role in G-API execution
|
||||
* stack. Every backend is hardware-oriented and thus can run its
|
||||
* kernels efficiently on the target platform.
|
||||
*
|
||||
* Backends are usually "back boxes" for G-API users -- on the API
|
||||
* side, all backends are represented as different objects of the
|
||||
* same class cv::gapi::GBackend. User can manipulate with backends
|
||||
* mainly by specifying which kernels to use or where to look up
|
||||
* for kernels first.
|
||||
*
|
||||
* @sa @ref gapi_hld, cv::gapi::lookup_order()
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get a reference to CPU (OpenCV) backend.
|
||||
*
|
||||
* This is the default backend in G-API at the moment, providing
|
||||
* broader functional coverage but losing some graph model
|
||||
* advantages. Provided mostly for reference and prototyping
|
||||
* purposes.
|
||||
*
|
||||
* @sa gapi_std_backends
|
||||
*/
|
||||
GAPI_EXPORTS cv::gapi::GBackend backend();
|
||||
/** @} */
|
||||
} // namespace cpu
|
||||
} // namespace gapi
|
||||
|
||||
|
||||
+5
-4
@@ -5,10 +5,11 @@
|
||||
// Copyright (C) 2018 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_GFLUIDCORE_HPP
|
||||
#define OPENCV_GAPI_GFLUIDCORE_HPP
|
||||
#ifndef OPENCV_GAPI_FLUID_CORE_HPP
|
||||
#define OPENCV_GAPI_FLUID_CORE_HPP
|
||||
|
||||
#include "opencv2/gapi/fluid/gfluidkernel.hpp"
|
||||
#include <opencv2/gapi/gkernel.hpp> // GKernelPackage
|
||||
#include <opencv2/gapi/own/exports.hpp> // GAPI_EXPORTS
|
||||
|
||||
namespace cv { namespace gapi { namespace core { namespace fluid {
|
||||
|
||||
@@ -16,4 +17,4 @@ GAPI_EXPORTS GKernelPackage kernels();
|
||||
|
||||
}}}}
|
||||
|
||||
#endif // OPENCV_GAPI_GFLUIDCORE_HPP
|
||||
#endif // OPENCV_GAPI_FLUID_CORE_HPP
|
||||
@@ -28,10 +28,21 @@ namespace gapi
|
||||
{
|
||||
namespace fluid
|
||||
{
|
||||
/**
|
||||
* \addtogroup gapi_std_backends G-API Standard backends
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Get a reference to Fluid backend.
|
||||
*
|
||||
* @sa gapi_std_backends
|
||||
*/
|
||||
GAPI_EXPORTS cv::gapi::GBackend backend();
|
||||
/** @} */
|
||||
} // namespace flud
|
||||
} // namespace gapi
|
||||
|
||||
|
||||
class GAPI_EXPORTS GFluidKernel
|
||||
{
|
||||
public:
|
||||
|
||||
+5
-4
@@ -5,10 +5,11 @@
|
||||
// Copyright (C) 2018 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_GFLUIDIMGPROC_HPP
|
||||
#define OPENCV_GAPI_GFLUIDIMGPROC_HPP
|
||||
#ifndef OPENCV_GAPI_FLUID_IMGPROC_HPP
|
||||
#define OPENCV_GAPI_FLUID_IMGPROC_HPP
|
||||
|
||||
#include "opencv2/gapi/fluid/gfluidkernel.hpp"
|
||||
#include <opencv2/gapi/gkernel.hpp> // GKernelPackage
|
||||
#include <opencv2/gapi/own/exports.hpp> // GAPI_EXPORTS
|
||||
|
||||
namespace cv { namespace gapi { namespace imgproc { namespace fluid {
|
||||
|
||||
@@ -16,4 +17,4 @@ GAPI_EXPORTS GKernelPackage kernels();
|
||||
|
||||
}}}}
|
||||
|
||||
#endif // OPENCV_GAPI_GFLUIDIMGPROC_HPP
|
||||
#endif // OPENCV_GAPI_FLUID_IMGPROC_HPP
|
||||
@@ -29,6 +29,10 @@ struct GOrigin;
|
||||
|
||||
template<typename T> class GArray;
|
||||
|
||||
/**
|
||||
* \addtogroup gapi_meta_args
|
||||
* @{
|
||||
*/
|
||||
struct GArrayDesc
|
||||
{
|
||||
// FIXME: Body
|
||||
@@ -36,7 +40,9 @@ struct GArrayDesc
|
||||
bool operator== (const GArrayDesc&) const { return true; }
|
||||
};
|
||||
template<typename U> GArrayDesc descr_of(const std::vector<U> &) { return {};}
|
||||
inline GArrayDesc empty_array_desc() {return {}; }
|
||||
static inline GArrayDesc empty_array_desc() {return {}; }
|
||||
/** @} */
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const cv::GArrayDesc &desc);
|
||||
|
||||
namespace detail
|
||||
@@ -218,6 +224,10 @@ namespace detail
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
/** \addtogroup gapi_data_objects
|
||||
* @{
|
||||
*/
|
||||
|
||||
template<typename T> class GArray
|
||||
{
|
||||
public:
|
||||
@@ -234,6 +244,8 @@ private:
|
||||
detail::GArrayU m_ref;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
} // namespace cv
|
||||
|
||||
#endif // OPENCV_GAPI_GARRAY_HPP
|
||||
|
||||
@@ -53,6 +53,41 @@ namespace detail {
|
||||
// CompileArg is an unified interface over backend-specific compilation
|
||||
// information
|
||||
// FIXME: Move to a separate file?
|
||||
/** \addtogroup gapi_compile_args
|
||||
* @{
|
||||
*
|
||||
* @brief Compilation arguments: a set of data structures which can be
|
||||
* passed to control compilation process
|
||||
*
|
||||
* G-API comes with a number of graph compilation options which can be
|
||||
* passed to cv::GComputation::apply() or
|
||||
* cv::GComputation::compile(). Known compilation options are listed
|
||||
* in this page, while extra backends may introduce their own
|
||||
* compilation options (G-API transparently accepts _everything_ which
|
||||
* can be passed to cv::compile_args(), it depends on underlying
|
||||
* backends if an option would be interpreted or not).
|
||||
*
|
||||
* For example, if an example computation is executed like this:
|
||||
*
|
||||
* @snippet modules/gapi/samples/api_ref_snippets.cpp graph_decl_apply
|
||||
*
|
||||
* Extra parameter specifying which kernels to compile with can be
|
||||
* passed like this:
|
||||
*
|
||||
* @snippet modules/gapi/samples/api_ref_snippets.cpp apply_with_param
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Represents an arbitrary compilation argument.
|
||||
*
|
||||
* Any value can be wrapped into cv::GCompileArg, but only known ones
|
||||
* (to G-API or its backends) can be interpreted correctly.
|
||||
*
|
||||
* Normally objects of this class shouldn't be created manually, use
|
||||
* cv::compile_args() function which automatically wraps everything
|
||||
* passed in (a variadic template parameter pack) into a vector of
|
||||
* cv::GCompileArg objects.
|
||||
*/
|
||||
struct GAPI_EXPORTS GCompileArg
|
||||
{
|
||||
public:
|
||||
@@ -82,15 +117,28 @@ private:
|
||||
|
||||
using GCompileArgs = std::vector<GCompileArg>;
|
||||
|
||||
/**
|
||||
* Wraps a list of arguments (a parameter pack) into a vector of
|
||||
* compilation arguments (cv::GCompileArg).
|
||||
*/
|
||||
template<typename... Ts> GCompileArgs compile_args(Ts&&... args)
|
||||
{
|
||||
return GCompileArgs{ GCompileArg(args)... };
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Ask G-API to dump compiled graph in Graphviz format under
|
||||
* the given file name.
|
||||
*
|
||||
* Specifies a graph dump path (path to .dot file to be generated).
|
||||
* G-API will dump a .dot file under specified path during a
|
||||
* compilation process if this flag is passed.
|
||||
*/
|
||||
struct graph_dump_path
|
||||
{
|
||||
std::string m_dump_path;
|
||||
};
|
||||
/** @} */
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user