From a6cbaeecde40f91ddc3ea09aa26a03ab5bbf8ba8 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Wed, 15 Mar 2017 20:39:18 +0000
Subject: [PATCH] Added support DLL (dynamic link library) - yolo_cpp_dll.dll

---
 src/yolo.c                             |    2 
 build/darknet/yolo_console_dll.sln     |   28 ++
 build/darknet/yolo_cpp_dll.vcxproj     |  286 ++++++++++++++++++++
 build/darknet/yolo_console_dll.vcxproj |  133 +++++++++
 build/darknet/yolo_cpp_dll.sln         |   28 ++
 src/network.h                          |   11 
 src/yolo_v2_class.cpp                  |  165 +++++++++++
 src/yolo_console_dll.cpp               |   57 ++++
 src/yolo_v2_class.hpp                  |  120 ++++++++
 9 files changed, 828 insertions(+), 2 deletions(-)

diff --git a/build/darknet/yolo_console_dll.sln b/build/darknet/yolo_console_dll.sln
new file mode 100644
index 0000000..e06e5a2
--- /dev/null
+++ b/build/darknet/yolo_console_dll.sln
@@ -0,0 +1,28 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yolo_console_dll", "yolo_console_dll.vcxproj", "{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Debug|x64.ActiveCfg = Debug|x64
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Debug|x64.Build.0 = Debug|x64
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Debug|x86.ActiveCfg = Debug|Win32
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Debug|x86.Build.0 = Debug|Win32
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Release|x64.ActiveCfg = Release|x64
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Release|x64.Build.0 = Release|x64
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Release|x86.ActiveCfg = Release|Win32
+		{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}.Release|x86.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal
diff --git a/build/darknet/yolo_console_dll.vcxproj b/build/darknet/yolo_console_dll.vcxproj
new file mode 100644
index 0000000..4faf7a0
--- /dev/null
+++ b/build/darknet/yolo_console_dll.vcxproj
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{4CFC8DC0-92A2-4311-B54B-2264E56A3B58}</ProjectGuid>
+    <RootNamespace>yolo_console_dll</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="Shared">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)$(Platform)\</OutDir>
+    <IntDir>$(Platform)\$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>C:\opencv_2.4.9\opencv\build\include</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <AdditionalLibraryDirectories>C:\opencv_2.4.9\opencv\build\x64\vc12\lib</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+    </ClCompile>
+    <Link>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>C:\opencv_2.4.9\opencv\build\include</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalLibraryDirectories>C:\opencv_2.4.9\opencv\build\x64\vc12\lib</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\yolo_console_dll.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <Library Include="x64\yolo_cpp_dll.lib" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/build/darknet/yolo_cpp_dll.sln b/build/darknet/yolo_cpp_dll.sln
new file mode 100644
index 0000000..4d45776
--- /dev/null
+++ b/build/darknet/yolo_cpp_dll.sln
@@ -0,0 +1,28 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yolo_cpp_dll", "yolo_cpp_dll.vcxproj", "{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Debug|x64.ActiveCfg = Debug|x64
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Debug|x64.Build.0 = Debug|x64
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Debug|x86.ActiveCfg = Debug|Win32
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Debug|x86.Build.0 = Debug|Win32
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Release|x64.ActiveCfg = Release|x64
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Release|x64.Build.0 = Release|x64
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Release|x86.ActiveCfg = Release|Win32
+		{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}.Release|x86.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal
diff --git a/build/darknet/yolo_cpp_dll.vcxproj b/build/darknet/yolo_cpp_dll.vcxproj
new file mode 100644
index 0000000..497c5df
--- /dev/null
+++ b/build/darknet/yolo_cpp_dll.vcxproj
@@ -0,0 +1,286 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{4CF5694F-12A5-4012-8D94-9A0915E9FEB5}</ProjectGuid>
+    <RootNamespace>darknet</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+    <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 8.0.props" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)$(Platform)\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)$(Platform)\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>..\..\3rdparty\include;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir);$(cudnn)\include</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>_MBCS;YOLODLL_EXPORTS;_TIMESPEC_DEFINED;_CRT_SECURE_NO_WARNINGS;GPU;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <UndefinePreprocessorDefinitions>CUDNN</UndefinePreprocessorDefinitions>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalLibraryDirectories>$(CUDA_PATH)lib\$(PlatformName);$(cudnn)\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <OutputFile>$(OutDir)\$(TargetName)$(TargetExt)</OutputFile>
+      <AdditionalDependencies>..\..\3rdparty\lib\x64\pthreadVC2.lib;cublas.lib;curand.lib;cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AssemblyDebug>true</AssemblyDebug>
+    </Link>
+    <CudaCompile>
+      <CodeGeneration>compute_30,sm_30;compute_52,sm_52</CodeGeneration>
+      <TargetMachinePlatform>64</TargetMachinePlatform>
+    </CudaCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>C:\opencv_2.4.9\opencv\build\include;..\..\3rdparty\include;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir);$(cudnn)\include</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>YOLODLL_EXPORTS;_TIMESPEC_DEFINED;_CRT_SECURE_NO_WARNINGS;GPU;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalLibraryDirectories>C:\opencv_2.4.9\opencv\build\x86\vc14\lib;C:\opencv_2.4.9\opencv\build\x86\vc12\lib;$(CUDA_PATH)lib\$(PlatformName);$(cudnn)\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalDependencies>..\..\3rdparty\lib\x86\pthreadVC2.lib;cudart.lib;cublas.lib;curand.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>..\..\3rdparty\include;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir);$(cudnn)\include</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>YOLODLL_EXPORTS;_TIMESPEC_DEFINED;_CRT_SECURE_NO_WARNINGS;GPU;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <CLanguageStandard>c11</CLanguageStandard>
+      <CppLanguageStandard>c++1y</CppLanguageStandard>
+      <PrecompiledHeaderCompileAs>CompileAsCpp</PrecompiledHeaderCompileAs>
+      <CompileAs>Default</CompileAs>
+      <UndefinePreprocessorDefinitions>
+      </UndefinePreprocessorDefinitions>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalLibraryDirectories>$(CUDA_PATH)lib\$(PlatformName);$(cudnn)\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalDependencies>..\..\3rdparty\lib\x64\pthreadVC2.lib;cublas.lib;curand.lib;cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <OutputFile>$(OutDir)\$(TargetName)$(TargetExt)</OutputFile>
+    </Link>
+    <CudaCompile>
+      <TargetMachinePlatform>64</TargetMachinePlatform>
+      <CodeGeneration>compute_30,sm_30;compute_52,sm_52</CodeGeneration>
+    </CudaCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <CudaCompile Include="..\..\src\activation_kernels.cu" />
+    <CudaCompile Include="..\..\src\avgpool_layer_kernels.cu" />
+    <CudaCompile Include="..\..\src\blas_kernels.cu" />
+    <CudaCompile Include="..\..\src\col2im_kernels.cu" />
+    <CudaCompile Include="..\..\src\convolutional_kernels.cu" />
+    <CudaCompile Include="..\..\src\crop_layer_kernels.cu" />
+    <CudaCompile Include="..\..\src\deconvolutional_kernels.cu" />
+    <CudaCompile Include="..\..\src\dropout_layer_kernels.cu" />
+    <CudaCompile Include="..\..\src\im2col_kernels.cu" />
+    <CudaCompile Include="..\..\src\maxpool_layer_kernels.cu" />
+    <CudaCompile Include="..\..\src\network_kernels.cu" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\activations.c" />
+    <ClCompile Include="..\..\src\activation_layer.c" />
+    <ClCompile Include="..\..\src\art.c" />
+    <ClCompile Include="..\..\src\avgpool_layer.c" />
+    <ClCompile Include="..\..\src\batchnorm_layer.c" />
+    <ClCompile Include="..\..\src\blas.c" />
+    <ClCompile Include="..\..\src\box.c" />
+    <ClCompile Include="..\..\src\captcha.c" />
+    <ClCompile Include="..\..\src\cifar.c" />
+    <ClCompile Include="..\..\src\classifier.c" />
+    <ClCompile Include="..\..\src\coco.c" />
+    <ClCompile Include="..\..\src\col2im.c" />
+    <ClCompile Include="..\..\src\compare.c" />
+    <ClCompile Include="..\..\src\connected_layer.c" />
+    <ClCompile Include="..\..\src\convolutional_layer.c" />
+    <ClCompile Include="..\..\src\cost_layer.c" />
+    <ClCompile Include="..\..\src\cpu_gemm.c" />
+    <ClCompile Include="..\..\src\crnn_layer.c" />
+    <ClCompile Include="..\..\src\crop_layer.c" />
+    <ClCompile Include="..\..\src\cuda.c" />
+    <ClCompile Include="..\..\src\darknet.c" />
+    <ClCompile Include="..\..\src\data.c" />
+    <ClCompile Include="..\..\src\deconvolutional_layer.c" />
+    <ClCompile Include="..\..\src\demo.c" />
+    <ClCompile Include="..\..\src\detection_layer.c" />
+    <ClCompile Include="..\..\src\detector.c" />
+    <ClCompile Include="..\..\src\dice.c" />
+    <ClCompile Include="..\..\src\dropout_layer.c" />
+    <ClCompile Include="..\..\src\gemm.c" />
+    <ClCompile Include="..\..\src\getopt.c" />
+    <ClCompile Include="..\..\src\gettimeofday.c" />
+    <ClCompile Include="..\..\src\go.c" />
+    <ClCompile Include="..\..\src\gru_layer.c" />
+    <ClCompile Include="..\..\src\im2col.c" />
+    <ClCompile Include="..\..\src\image.c" />
+    <ClCompile Include="..\..\src\layer.c" />
+    <ClCompile Include="..\..\src\list.c" />
+    <ClCompile Include="..\..\src\local_layer.c" />
+    <ClCompile Include="..\..\src\matrix.c" />
+    <ClCompile Include="..\..\src\maxpool_layer.c" />
+    <ClCompile Include="..\..\src\network.c" />
+    <ClCompile Include="..\..\src\nightmare.c" />
+    <ClCompile Include="..\..\src\normalization_layer.c" />
+    <ClCompile Include="..\..\src\option_list.c" />
+    <ClCompile Include="..\..\src\parser.c" />
+    <ClCompile Include="..\..\src\region_layer.c" />
+    <ClCompile Include="..\..\src\reorg_layer.c" />
+    <ClCompile Include="..\..\src\rnn.c" />
+    <ClCompile Include="..\..\src\rnn_layer.c" />
+    <ClCompile Include="..\..\src\rnn_vid.c" />
+    <ClCompile Include="..\..\src\route_layer.c" />
+    <ClCompile Include="..\..\src\shortcut_layer.c" />
+    <ClCompile Include="..\..\src\softmax_layer.c" />
+    <ClCompile Include="..\..\src\super.c" />
+    <ClCompile Include="..\..\src\swag.c" />
+    <ClCompile Include="..\..\src\tag.c" />
+    <ClCompile Include="..\..\src\tree.c" />
+    <ClCompile Include="..\..\src\utils.c" />
+    <ClCompile Include="..\..\src\voxel.c" />
+    <ClCompile Include="..\..\src\writing.c" />
+    <ClCompile Include="..\..\src\yolo.c" />
+    <ClCompile Include="..\..\src\yolo_v2_class.cpp" />
+    <ClCompile Include="..\..\src\yolo_v2_class.hpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\src\activations.h" />
+    <ClInclude Include="..\..\src\activation_layer.h" />
+    <ClInclude Include="..\..\src\avgpool_layer.h" />
+    <ClInclude Include="..\..\src\batchnorm_layer.h" />
+    <ClInclude Include="..\..\src\blas.h" />
+    <ClInclude Include="..\..\src\box.h" />
+    <ClInclude Include="..\..\src\classifier.h" />
+    <ClInclude Include="..\..\src\col2im.h" />
+    <ClInclude Include="..\..\src\connected_layer.h" />
+    <ClInclude Include="..\..\src\convolutional_layer.h" />
+    <ClInclude Include="..\..\src\cost_layer.h" />
+    <ClInclude Include="..\..\src\crnn_layer.h" />
+    <ClInclude Include="..\..\src\crop_layer.h" />
+    <ClInclude Include="..\..\src\cuda.h" />
+    <ClInclude Include="..\..\src\data.h" />
+    <ClInclude Include="..\..\src\deconvolutional_layer.h" />
+    <ClInclude Include="..\..\src\demo.h" />
+    <ClInclude Include="..\..\src\detection_layer.h" />
+    <ClInclude Include="..\..\src\dropout_layer.h" />
+    <ClInclude Include="..\..\src\gemm.h" />
+    <ClInclude Include="..\..\src\getopt.h" />
+    <ClInclude Include="..\..\src\gettimeofday.h" />
+    <ClInclude Include="..\..\src\gru_layer.h" />
+    <ClInclude Include="..\..\src\im2col.h" />
+    <ClInclude Include="..\..\src\image.h" />
+    <ClInclude Include="..\..\src\layer.h" />
+    <ClInclude Include="..\..\src\list.h" />
+    <ClInclude Include="..\..\src\local_layer.h" />
+    <ClInclude Include="..\..\src\matrix.h" />
+    <ClInclude Include="..\..\src\maxpool_layer.h" />
+    <ClInclude Include="..\..\src\network.h" />
+    <ClInclude Include="..\..\src\normalization_layer.h" />
+    <ClInclude Include="..\..\src\option_list.h" />
+    <ClInclude Include="..\..\src\parser.h" />
+    <ClInclude Include="..\..\src\region_layer.h" />
+    <ClInclude Include="..\..\src\reorg_layer.h" />
+    <ClInclude Include="..\..\src\rnn_layer.h" />
+    <ClInclude Include="..\..\src\route_layer.h" />
+    <ClInclude Include="..\..\src\shortcut_layer.h" />
+    <ClInclude Include="..\..\src\softmax_layer.h" />
+    <ClInclude Include="..\..\src\stb_image.h" />
+    <ClInclude Include="..\..\src\stb_image_write.h" />
+    <ClInclude Include="..\..\src\tree.h" />
+    <ClInclude Include="..\..\src\unistd.h" />
+    <ClInclude Include="..\..\src\utils.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+    <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 8.0.targets" />
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/src/network.h b/src/network.h
index e48cbc2..bb65eac 100644
--- a/src/network.h
+++ b/src/network.h
@@ -2,8 +2,13 @@
 #ifndef NETWORK_H
 #define NETWORK_H
 
