Skip to content

Commit 9d32a96

Browse files
committedJul 16, 2015
適当なdllのプロジェクトを追加
1 parent c1a4763 commit 9d32a96

6 files changed

+1082
-0
lines changed
 

‎waifu2x-caffe-dll/Source.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "waifu2x.h"
4+
5+
6+
__declspec(dllexport)
7+
void* Waifu2xInit(const char *mode, const int noise_level, const char *model_dir, const char *process, const int crop_size = 128, const int batch_size = 1)
8+
{
9+
Waifu2x *obj = new Waifu2x();
10+
11+
char *argv[] = { "" };
12+
13+
if (obj->init(1, argv, mode, noise_level, model_dir, process, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK)
14+
{
15+
delete obj;
16+
return nullptr;
17+
}
18+
19+
return obj;
20+
}
21+
22+
__declspec(dllexport)
23+
bool Waifu2xProcess(void *waifu2xObj, int factor, const uint32_t* source, uint32_t* dest, int width, int height)
24+
{
25+
if (!waifu2xObj)
26+
return false;
27+
28+
Waifu2x *obj = (Waifu2x *)waifu2xObj;
29+
30+
return obj->waifu2x(factor, source, dest, width, height) == Waifu2x::eWaifu2xError_OK;
31+
}
32+
33+
__declspec(dllexport)
34+
void Waifu2xDestory(void *waifu2xObj)
35+
{
36+
if (waifu2xObj)
37+
{
38+
Waifu2x *obj = (Waifu2x *)waifu2xObj;
39+
delete obj;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|x64">
9+
<Configuration>Release</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}</ProjectGuid>
15+
<Keyword>Win32Proj</Keyword>
16+
<RootNamespace>waifu2x-caffe-dll</RootNamespace>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
20+
<ConfigurationType>DynamicLibrary</ConfigurationType>
21+
<UseDebugLibraries>true</UseDebugLibraries>
22+
<PlatformToolset>v120</PlatformToolset>
23+
<CharacterSet>Unicode</CharacterSet>
24+
</PropertyGroup>
25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
26+
<ConfigurationType>DynamicLibrary</ConfigurationType>
27+
<UseDebugLibraries>false</UseDebugLibraries>
28+
<PlatformToolset>v120</PlatformToolset>
29+
<WholeProgramOptimization>true</WholeProgramOptimization>
30+
<CharacterSet>Unicode</CharacterSet>
31+
</PropertyGroup>
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33+
<ImportGroup Label="ExtensionSettings">
34+
</ImportGroup>
35+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
36+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37+
</ImportGroup>
38+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
39+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40+
</ImportGroup>
41+
<PropertyGroup Label="UserMacros" />
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
43+
<LinkIncremental>true</LinkIncremental>
44+
<IncludePath>$(SolutionDir)caffe\build\include;$(SolutionDir)caffe\3rdparty\include;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include;C:\boost_1_56_0;C:\opencv249\build\include;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(IncludePath)</IncludePath>
45+
<LibraryPath>$(SolutionDir)caffe\build\lib;$(SolutionDir)caffe\3rdparty\lib;C:\boost_1_56_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
46+
<TargetName>waifu2x-caffe</TargetName>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
49+
<LinkIncremental>false</LinkIncremental>
50+
<IncludePath>$(SolutionDir)caffe\build\include;$(SolutionDir)caffe\3rdparty\include;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include;C:\boost_1_56_0;C:\opencv249\build\include;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(IncludePath)</IncludePath>
51+
<LibraryPath>$(SolutionDir)caffe\build\lib;$(SolutionDir)caffe\3rdparty\lib;C:\boost_1_56_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
52+
<TargetName>waifu2x-caffe</TargetName>
53+
</PropertyGroup>
54+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
55+
<ClCompile>
56+
<PrecompiledHeader>
57+
</PrecompiledHeader>
58+
<WarningLevel>Level3</WarningLevel>
59+
<Optimization>Disabled</Optimization>
60+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
61+
</ClCompile>
62+
<Link>
63+
<SubSystem>Console</SubSystem>
64+
<GenerateDebugInformation>true</GenerateDebugInformation>
65+
<DelayLoadDLLs>cudnn64_65.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
66+
</Link>
67+
</ItemDefinitionGroup>
68+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<ClCompile>
70+
<WarningLevel>Level3</WarningLevel>
71+
<PrecompiledHeader>
72+
</PrecompiledHeader>
73+
<Optimization>MaxSpeed</Optimization>
74+
<FunctionLevelLinking>true</FunctionLevelLinking>
75+
<IntrinsicFunctions>true</IntrinsicFunctions>
76+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
77+
</ClCompile>
78+
<Link>
79+
<SubSystem>Console</SubSystem>
80+
<GenerateDebugInformation>true</GenerateDebugInformation>
81+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
82+
<OptimizeReferences>true</OptimizeReferences>
83+
<DelayLoadDLLs>cudnn64_65.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
84+
</Link>
85+
</ItemDefinitionGroup>
86+
<ItemGroup>
87+
<ClCompile Include="Source.cpp" />
88+
<ClCompile Include="waifu2x.cpp" />
89+
</ItemGroup>
90+
<ItemGroup>
91+
<ClInclude Include="waifu2x.h" />
92+
</ItemGroup>
93+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
94+
<ImportGroup Label="ExtensionTargets">
95+
</ImportGroup>
96+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="ソース ファイル">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="ヘッダー ファイル">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="リソース ファイル">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="Source.cpp">
19+
<Filter>ソース ファイル</Filter>
20+
</ClCompile>
21+
<ClCompile Include="waifu2x.cpp">
22+
<Filter>ソース ファイル</Filter>
23+
</ClCompile>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClInclude Include="waifu2x.h">
27+
<Filter>ヘッダー ファイル</Filter>
28+
</ClInclude>
29+
</ItemGroup>
30+
</Project>

‎waifu2x-caffe-dll/waifu2x.cpp

+794
Large diffs are not rendered by default.

‎waifu2x-caffe-dll/waifu2x.h

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#pragma once
2+
3+
#include <stdint.h>
4+
#include <string>
5+
#include <vector>
6+
#include <utility>
7+
#include <functional>
8+
#include <boost/shared_ptr.hpp>
9+
#include <opencv2/opencv.hpp>
10+
11+
12+
namespace caffe
13+
{
14+
template <typename Dtype>
15+
class Net;
16+
class NetParameter;
17+
};
18+
19+
class Waifu2x
20+
{
21+
public:
22+
enum eWaifu2xError
23+
{
24+
eWaifu2xError_OK = 0,
25+
eWaifu2xError_Cancel,
26+
eWaifu2xError_NotInitialized,
27+
eWaifu2xError_InvalidParameter,
28+
eWaifu2xError_FailedOpenInputFile,
29+
eWaifu2xError_FailedOpenOutputFile,
30+
eWaifu2xError_FailedOpenModelFile,
31+
eWaifu2xError_FailedParseModelFile,
32+
eWaifu2xError_FailedConstructModel,
33+
eWaifu2xError_FailedProcessCaffe,
34+
eWaifu2xError_FailedCudaCheck,
35+
};
36+
37+
enum eWaifu2xCudaError
38+
{
39+
eWaifu2xCudaError_OK = 0,
40+
eWaifu2xCudaError_NotFind,
41+
eWaifu2xCudaError_OldVersion,
42+
};
43+
44+
enum eWaifu2xcuDNNError
45+
{
46+
eWaifu2xcuDNNError_OK = 0,
47+
eWaifu2xcuDNNError_NotFind,
48+
eWaifu2xcuDNNError_OldVersion,
49+
eWaifu2xcuDNNError_CannotCreate,
50+
};
51+
52+
typedef std::function<bool()> waifu2xCancelFunc;
53+
54+
private:
55+
bool is_inited;
56+
57+
// 一度に処理する画像の幅
58+
int crop_size;
59+
// 一度に何ブロック分処理するか
60+
int batch_size;
61+
62+
// ネットに入力する画像のサイズ
63+
int input_block_size;
64+
// ブロック変換後の出力サイズ
65+
int output_size;
66+
// ネットワークに入力する画像のサイズ(出力画像の幅はlayer_num * 2だけ小さくなる)
67+
int block_width_height;
68+
// srcnn.prototxtで定義された入力する画像のサイズ
69+
int original_width_height;
70+
71+
std::string mode;
72+
int noise_level;
73+
std::string model_dir;
74+
std::string process;
75+
76+
int inner_padding;
77+
int outer_padding;
78+
79+
int output_block_size;
80+
81+
int input_plane;
82+
83+
bool isCuda;
84+
85+
boost::shared_ptr<caffe::Net<float>> net_noise;
86+
boost::shared_ptr<caffe::Net<float>> net_scale;
87+
88+
float *input_block;
89+
float *dummy_data;
90+
float *output_block;
91+
92+
private:
93+
eWaifu2xError LoadMat(cv::Mat &float_image, const uint32_t* source, int width, int height);
94+
eWaifu2xError PaddingImage(const cv::Mat &input, cv::Mat &output);
95+
eWaifu2xError Zoom2xAndPaddingImage(const cv::Mat &input, cv::Mat &output, cv::Size_<int> &zoom_size);
96+
eWaifu2xError CreateZoomColorImage(const cv::Mat &float_image, const cv::Size_<int> &zoom_size, std::vector<cv::Mat> &cubic_planes);
97+
eWaifu2xError ConstractNet(boost::shared_ptr<caffe::Net<float>> &net, const std::string &model_path, const std::string &param_path, const std::string &process);
98+
eWaifu2xError SetParameter(caffe::NetParameter &param) const;
99+
eWaifu2xError ReconstructImage(boost::shared_ptr<caffe::Net<float>> net, cv::Mat &im);
100+
101+
public:
102+
Waifu2x();
103+
~Waifu2x();
104+
105+
// mode: noise or scale or noise_scale or auto_scale
106+
// process: cpu or gpu or cudnn
107+
eWaifu2xError init(int argc, char** argv, const std::string &mode, const int noise_level, const std::string &model_dir, const std::string &process,
108+
const int crop_size = 128, const int batch_size = 1);
109+
110+
void destroy();
111+
112+
eWaifu2xError waifu2x(int factor, const uint32_t* source, uint32_t* dest, int width, int height);
113+
114+
const std::string& used_process() const;
115+
};

‎waifu2x-caffe.sln

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "waifu2x-caffe", "waifu2x-ca
77
EndProject
88
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "waifu2x-caffe-gui", "waifu2x-caffe-gui\waifu2x-caffe-gui.vcxproj", "{63FB3EFC-63B0-401C-BB54-F3A984DC233F}"
99
EndProject
10+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "waifu2x-caffe-dll", "waifu2x-caffe-dll\waifu2x-caffe-dll.vcxproj", "{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|x64 = Debug|x64
@@ -21,6 +23,10 @@ Global
2123
{63FB3EFC-63B0-401C-BB54-F3A984DC233F}.Debug|x64.Build.0 = Debug|x64
2224
{63FB3EFC-63B0-401C-BB54-F3A984DC233F}.Release|x64.ActiveCfg = Release|x64
2325
{63FB3EFC-63B0-401C-BB54-F3A984DC233F}.Release|x64.Build.0 = Release|x64
26+
{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}.Debug|x64.ActiveCfg = Debug|x64
27+
{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}.Debug|x64.Build.0 = Debug|x64
28+
{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}.Release|x64.ActiveCfg = Release|x64
29+
{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}.Release|x64.Build.0 = Release|x64
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)
Please sign in to comment.