├── .gitignore
├── CMakeLists.txt
├── LICENSE
├── README.md
├── Win64
├── DemoMatting
│ ├── DemoMatting.vcxproj
│ ├── DemoMatting.vcxproj.filters
│ └── DemoMatting.vcxproj.user
├── ovmatting.sln
└── ovmatting
│ ├── dllmain.cpp
│ ├── framework.h
│ ├── ovmatting.vcxproj
│ ├── ovmatting.vcxproj.filters
│ ├── ovmatting.vcxproj.user
│ ├── pch.cpp
│ └── pch.h
├── demo.py
├── demo1.py
├── include
├── cnn.hpp
├── cnn_backgroundv2.hpp
├── cnn_modnet.hpp
├── common.hpp
├── ext_ops.hpp
├── ns_bmp.hpp
├── ns_register.hpp
├── ns_thread.hpp
├── ns_utils.hpp
├── ocv_common.hpp
├── ovmatter.h
├── ovmatter_base_impl.hpp
├── ovmatter_bgv2_impl.hpp
├── ovmatter_modnet_impl.hpp
└── samples.hpp
├── libovmatting
└── CMakeLists.txt
├── main.cpp
├── run.sh
├── samples
├── inference_camera.cpp
├── inference_demo1.cpp
├── inference_modnet.cpp
└── inference_video.cpp
├── share
├── modnet.bin
├── modnet.xml
├── pytorch_mobilenetv2.bin
├── pytorch_mobilenetv2.xml
├── replace.jpg
├── src.mp4
└── src.png
└── src
├── cnn.cpp
├── cnn_backgroundv2.cpp
├── cnn_modnet.cpp
├── ext_ops.cpp
├── ns_bmp.cpp
├── ns_register.cpp
├── ns_thread.cpp
├── ns_utils.cpp
├── ovmatter.cpp
├── ovmatter_base_impl.cpp
├── ovmatter_bgv2_impl.cpp
└── ovmatter_modnet_impl.cpp
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | .svn
35 | .vscode
36 | **/build/
37 | **/.vs
38 | **/x64
39 | **/dst.mp4
40 | **/bxg1.png
41 | **/bxg1.mp4
42 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.10)
3 |
4 | add_subdirectory(libovmatting)
5 |
6 | project(sample)
7 |
8 | set(CMAKE_CXX_STANDARD 11)
9 | #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/out/debug)
10 | #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/out/release)
11 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
12 |
13 | set(TARGET_NAME "sample")
14 |
15 | include_directories(${PROJECT_SOURCE_DIR}/include)
16 | message("Root Directory:${PROJECT_SOURCE_DIR}")
17 |
18 | find_package(ngraph REQUIRED OPTIONAL_COMPONENTS onnx_importer)
19 | find_package(InferenceEngine REQUIRED)
20 | find_package(OpenCV REQUIRED)
21 |
22 | LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/build)
23 |
24 |
25 | file(GLOB NATIVE_SRCS ${PROJECT_SOURCE_DIR}/main.cpp ${PROJECT_SOURCE_DIR}/samples/*.cpp)
26 | # set(SRC ${PROJECT_SOURCE_DIR}/src/*.cpp )
27 | # file(GLOB NATIVE_SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/main.cpp)
28 |
29 | ADD_EXECUTABLE(${TARGET_NAME} ${NATIVE_SRCS} "include/ovmatter.h")
30 |
31 | target_link_libraries(${TARGET_NAME} PRIVATE ovmatting)
32 |
33 | target_compile_definitions(${TARGET_NAME} PRIVATE OPENCV_IMPORT_ENABLED)
34 | target_link_libraries(${TARGET_NAME} PRIVATE opencv_core)
35 |
36 | target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_EXTENSION_API)
37 | target_link_libraries(${TARGET_NAME} PRIVATE IE::inference_engine ${NGRAPH_LIBRARIES})
38 | target_link_libraries(${TARGET_NAME} PRIVATE ${ONNX_IMPORTER_LIBRARIES})
39 | target_link_libraries(${TARGET_NAME} PRIVATE ${OpenCV_LIBS})
40 | target_compile_definitions(${TARGET_NAME} PRIVATE NGRAPH_ONNX_IMPORT_ENABLED)
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 kingpeter2015
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # libovmatting
2 | A C++ library for Background Matting using openvino and deep learning models.
3 |
4 | Now support models such as BackgroundMattingV2, MODNet.
5 |
6 | ## 1 Application scenes
7 |
8 | ...
9 |
10 | ## 2 License
11 | The code of libovmatting is released under the MIT License.
12 |
13 | ## 3 Development environment
14 | CentOS 7
15 | Ubuntu
16 | Windows 10
17 |
18 | ## 4 Usage
19 | ### 4.1 Install openvino
20 | Please refer https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html
21 | Use version: openvino_2021.2.185
22 |
23 | ### 4.2 Build libovmatting library and test program
24 | Clone the project
25 | $git clone https://github.com/kingpeter2015/libovmatting.git
26 |
27 | #### 4.2.1 Ubuntu/CentOS
28 |
29 | $cd libovmatting
30 | $mkdir build
31 | $cmake ..
32 | $make
33 |
34 | Run the test program
35 | $cd ./build/
36 | $LD_LIBRARY_PATH=./:$(LD_LIBRARY_PATH) ./sample
37 |
38 | #### 4.2.2 Windows 10
39 | Install Visual Studio 2019
40 | open Win64\ovmatting.sln
41 | build and run in the Visual Studio IDE
42 |
43 | ## 5 About Source Code
44 |
45 | ### 5.1 Directory Structure
46 |
47 | * Win64: Windows Solution and projects
48 | * include: contains header files. **ovmatter.h is api header file**
49 | * libovmatting: CMakefiles for compile libovmatting.so under linux
50 | * samples: four samples using libovmatting library
51 | * share: contains model files which are used by openvino inference engine.
52 | * src: contains source code files
53 |
54 | main.cpp: startup point of demos
55 |
56 | ### 5.2 Please Attention !!!
57 |
58 | * 'include/ovmatter.h' is one only sdk header file which exposes api to applications.
59 | * libovmatting library only supports two matting method: METHOD_BACKGROUND_MATTING_V2 and METHOD_MODNET. They are defined in include/ovmatter.h
60 | * METHOD_BACKGROUND_MATTING_V2 method uses cnn model defined 'pytorch_mobilenetv2.bin/pytorch_mobilenetv2.xml'.
61 | * METHOD_MODNET method uses cnn model defined in 'modnet.bin/modnet.xml'
62 |
63 | if you want to use your own model, you can do following steps:
64 | * Add a enum item in enum OV_MATTER_API MattingMethod which is defined in include/ovmatter.h
65 | * declare and implement a new ovmatter class, and inherit 'MatterBaseImpl', then write a new cnn that uses your own models
66 |
67 | That's all, have fun !
68 |
69 | ## 6 Reference
70 | OpenVINO https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html
71 | BackgroundMattingV2 https://github.com/PeterL1n/BackgroundMattingV2
72 | MODNet https://github.com/ZHKKKe/MODNet
73 |
--------------------------------------------------------------------------------
/Win64/DemoMatting/DemoMatting.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | x64
7 |
8 |
9 | Release
10 | x64
11 |
12 |
13 |
14 | 16.0
15 | Win32Proj
16 | {2faea063-7fb6-4695-8471-42c5353c965c}
17 | DemoMatting
18 | 10.0
19 |
20 |
21 |
22 | Application
23 | true
24 | v142
25 | MultiByte
26 |
27 |
28 | Application
29 | false
30 | v142
31 | true
32 | MultiByte
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | true
48 |
49 |
50 | false
51 |
52 |
53 |
54 | Level3
55 | true
56 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
57 | true
58 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\external\tbb\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include;C:\Program Files (x86)\Intel\openvino_2021\opencv\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include\ngraph\frontend;..\..\include
59 | 4244;4251;4267;4275;26451;26495;26812;
60 |
61 |
62 | Console
63 | true
64 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\lib\intel64\Debug;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\lib;C:\Program Files (x86)\Intel\openvino_2021\opencv\lib;C:\Program Files (x86)\Intel\openvino_2021\inference_engine\external\tbb\lib;..\x64\Debug
65 | ovmatting.lib;inference_engined.lib;inference_engine_c_apid.lib;inference_engine_ir_readerd.lib;inference_engine_legacyd.lib;inference_engine_lp_transformationsd.lib;inference_engine_onnx_readerd.lib;inference_engine_preprocd.lib;inference_engine_transformationsd.lib;ngraphd.lib;onnx_importerd.lib;opencv_calib3d451d.lib;opencv_core451d.lib;opencv_dnn451d.lib;opencv_features2d451d.lib;opencv_flann451d.lib;opencv_gapi451d.lib;opencv_highgui451d.lib;opencv_imgcodecs451d.lib;opencv_imgproc451d.lib;opencv_ml451d.lib;opencv_objdetect451d.lib;opencv_photo451d.lib;opencv_stitching451d.lib;opencv_video451d.lib;opencv_videoio451d.lib;tbb.lib;tbbbind.lib;tbbmalloc.lib;tbbmalloc_proxy.lib;tbbproxy.lib;tbb_preview.lib;%(AdditionalDependencies)
66 |
67 |
68 |
69 |
70 | Level3
71 | true
72 | true
73 | true
74 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
75 | true
76 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\external\tbb\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include;C:\Program Files (x86)\Intel\openvino_2021\opencv\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include\ngraph\frontend;..\..\include;
77 | 4244;4251;4267;4275;26451;26495;26812;
78 |
79 |
80 | Console
81 | true
82 | true
83 | true
84 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\lib\intel64\Release;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\lib;C:\Program Files (x86)\Intel\openvino_2021\opencv\lib;C:\Program Files (x86)\Intel\openvino_2021\inference_engine\external\tbb\lib;..\x64\Release
85 | ovmatting.lib;inference_engine.lib;inference_engine_c_api.lib;inference_engine_ir_reader.lib;inference_engine_legacy.lib;inference_engine_lp_transformations.lib;inference_engine_onnx_reader.lib;inference_engine_preproc.lib;inference_engine_transformations.lib;ngraph.lib;onnx_importer.lib;opencv_calib3d451.lib;opencv_core451.lib;opencv_dnn451.lib;opencv_features2d451.lib;opencv_flann451.lib;opencv_gapi451.lib;opencv_highgui451.lib;opencv_imgcodecs451.lib;opencv_imgproc451.lib;opencv_ml451.lib;opencv_objdetect451.lib;opencv_photo451.lib;opencv_stitching451.lib;opencv_video451.lib;opencv_videoio451.lib;tbb.lib;tbbbind.lib;tbbmalloc.lib;tbbmalloc_proxy.lib;tbbproxy.lib;tbb_preview.lib;%(AdditionalDependencies)
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/Win64/DemoMatting/DemoMatting.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Win64/DemoMatting/DemoMatting.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(TargetDir)
5 | WindowsLocalDebugger
6 | OMP_NUM_THREADS=4
7 | $(LocalDebuggerEnvironment)
8 | -method 1
9 |
10 |
11 | $(TargetDir)
12 | WindowsLocalDebugger
13 | OMP_NUM_THREADS=4
14 | $(LocalDebuggerEnvironment)
15 | -method 1
16 |
17 |
--------------------------------------------------------------------------------
/Win64/ovmatting.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30804.86
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DemoMatting", "DemoMatting\DemoMatting.vcxproj", "{2FAEA063-7FB6-4695-8471-42C5353C965C}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {01F0A09C-F8D2-418F-981B-0E2DAFB14A01} = {01F0A09C-F8D2-418F-981B-0E2DAFB14A01}
9 | EndProjectSection
10 | EndProject
11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ovmatting", "ovmatting\ovmatting.vcxproj", "{01F0A09C-F8D2-418F-981B-0E2DAFB14A01}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|x64 = Debug|x64
16 | Release|x64 = Release|x64
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {2FAEA063-7FB6-4695-8471-42C5353C965C}.Debug|x64.ActiveCfg = Debug|x64
20 | {2FAEA063-7FB6-4695-8471-42C5353C965C}.Debug|x64.Build.0 = Debug|x64
21 | {2FAEA063-7FB6-4695-8471-42C5353C965C}.Release|x64.ActiveCfg = Release|x64
22 | {2FAEA063-7FB6-4695-8471-42C5353C965C}.Release|x64.Build.0 = Release|x64
23 | {01F0A09C-F8D2-418F-981B-0E2DAFB14A01}.Debug|x64.ActiveCfg = Debug|x64
24 | {01F0A09C-F8D2-418F-981B-0E2DAFB14A01}.Debug|x64.Build.0 = Debug|x64
25 | {01F0A09C-F8D2-418F-981B-0E2DAFB14A01}.Release|x64.ActiveCfg = Release|x64
26 | {01F0A09C-F8D2-418F-981B-0E2DAFB14A01}.Release|x64.Build.0 = Release|x64
27 | EndGlobalSection
28 | GlobalSection(SolutionProperties) = preSolution
29 | HideSolutionNode = FALSE
30 | EndGlobalSection
31 | GlobalSection(ExtensibilityGlobals) = postSolution
32 | SolutionGuid = {94AE093A-B668-44B0-A122-CEE6079EBF6E}
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/Win64/ovmatting/dllmain.cpp:
--------------------------------------------------------------------------------
1 | // dllmain.cpp : Defines the entry point for the DLL application.
2 | #include "pch.h"
3 |
4 | BOOL APIENTRY DllMain( HMODULE hModule,
5 | DWORD ul_reason_for_call,
6 | LPVOID lpReserved
7 | )
8 | {
9 | switch (ul_reason_for_call)
10 | {
11 | case DLL_PROCESS_ATTACH:
12 | case DLL_THREAD_ATTACH:
13 | case DLL_THREAD_DETACH:
14 | case DLL_PROCESS_DETACH:
15 | break;
16 | }
17 | return TRUE;
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/Win64/ovmatting/framework.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
4 | // Windows Header Files
5 | #include
6 |
--------------------------------------------------------------------------------
/Win64/ovmatting/ovmatting.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | x64
7 |
8 |
9 | Release
10 | x64
11 |
12 |
13 |
14 | 16.0
15 | Win32Proj
16 | {01f0a09c-f8d2-418f-981b-0e2dafb14a01}
17 | ovmatting
18 | 10.0
19 |
20 |
21 |
22 | DynamicLibrary
23 | true
24 | v142
25 | MultiByte
26 |
27 |
28 | DynamicLibrary
29 | false
30 | v142
31 | true
32 | MultiByte
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | true
48 |
49 |
50 | false
51 |
52 |
53 |
54 | Level3
55 | true
56 | _DEBUG;OVMATTING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
57 | true
58 | NotUsing
59 | pch.h
60 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\external\tbb\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include;C:\Program Files (x86)\Intel\openvino_2021\opencv\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include\ngraph\frontend;..\..\include
61 | Default
62 | Default
63 | 4244;4251;4267;4275;26451;26495;26812;%(DisableSpecificWarnings)
64 |
65 |
66 | Windows
67 | true
68 | false
69 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\lib\intel64\Debug;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\lib;C:\Program Files (x86)\Intel\openvino_2021\opencv\lib;C:\Program Files (x86)\Intel\openvino_2021\inference_engine\external\tbb\lib;%(AdditionalLibraryDirectories)
70 | inference_engined.lib;inference_engine_c_apid.lib;inference_engine_ir_readerd.lib;inference_engine_legacyd.lib;inference_engine_lp_transformationsd.lib;inference_engine_onnx_readerd.lib;inference_engine_preprocd.lib;inference_engine_transformationsd.lib;ngraphd.lib;onnx_importerd.lib;opencv_calib3d451d.lib;opencv_core451d.lib;opencv_dnn451d.lib;opencv_features2d451d.lib;opencv_flann451d.lib;opencv_gapi451d.lib;opencv_highgui451d.lib;opencv_imgcodecs451d.lib;opencv_imgproc451d.lib;opencv_ml451d.lib;opencv_objdetect451d.lib;opencv_photo451d.lib;opencv_stitching451d.lib;opencv_video451d.lib;opencv_videoio451d.lib;tbb.lib;tbbbind.lib;tbbmalloc.lib;tbbmalloc_proxy.lib;tbbproxy.lib;tbb_preview.lib;%(AdditionalDependencies)
71 |
72 |
73 |
74 |
75 | Level3
76 | true
77 | true
78 | true
79 | NDEBUG;OVMATTING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
80 | true
81 | NotUsing
82 | pch.h
83 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\external\tbb\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include;C:\Program Files (x86)\Intel\openvino_2021\opencv\include;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\include\ngraph\frontend;..\..\include;%(AdditionalIncludeDirectories)
84 | 4244;4251;4267;4275;26451;26495;26812;%(DisableSpecificWarnings)
85 |
86 |
87 | Windows
88 | true
89 | true
90 | true
91 | false
92 | inference_engine.lib;inference_engine_c_api.lib;inference_engine_ir_reader.lib;inference_engine_legacy.lib;inference_engine_lp_transformations.lib;inference_engine_onnx_reader.lib;inference_engine_preproc.lib;inference_engine_transformations.lib;ngraph.lib;onnx_importer.lib;opencv_calib3d451.lib;opencv_core451.lib;opencv_dnn451.lib;opencv_features2d451.lib;opencv_flann451.lib;opencv_gapi451.lib;opencv_highgui451.lib;opencv_imgcodecs451.lib;opencv_imgproc451.lib;opencv_ml451.lib;opencv_objdetect451.lib;opencv_photo451.lib;opencv_stitching451.lib;opencv_video451.lib;opencv_videoio451.lib;tbb.lib;tbbbind.lib;tbbmalloc.lib;tbbmalloc_proxy.lib;tbbproxy.lib;tbb_preview.lib;%(AdditionalDependencies)
93 | C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\inference_engine\lib\intel64\Release;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\ngraph\lib;C:\Program Files (x86)\Intel\openvino_2021\opencv\lib;C:\Program Files (x86)\Intel\openvino_2021\inference_engine\external\tbb\lib
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | Create
128 | Create
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/Win64/ovmatting/ovmatting.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
11 |
12 |
13 | {556ed048-d048-4890-a5a6-4966691db9f5}
14 |
15 |
16 | {15544307-ea9d-45cd-b834-8f6f2e463d8d}
17 |
18 |
19 |
20 |
21 | headers
22 |
23 |
24 | headers
25 |
26 |
27 | headers
28 |
29 |
30 | headers
31 |
32 |
33 | headers
34 |
35 |
36 | headers
37 |
38 |
39 | headers
40 |
41 |
42 | Source Files
43 |
44 |
45 | Source Files
46 |
47 |
48 | headers
49 |
50 |
51 | headers
52 |
53 |
54 | headers
55 |
56 |
57 | headers
58 |
59 |
60 | headers
61 |
62 |
63 | headers
64 |
65 |
66 |
67 |
68 | Source Files
69 |
70 |
71 | Source Files
72 |
73 |
74 | source
75 |
76 |
77 | source
78 |
79 |
80 | source
81 |
82 |
83 | source
84 |
85 |
86 | source
87 |
88 |
89 | source
90 |
91 |
92 | source
93 |
94 |
95 | source
96 |
97 |
98 | source
99 |
100 |
101 | source
102 |
103 |
104 | source
105 |
106 |
107 |
--------------------------------------------------------------------------------
/Win64/ovmatting/ovmatting.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Win64/ovmatting/pch.cpp:
--------------------------------------------------------------------------------
1 | // pch.cpp: source file corresponding to the pre-compiled header
2 |
3 | #include "pch.h"
4 |
5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
6 |
--------------------------------------------------------------------------------
/Win64/ovmatting/pch.h:
--------------------------------------------------------------------------------
1 | // pch.h: This is a precompiled header file.
2 | // Files listed below are compiled only once, improving build performance for future builds.
3 | // This also affects IntelliSense performance, including code completion and many code browsing features.
4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds.
5 | // Do not add files here that you will be updating frequently as this negates the performance advantage.
6 |
7 | #ifndef PCH_H
8 | #define PCH_H
9 |
10 | // add headers that you want to pre-compile here
11 | #include "framework.h"
12 |
13 | #endif //PCH_H
14 |
--------------------------------------------------------------------------------
/demo.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | Copyright (c) 2018 Intel Corporation
4 |
5 | Licensed under the Apache License, Version 2.0 (the "License");
6 | you may not use this file except in compliance with the License.
7 | You may obtain a copy of the License at
8 |
9 | http://www.apache.org/licenses/LICENSE-2.0
10 |
11 | Unless required by applicable law or agreed to in writing, software
12 | distributed under the License is distributed on an "AS IS" BASIS,
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | See the License for the specific language governing permissions and
15 | limitations under the License.
16 | """
17 | from __future__ import print_function
18 | import sys
19 | import os
20 | from argparse import ArgumentParser, SUPPRESS
21 | import cv2
22 | import numpy as np
23 | import logging as log
24 | from openvino.inference_engine import IECore
25 | from PIL import Image
26 |
27 | import ngraph as ng
28 |
29 | def build_argparser():
30 | parser = ArgumentParser(add_help=False)
31 | args = parser.add_argument_group("Options")
32 | args.add_argument('-h', '--help', action='help', default=SUPPRESS, help='Show this help message and exit.')
33 | args.add_argument("-m", "--model", help="Required. Path to an .xml or .onnx file with a trained model.",
34 | required=False, type=str)
35 | args.add_argument("-i", "--input", help="Required. Path to image file.",
36 | required=False, type=str, nargs="+")
37 | args.add_argument("-l", "--cpu_extension",
38 | help="Optional. Required for CPU custom layers. "
39 | "Absolute path to a shared library with the kernels implementations.",
40 | type=str, default=None)
41 | args.add_argument("-d", "--device",
42 | help="Optional. Specify the target device to infer on; "
43 | "CPU, GPU, FPGA or MYRIAD is acceptable. "
44 | "Sample will look for a suitable plugin for device specified (CPU by default)",
45 | default="CPU", type=str)
46 | args.add_argument("--labels", help="Optional. Labels mapping file", default=None, type=str)
47 | args.add_argument("-nt", "--number_top", help="Optional. Number of top results", default=10, type=int)
48 |
49 | return parser
50 |
51 |
52 | def main():
53 | log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
54 | args = build_argparser().parse_args()
55 | log.info("Loading Inference Engine")
56 | ie = IECore()
57 |
58 | # ---1. Read a model in OpenVINO Intermediate Representation (.xml and .bin files) or ONNX (.onnx file) format ---
59 | # model = args.model
60 | model_xml = "pytorch_mobilenetv2.xml"
61 | model_bin = "pytorch_mobilenetv2.bin"
62 | log.info(f"Loading network:\n\t{model}")
63 |
64 | net = ie.read_network(model=model_xml, weights=model_bin)
65 | print("read_network Successfully")
66 |
67 | # -----------------------------------------------------------------------------------------------------
68 |
69 | # ------------- 2. Load Plugin for inference engine and extensions library if specified --------------
70 | log.info("Device info:")
71 | versions = ie.get_versions(args.device)
72 | print("{}{}".format(" " * 8, args.device))
73 | print("{}MKLDNNPlugin version ......... {}.{}".format(" " * 8, versions[args.device].major,
74 | versions[args.device].minor))
75 | print("{}Build ........... {}".format(" " * 8, versions[args.device].build_number))
76 |
77 | if args.cpu_extension and "CPU" in args.device:
78 | ie.add_extension(args.cpu_extension, "CPU")
79 | log.info("CPU extension loaded: {}".format(args.cpu_extension))
80 | # -----------------------------------------------------------------------------------------------------
81 |
82 | # --------------------------- 3. Read and preprocess input --------------------------------------------
83 |
84 | path_bgr = "./src.png"
85 | bgr = [Image.open(path_bgr).convert('RGB')]
86 | path_vid = "./src.mp4"
87 |
88 | # -----------------------------------------------------------------------------------------------------
89 |
90 | # --------------------------- 4. Configure input & output ---------------------------------------------
91 | # --------------------------- Prepare input blobs -----------------------------------------------------
92 | log.info("Preparing input blobs")
93 | assert (len(net.input_info.keys()) == 1 or len(
94 | net.input_info.keys()) == 2), "Sample supports topologies only with 1 or 2 inputs"
95 | out_blob = next(iter(net.outputs))
96 | input_name, input_info_name = "", ""
97 |
98 | for input_key in net.input_info:
99 | if len(net.input_info[input_key].layout) == 4:
100 | input_name = input_key
101 | log.info("Batch size is {}".format(net.batch_size))
102 | net.input_info[input_key].precision = 'U8'
103 | elif len(net.input_info[input_key].layout) == 2:
104 | input_info_name = input_key
105 | net.input_info[input_key].precision = 'FP32'
106 | if net.input_info[input_key].input_data.shape[1] != 3 and net.input_info[input_key].input_data.shape[1] != 6 or \
107 | net.input_info[input_key].input_data.shape[0] != 1:
108 | log.error('Invalid input info. Should be 3 or 6 values length.')
109 |
110 | data = {}
111 | data[input_name] = images
112 |
113 | if input_info_name != "":
114 | infos = np.ndarray(shape=(n, c), dtype=float)
115 | for i in range(n):
116 | infos[i, 0] = h
117 | infos[i, 1] = w
118 | infos[i, 2] = 1.0
119 | data[input_info_name] = infos
120 |
121 | # --------------------------- Prepare output blobs ----------------------------------------------------
122 | log.info('Preparing output blobs')
123 |
124 | output_name, output_info = "", net.outputs[next(iter(net.outputs.keys()))]
125 | output_ops = {op.friendly_name : op for op in ops \
126 | if op.friendly_name in net.outputs and op.get_type_name() == "DetectionOutput"}
127 | if len(output_ops) != 0:
128 | output_name, output_info = output_ops.popitem()
129 |
130 | if output_name == "":
131 | log.error("Can't find a DetectionOutput layer in the topology")
132 |
133 | output_dims = output_info.shape
134 | if len(output_dims) != 4:
135 | log.error("Incorrect output dimensions for SSD model")
136 | max_proposal_count, object_size = output_dims[2], output_dims[3]
137 |
138 | if object_size != 7:
139 | log.error("Output item should have 7 as a last dimension")
140 |
141 | output_info.precision = "FP32"
142 | # -----------------------------------------------------------------------------------------------------
143 |
144 | # --------------------------- Performing inference ----------------------------------------------------
145 | log.info("Loading model to the device")
146 | exec_net = ie.load_network(network=net, device_name=args.device)
147 | log.info("Creating infer request and starting inference")
148 | res = exec_net.infer(inputs=data)
149 | # -----------------------------------------------------------------------------------------------------
150 |
151 | # --------------------------- Read and postprocess output ---------------------------------------------
152 | log.info("Processing output blobs")
153 | res = res[out_blob]
154 | boxes, classes = {}, {}
155 | data = res[0][0]
156 | for number, proposal in enumerate(data):
157 | if proposal[2] > 0:
158 | imid = np.int(proposal[0])
159 | ih, iw = images_hw[imid]
160 | label = np.int(proposal[1])
161 | confidence = proposal[2]
162 | xmin = np.int(iw * proposal[3])
163 | ymin = np.int(ih * proposal[4])
164 | xmax = np.int(iw * proposal[5])
165 | ymax = np.int(ih * proposal[6])
166 | print("[{},{}] element, prob = {:.6} ({},{})-({},{}) batch id : {}" \
167 | .format(number, label, confidence, xmin, ymin, xmax, ymax, imid), end="")
168 | if proposal[2] > 0.5:
169 | print(" WILL BE PRINTED!")
170 | if not imid in boxes.keys():
171 | boxes[imid] = []
172 | boxes[imid].append([xmin, ymin, xmax, ymax])
173 | if not imid in classes.keys():
174 | classes[imid] = []
175 | classes[imid].append(label)
176 | else:
177 | print()
178 |
179 | for imid in classes:
180 | tmp_image = cv2.imread(args.input[imid])
181 | for box in boxes[imid]:
182 | cv2.rectangle(tmp_image, (box[0], box[1]), (box[2], box[3]), (232, 35, 244), 2)
183 | cv2.imwrite("out.bmp", tmp_image)
184 | log.info("Image out.bmp created!")
185 | # -----------------------------------------------------------------------------------------------------
186 |
187 | log.info("Execution successful\n")
188 | log.info(
189 | "This sample is an API example, for any performance measurements please use the dedicated benchmark_app tool")
190 |
191 |
192 | if __name__ == '__main__':
193 | sys.exit(main() or 0)
194 |
--------------------------------------------------------------------------------
/demo1.py:
--------------------------------------------------------------------------------
1 | import cv2
2 |
3 | cv2.namedWindow("frame") #, cv2.WINDOW_NORMAL or cv2.WINDOW_FREERATIO
4 | cap = cv2.VideoCapture(1)
5 | height, width = 720, 1280
6 | cap.set(cv2.CAP_PROP_FRAME_WIDTH ,width)
7 | cap.set(cv2.CAP_PROP_FRAME_HEIGHT,height)
8 | cap.set(cv2.CAP_PROP_FPS, 60)
9 |
10 | while(True):
11 | success, frame=cap.read()
12 | cv2.imshow("frame", frame)
13 | ckey = cv2.waitKey(10)
14 | print("press key:",ckey)
15 | if(ckey == ord('c')):
16 | break
17 |
18 | #
19 |
--------------------------------------------------------------------------------
/include/cnn.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include