-#include "image.h"
 #include "layer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "image.h"
 #include "data.h"
 #include "tree.h"
 
@@ -125,5 +130,9 @@
 int get_network_nuisance(network net);
 int get_network_background(network net);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/src/yolo.c b/src/yolo.c
index 206e468..2a9cde3 100644
--- a/src/yolo.c
+++ b/src/yolo.c
@@ -6,6 +6,7 @@
 #include "box.h"
 #include "demo.h"
 
+#ifdef OPENCV
 #pragma comment(lib, "opencv_core249.lib")  
 #pragma comment(lib, "opencv_imgproc249.lib")  
 #pragma comment(lib, "opencv_highgui249.lib")  
@@ -13,7 +14,6 @@
 //#pragma comment(lib, "opencv_photo249.lib")  
 //#pragma comment(lib, "opencv_video249.lib")  
 
-#ifdef OPENCV
 #include "opencv2/highgui/highgui_c.h"
 #endif
 
diff --git a/src/yolo_console_dll.cpp b/src/yolo_console_dll.cpp
new file mode 100644
index 0000000..00eca16
--- /dev/null
+++ b/src/yolo_console_dll.cpp
@@ -0,0 +1,57 @@
+#include <iostream>
+#include <string>
+#include <vector>
+
+//#define OPENCV
+
+#include "yolo_v2_class.hpp"	// imported functions from DLL
+
+
+#ifdef OPENCV
+#include <opencv2/opencv.hpp>			// C++
+#pragma comment(lib, "opencv_core249.lib")
+#pragma comment(lib, "opencv_imgproc249.lib")
+#pragma comment(lib, "opencv_highgui249.lib")
+void draw_boxes(cv::Mat mat_img, std::vector<bbox_t> result_vec) {
+	for (auto &i : result_vec) {
+		cv::rectangle(mat_img, cv::Rect(i.x, i.y, i.w, i.h), cv::Scalar(50, 200, 50), 3);
+	}
+	cv::imshow("window name", mat_img);
+	cv::waitKey(0);
+}
+#endif	// OPENCV
+
+
+void show_result(std::vector<bbox_t> result_vec) {
+	for (auto &i : result_vec) {
+		std::cout << "obj_id = " << i.obj_id << " - x = " << i.x << ", y = " << i.y 
+			<< ", w = " << i.w << ", h = " << i.h
+			<< ", prob = " << i.prob << std::endl;
+	}
+}
+
+
+
+int main() 
+{
+	Detector detector("yolo-voc.cfg", "yolo-voc.weights");
+
+	while (true) 
+	{
+		std::string filename;
+		std::cout << "input image filename: ";
+		std::cin >> filename;
+		if (filename.size() == 0) break;
+
+#ifdef OPENCV
+		cv::Mat mat_img = cv::imread(filename);
+		std::vector<bbox_t> result_vec = detector.detect(mat_img);
+		draw_boxes(mat_img, result_vec);
+#else
+		std::vector<bbox_t> result_vec = detector.detect(filename);
+#endif
+		show_result(result_vec);
+	}
+
+	return 0;
+}
\ No newline at end of file
diff --git a/src/yolo_v2_class.cpp b/src/yolo_v2_class.cpp
new file mode 100644
index 0000000..69cd5fc
--- /dev/null
+++ b/src/yolo_v2_class.cpp
@@ -0,0 +1,165 @@
+#include "yolo_v2_class.hpp"
+
+
+#include "network.h"
+
+extern "C" {
+#include "detection_layer.h"
+#include "region_layer.h"
+#include "cost_layer.h"
+#include "utils.h"
+#include "parser.h"
+#include "box.h"
+#include "image.h"
+#include "demo.h"
+
+#include "option_list.h"
+
+}
+//#include <sys/time.h>
+
+#include <vector>
+#include <iostream>
+
+
+#define FRAMES 3
+#define ROI_PER_DETECTOR 100
+
+
+struct detector_gpu_t{
+	float **probs;
+	box *boxes;
+	network net;
+	//image det;
+	//image det_s;
+	image images[FRAMES];
+	float *avg;
+	float *predictions[FRAMES];
+};
+
+
+
+YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_filename, int gpu_id)
+{
+	int old_gpu_index;
+	cudaGetDevice(&old_gpu_index);
+
+	detector_gpu_ptr = std::make_shared<detector_gpu_t>();
+
+	detector_gpu_t &detector_gpu = *reinterpret_cast<detector_gpu_t *>(detector_gpu_ptr.get());
+
+	cudaSetDevice(gpu_id);
+	network &net = detector_gpu.net;
+	net.gpu_index = gpu_id;
+	//gpu_index = i;
+	
+	char *cfgfile = const_cast<char *>(cfg_filename.data());
+	char *weightfile = const_cast<char *>(weight_filename.data());
+
+	net = parse_network_cfg(cfgfile);
+	if (weightfile) {
+		load_weights(&net, weightfile);
+	}
+	set_batch_network(&net, 1);
+	net.gpu_index = gpu_id;
+
+	layer l = net.layers[net.n - 1];
+	int j;
+
+	detector_gpu.avg = (float *)calloc(l.outputs, sizeof(float));
+	for (j = 0; j < FRAMES; ++j) detector_gpu.predictions[j] = (float *)calloc(l.outputs, sizeof(float));
+	for (j = 0; j < FRAMES; ++j) detector_gpu.images[j] = make_image(1, 1, 3);
+
+	detector_gpu.boxes = (box *)calloc(l.w*l.h*l.n, sizeof(box));
+	detector_gpu.probs = (float **)calloc(l.w*l.h*l.n, sizeof(float *));
+	for (j = 0; j < l.w*l.h*l.n; ++j) detector_gpu.probs[j] = (float *)calloc(l.classes, sizeof(float));
+
+	cudaSetDevice(old_gpu_index);
+}
+
+YOLODLL_API Detector::~Detector() 
+{
+	detector_gpu_t &detector_gpu = *reinterpret_cast<detector_gpu_t *>(detector_gpu_ptr.get());
+	layer l = detector_gpu.net.layers[detector_gpu.net.n - 1];
+
+	free(detector_gpu.boxes);
+	free(detector_gpu.avg);
+	free(detector_gpu.predictions);
+	for (int j = 0; j < l.w*l.h*l.n; ++j) free(detector_gpu.probs[j]);
+	free(detector_gpu.probs);
+}
+
+
+YOLODLL_API std::vector<bbox_t> Detector::detect(std::string image_filename, float thresh)
+{
+	char *input = const_cast<char *>(image_filename.data());
+	image im = load_image_color(input, 0, 0);
+
+	image_t img;
+	img.c = im.c;
+	img.data = im.data;
+	img.h = im.h;
+	img.w = im.w;
+
+	return detect(img, thresh);
+}
+
+
+YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh)
+{
+
+	detector_gpu_t &detector_gpu = *reinterpret_cast<detector_gpu_t *>(detector_gpu_ptr.get());
+	network &net = detector_gpu.net;
+	int old_gpu_index;
+	cudaGetDevice(&old_gpu_index);
+	cudaSetDevice(net.gpu_index);
+	//std::cout << "net.gpu_index = " << net.gpu_index << std::endl;
+
+	float nms = .4;
+
+	image im;
+	im.c = img.c;
+	im.data = img.data;
+	im.h = img.h;
+	im.w = img.w;
+
+	image sized = resize_image(im, net.w, net.h);
+	layer l = net.layers[net.n - 1];
+
+	//box *boxes = (box *)calloc(l.w*l.h*l.n, sizeof(box));
+	//float **probs = (float **)calloc(l.w*l.h*l.n, sizeof(float *));
+	// (int j = 0; j < l.w*l.h*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float *));
+
+	float *X = sized.data;
+
+	network_predict(net, X);
+
+	get_region_boxes(l, 1, 1, thresh, detector_gpu.probs, detector_gpu.boxes, 0, 0);
+	if (nms) do_nms_sort(detector_gpu.boxes, detector_gpu.probs, l.w*l.h*l.n, l.classes, nms);
+	//draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, names, alphabet, l.classes);
+
+	std::vector<bbox_t> bbox_vec;
+
+	for (size_t i = 0; i < (l.w*l.h*l.n); ++i) {
+		box b = detector_gpu.boxes[i];
+		int const obj_id = max_index(detector_gpu.probs[i], l.classes);
+		float const prob = detector_gpu.probs[i][obj_id];
+		
+		if (prob > thresh) 
+		{
+			bbox_t bbox;
+			bbox.x = (b.x - b.w / 2.)*im.w;
+			bbox.y = (b.y - b.h / 2.)*im.h;
+			bbox.w = b.w*im.w;
+			bbox.h = b.h*im.h;
+			bbox.obj_id = obj_id;
+			bbox.prob = prob;
+
+			bbox_vec.push_back(bbox);
+		}
+	}
+
+	cudaSetDevice(old_gpu_index);
+
+	return bbox_vec;
+}
\ No newline at end of file
diff --git a/src/yolo_v2_class.hpp b/src/yolo_v2_class.hpp
new file mode 100644
index 0000000..0116cce
--- /dev/null
+++ b/src/yolo_v2_class.hpp
@@ -0,0 +1,120 @@
+#pragma once
+#include <memory>
+#include <vector>
+
+#ifdef OPENCV
+#include <opencv2/opencv.hpp>			// C++
+#include "opencv2/highgui/highgui_c.h"	// C
+#include "opencv2/imgproc/imgproc_c.h"	// C
+#endif	// OPENCV
+
+//extern "C" {
+//#include "image.h"
+//}
+
+#ifdef YOLODLL_EXPORTS
+#define YOLODLL_API __declspec(dllexport) 
+#else
+#define YOLODLL_API __declspec(dllimport) 
+#endif
+
+struct bbox_t {
+	float x, y, w, h;
+	float prob;
+	unsigned int obj_id;
+};
+
+typedef struct {
+	int h;
+	int w;
+	int c;
+	float *data;
+} image_t;
+
+
+class Detector {
+	std::shared_ptr<void> detector_gpu_ptr;
+public:
+
+	YOLODLL_API Detector(std::string cfg_filename, std::string weight_filename, int gpu_id = 0);
+	YOLODLL_API ~Detector();
+
+	YOLODLL_API std::vector<bbox_t> Detector::detect(std::string image_filename, float thresh = 0.2);
+
+	YOLODLL_API std::vector<bbox_t> detect(image_t img, float thresh = 0.2);
+
+
+#ifdef OPENCV
+	std::vector<bbox_t> detect(cv::Mat mat, float thresh = 0.2) {
+		std::shared_ptr<image_t> image_ptr(new image_t, [](image_t *img) { free_image(*img); } );
+		*image_ptr = mat_to_image(mat);
+		return detect(*image_ptr, thresh);
+	}
+
+private:
+	static image_t mat_to_image(cv::Mat img)
+	{
+		std::shared_ptr<IplImage> ipl_small = std::make_shared<IplImage>(img);
+		image_t im_small = ipl_to_image(ipl_small.get());
+		rgbgr_image(im_small);
+		return im_small;
+	}
+
+	static image_t ipl_to_image(IplImage* src)
+	{
+		unsigned char *data = (unsigned char *)src->imageData;
+		int h = src->height;
+		int w = src->width;
+		int c = src->nChannels;
+		int step = src->widthStep;
+		image_t out = make_image_custom(w, h, c);
+		int i, j, k, count = 0;;
+
+		for (k = 0; k < c; ++k) {
+			for (i = 0; i < h; ++i) {
+				for (j = 0; j < w; ++j) {
+					out.data[count++] = data[i*step + j*c + k] / 255.;
+				}
+			}
+		}
+		return out;
+	}
+
+	static image_t make_empty_image(int w, int h, int c)
+	{
+		image_t out;
+		out.data = 0;
+		out.h = h;
+		out.w = w;
+		out.c = c;
+		return out;
+	}
+
+	static image_t make_image_custom(int w, int h, int c)
+	{
+		image_t out = make_empty_image(w, h, c);
+		out.data = (float *)calloc(h*w*c, sizeof(float));
+		return out;
+	}
+
+	static void rgbgr_image(image_t im)
+	{
+		int i;
+		for (i = 0; i < im.w*im.h; ++i) {
+			float swap = im.data[i];
+			im.data[i] = im.data[i + im.w*im.h * 2];
+			im.data[i + im.w*im.h * 2] = swap;
+		}
+	}
+
+	static void free_image(image_t m)
+	{
+		if (m.data) {
+			free(m.data);
+		}
+	}
+#endif	// OPENCV
+};
+
+
+

--
Gitblit v1.10.0