mirror of
https://github.com/lltcggie/waifu2x-caffe.git
synced 2025-11-24 18:44:55 +00:00
テスト
This commit is contained in:
parent
807cfcb78f
commit
e6270364ed
3
.gitignore
vendored
3
.gitignore
vendored
@ -243,5 +243,8 @@ ModelManifest.xml
|
|||||||
|
|
||||||
# FAKE - F# Make
|
# FAKE - F# Make
|
||||||
.fake/
|
.fake/
|
||||||
|
|
||||||
*.caffemodel
|
*.caffemodel
|
||||||
*.protobin
|
*.protobin
|
||||||
|
/lib/
|
||||||
|
/opencv_contrib-*/
|
||||||
|
|||||||
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -7,10 +7,6 @@
|
|||||||
[submodule "msgpack-c"]
|
[submodule "msgpack-c"]
|
||||||
path = msgpack-c
|
path = msgpack-c
|
||||||
url = https://github.com/msgpack/msgpack-c
|
url = https://github.com/msgpack/msgpack-c
|
||||||
[submodule "caffe"]
|
|
||||||
path = caffe
|
|
||||||
url = https://github.com/lltcggie/caffe.git
|
|
||||||
branch = lltcggie/custom
|
|
||||||
[submodule "opencv"]
|
[submodule "opencv"]
|
||||||
path = opencv
|
path = opencv
|
||||||
url = https://github.com/opencv/opencv.git
|
url = https://github.com/opencv/opencv.git
|
||||||
|
|||||||
1
caffe
1
caffe
@ -1 +0,0 @@
|
|||||||
Subproject commit 9d5aa36c65a0082768f10c1d474c56d8a7cc9934
|
|
||||||
@ -4,7 +4,7 @@ cd /d "%~dp0"
|
|||||||
|
|
||||||
cd caffe
|
cd caffe
|
||||||
|
|
||||||
set MSVC_VERSION=14
|
set MSVC_VERSION=17
|
||||||
set USE_CUDNN=1
|
set USE_CUDNN=1
|
||||||
set USE_NCCL=0
|
set USE_NCCL=0
|
||||||
set USE_OPENCV=0
|
set USE_OPENCV=0
|
||||||
@ -21,7 +21,8 @@ set BUILD_PYTHON_LAYER=0
|
|||||||
set RUN_TESTS=0
|
set RUN_TESTS=0
|
||||||
set CMAKE_INSTALL_PREFIX=../../lib
|
set CMAKE_INSTALL_PREFIX=../../lib
|
||||||
set RUN_INSTALL=1
|
set RUN_INSTALL=1
|
||||||
set CUDA_ARCH_BIN=35 50 52 53 60 61 62 70 75 80
|
rem set CUDA_ARCH_BIN=75 80 86 89 90 100 120
|
||||||
set CUDA_ARCH_PTX=80
|
set CUDA_ARCH_BIN=89
|
||||||
|
set CUDA_ARCH_PTX=120
|
||||||
|
|
||||||
scripts\build_win.cmd
|
scripts\build_win.cmd
|
||||||
@ -29,7 +29,7 @@ static bool readFile(boost::iostreams::stream<boost::iostreams::file_descriptor_
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename BufType>
|
template<typename BufType>
|
||||||
static bool readFile(const boost::filesystem::path &path, std::vector<BufType> &buf)
|
static bool readFile(const std::filesystem::path &path, std::vector<BufType> &buf)
|
||||||
{
|
{
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ static bool readFile(const boost::filesystem::path &path, std::vector<BufType> &
|
|||||||
return readFile(is, buf);
|
return readFile(is, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Waifu2x::eWaifu2xError readProtoText(const boost::filesystem::path &path, ::google::protobuf::Message* proto)
|
static Waifu2x::eWaifu2xError readProtoText(const std::filesystem::path &path, ::google::protobuf::Message* proto)
|
||||||
{
|
{
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ static Waifu2x::eWaifu2xError readProtoText(const boost::filesystem::path &path,
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Waifu2x::eWaifu2xError writeProtoBinary(const ::google::protobuf::Message& proto, const boost::filesystem::path &path)
|
static Waifu2x::eWaifu2xError writeProtoBinary(const ::google::protobuf::Message& proto, const std::filesystem::path &path)
|
||||||
{
|
{
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor> os;
|
boost::iostreams::stream<boost::iostreams::file_descriptor> os;
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ static Waifu2x::eWaifu2xError writeProtoBinary(const ::google::protobuf::Message
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Waifu2x::eWaifu2xError readProtoBinary(const boost::filesystem::path &path, ::google::protobuf::Message* proto)
|
static Waifu2x::eWaifu2xError readProtoBinary(const std::filesystem::path &path, ::google::protobuf::Message* proto)
|
||||||
{
|
{
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ static Waifu2x::eWaifu2xError readProtoBinary(const boost::filesystem::path &pat
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
Waifu2x::eWaifu2xError ReadJson(const boost::filesystem::path &info_path, rapidjson::Document &d, std::vector<char> &jsonBuf)
|
Waifu2x::eWaifu2xError ReadJson(const std::filesystem::path &info_path, rapidjson::Document &d, std::vector<char> &jsonBuf)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -174,7 +174,7 @@ cNet::cNet() : mModelScale(0), mInnerScale(0), mNetOffset(0), mInputPlane(0), mH
|
|||||||
cNet::~cNet()
|
cNet::~cNet()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError cNet::GetInfo(const boost::filesystem::path & info_path, Waifu2x::stInfo &info)
|
Waifu2x::eWaifu2xError cNet::GetInfo(const std::filesystem::path & info_path, Waifu2x::stInfo &info)
|
||||||
{
|
{
|
||||||
rapidjson::Document d;
|
rapidjson::Document d;
|
||||||
std::vector<char> jsonBuf;
|
std::vector<char> jsonBuf;
|
||||||
@ -291,7 +291,7 @@ Waifu2x::eWaifu2xError cNet::GetInfo(const boost::filesystem::path & info_path,
|
|||||||
|
|
||||||
// モデルファイルからネットワークを構築
|
// モデルファイルからネットワークを構築
|
||||||
// processでcudnnが指定されなかった場合はcuDNNが呼び出されないように変更する
|
// processでcudnnが指定されなかった場合はcuDNNが呼び出されないように変更する
|
||||||
Waifu2x::eWaifu2xError cNet::ConstractNet(const Waifu2x::eWaifu2xModelType mode, const boost::filesystem::path &model_path, const boost::filesystem::path ¶m_path, const Waifu2x::stInfo &info, const std::string &process)
|
Waifu2x::eWaifu2xError cNet::ConstractNet(const Waifu2x::eWaifu2xModelType mode, const std::filesystem::path &model_path, const std::filesystem::path ¶m_path, const Waifu2x::stInfo &info, const std::string &process)
|
||||||
{
|
{
|
||||||
Waifu2x::eWaifu2xError ret;
|
Waifu2x::eWaifu2xError ret;
|
||||||
|
|
||||||
@ -299,9 +299,9 @@ Waifu2x::eWaifu2xError cNet::ConstractNet(const Waifu2x::eWaifu2xModelType mode,
|
|||||||
|
|
||||||
LoadParamFromInfo(mode, info);
|
LoadParamFromInfo(mode, info);
|
||||||
|
|
||||||
boost::filesystem::path modelbin_path = model_path;
|
std::filesystem::path modelbin_path = model_path;
|
||||||
modelbin_path += ".protobin";
|
modelbin_path += ".protobin";
|
||||||
boost::filesystem::path caffemodel_path = param_path;
|
std::filesystem::path caffemodel_path = param_path;
|
||||||
caffemodel_path += ".caffemodel";
|
caffemodel_path += ".caffemodel";
|
||||||
|
|
||||||
caffe::NetParameter param_model;
|
caffe::NetParameter param_model;
|
||||||
@ -331,7 +331,7 @@ Waifu2x::eWaifu2xError cNet::ConstractNet(const Waifu2x::eWaifu2xModelType mode,
|
|||||||
if (!caffe::UpgradeNetAsNeeded(caffemodel_path.string(), ¶m_caffemodel))
|
if (!caffe::UpgradeNetAsNeeded(caffemodel_path.string(), ¶m_caffemodel))
|
||||||
return Waifu2x::eWaifu2xError_FailedParseModelFile;
|
return Waifu2x::eWaifu2xError_FailedParseModelFile;
|
||||||
|
|
||||||
mNet = boost::shared_ptr<caffe::Net<float>>(new caffe::Net<float>(param_model));
|
mNet = std::shared_ptr<caffe::Net<float>>(new caffe::Net<float>(param_model));
|
||||||
mNet->CopyTrainedLayersFrom(param_caffemodel);
|
mNet->CopyTrainedLayersFrom(param_caffemodel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -437,8 +437,8 @@ Waifu2x::eWaifu2xError cNet::SetParameter(caffe::NetParameter ¶m, const std:
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const boost::filesystem::path &model_path, const boost::filesystem::path ¶m_path
|
Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const std::filesystem::path &model_path, const std::filesystem::path ¶m_path
|
||||||
, const boost::filesystem::path &modelbin_path, const boost::filesystem::path &caffemodel_path, const std::string &process)
|
, const std::filesystem::path &modelbin_path, const std::filesystem::path &caffemodel_path, const std::string &process)
|
||||||
{
|
{
|
||||||
Waifu2x::eWaifu2xError ret;
|
Waifu2x::eWaifu2xError ret;
|
||||||
|
|
||||||
@ -455,7 +455,7 @@ Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const boost::filesystem::path
|
|||||||
if (ret != Waifu2x::eWaifu2xError_OK)
|
if (ret != Waifu2x::eWaifu2xError_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
mNet = boost::shared_ptr<caffe::Net<float>>(new caffe::Net<float>(param));
|
mNet = std::shared_ptr<caffe::Net<float>>(new caffe::Net<float>(param));
|
||||||
|
|
||||||
rapidjson::Document d;
|
rapidjson::Document d;
|
||||||
std::vector<char> jsonBuf;
|
std::vector<char> jsonBuf;
|
||||||
@ -509,7 +509,7 @@ Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const boost::filesystem::path
|
|||||||
if (inputPlane != outputPlane)
|
if (inputPlane != outputPlane)
|
||||||
return Waifu2x::eWaifu2xError_FailedParseModelFile;
|
return Waifu2x::eWaifu2xError_FailedParseModelFile;
|
||||||
|
|
||||||
std::vector<boost::shared_ptr<caffe::Layer<float>>> list;
|
std::vector<std::shared_ptr<caffe::Layer<float>>> list;
|
||||||
auto &v = mNet->layers();
|
auto &v = mNet->layers();
|
||||||
for (auto &l : v)
|
for (auto &l : v)
|
||||||
{
|
{
|
||||||
@ -858,7 +858,7 @@ Waifu2x::eWaifu2xError cNet::ReconstructImage(const bool UseTTA, const int crop_
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cNet::GetModelName(const boost::filesystem::path &info_path)
|
std::string cNet::GetModelName(const std::filesystem::path &info_path)
|
||||||
{
|
{
|
||||||
Waifu2x::eWaifu2xError ret;
|
Waifu2x::eWaifu2xError ret;
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ class cNet
|
|||||||
private:
|
private:
|
||||||
Waifu2x::eWaifu2xModelType mMode;
|
Waifu2x::eWaifu2xModelType mMode;
|
||||||
|
|
||||||
boost::shared_ptr<caffe::Net<float>> mNet;
|
std::shared_ptr<caffe::Net<float>> mNet;
|
||||||
|
|
||||||
int mModelScale; // モデルが対象とする拡大率
|
int mModelScale; // モデルが対象とする拡大率
|
||||||
int mInnerScale; // ネット内部で拡大される倍率
|
int mInnerScale; // ネット内部で拡大される倍率
|
||||||
@ -18,18 +18,18 @@ private:
|
|||||||
bool mHasNoiseScaleModel;
|
bool mHasNoiseScaleModel;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadParamFromInfo(const Waifu2x::eWaifu2xModelType mode, const Waifu2x::stInfo &info);
|
void LoadParamFromInfo(const Waifu2x::eWaifu2xModelType mode, const Waifu2x::stInfo& info);
|
||||||
Waifu2x::eWaifu2xError LoadParameterFromJson(const boost::filesystem::path &model_path, const boost::filesystem::path ¶m_path
|
Waifu2x::eWaifu2xError LoadParameterFromJson(const std::filesystem::path& model_path, const std::filesystem::path& param_path
|
||||||
, const boost::filesystem::path &modelbin_path, const boost::filesystem::path &caffemodel_path, const std::string &process);
|
, const std::filesystem::path& modelbin_path, const std::filesystem::path& caffemodel_path, const std::string& process);
|
||||||
Waifu2x::eWaifu2xError SetParameter(caffe::NetParameter ¶m, const std::string &process) const;
|
Waifu2x::eWaifu2xError SetParameter(caffe::NetParameter& param, const std::string& process) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cNet();
|
cNet();
|
||||||
~cNet();
|
~cNet();
|
||||||
|
|
||||||
static Waifu2x::eWaifu2xError GetInfo(const boost::filesystem::path &info_path, Waifu2x::stInfo &info);
|
static Waifu2x::eWaifu2xError GetInfo(const std::filesystem::path& info_path, Waifu2x::stInfo& info);
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError ConstractNet(const Waifu2x::eWaifu2xModelType mode, const boost::filesystem::path &model_path, const boost::filesystem::path ¶m_path, const Waifu2x::stInfo &info, const std::string &process);
|
Waifu2x::eWaifu2xError ConstractNet(const Waifu2x::eWaifu2xModelType mode, const std::filesystem::path& model_path, const std::filesystem::path& param_path, const Waifu2x::stInfo& info, const std::string& process);
|
||||||
|
|
||||||
int GetInputPlane() const;
|
int GetInputPlane() const;
|
||||||
int GetInnerScale() const;
|
int GetInnerScale() const;
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
int GetInputMemorySize(const int crop_w, const int crop_h, const int outer_padding, const int batch_size) const;
|
int GetInputMemorySize(const int crop_w, const int crop_h, const int outer_padding, const int batch_size) const;
|
||||||
int GetOutputMemorySize(const int crop_w, const int crop_h, const int outer_padding, const int batch_size) const;
|
int GetOutputMemorySize(const int crop_w, const int crop_h, const int outer_padding, const int batch_size) const;
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError ReconstructImage(const bool UseTTA, const int crop_w, const int crop_h, const int outer_padding, const int batch_size, float *outputBlockBuf, const cv::Mat &inMat, cv::Mat &outMat);
|
Waifu2x::eWaifu2xError ReconstructImage(const bool UseTTA, const int crop_w, const int crop_h, const int outer_padding, const int batch_size, float* outputBlockBuf, const cv::Mat& inMat, cv::Mat& outMat);
|
||||||
|
|
||||||
static std::string GetModelName(const boost::filesystem::path &info_path);
|
static std::string GetModelName(const std::filesystem::path& info_path);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "stImage.h"
|
#include "stImage.h"
|
||||||
#include <boost/iostreams/stream.hpp>
|
//#include <boost/iostreams/stream.hpp>
|
||||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
//#include <boost/iostreams/device/file_descriptor.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
//#include <boost/algorithm/string.hpp>
|
||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <opencv2/imgcodecs.hpp>
|
#include <opencv2/imgcodecs.hpp>
|
||||||
@ -11,10 +11,10 @@
|
|||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include <stb_image_write.h>
|
#include <stb_image_write.h>
|
||||||
|
|
||||||
const int YToRGBConvertMode = CV_GRAY2RGB;
|
const int YToRGBConvertMode = cv::COLOR_GRAY2RGB;
|
||||||
const int YToRGBConverInversetMode = CV_RGB2GRAY;
|
const int YToRGBConverInversetMode = cv::COLOR_RGB2GRAY;
|
||||||
const int BGRToYConvertMode = CV_BGR2YUV;
|
const int BGRToYConvertMode = cv::COLOR_BGR2YUV;
|
||||||
const int BGRToConvertInverseMode = CV_YUV2BGR;
|
const int BGRToConvertInverseMode = cv::COLOR_YUV2BGR;
|
||||||
|
|
||||||
// floatな画像をuint8_tな画像に変換する際の四捨五入に使う値
|
// floatな画像をuint8_tな画像に変換する際の四捨五入に使う値
|
||||||
// https://github.com/nagadomi/waifu2x/commit/797b45ae23665a1c5e3c481c018e48e6f0d0e383
|
// https://github.com/nagadomi/waifu2x/commit/797b45ae23665a1c5e3c481c018e48e6f0d0e383
|
||||||
@ -24,39 +24,22 @@ const double clip_eps32 = 1.0 * 0.5 - (1.0e-7 * 0.5);
|
|||||||
|
|
||||||
const std::vector<stImage::stOutputExtentionElement> stImage::OutputExtentionList =
|
const std::vector<stImage::stOutputExtentionElement> stImage::OutputExtentionList =
|
||||||
{
|
{
|
||||||
{L".png",{8, 16}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".png",{8, 16}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".bmp",{8}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".bmp",{8}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".jpg",{8}, 0, 100, 95, cv::IMWRITE_JPEG_QUALITY},
|
{L".jpg",{8}, 0, 100, 95, cv::IMWRITE_JPEG_QUALITY},
|
||||||
{L".jp2",{8, 16}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".jp2",{8, 16}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".sr",{8}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".sr",{8}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".tif",{8, 16, 32}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".tif",{8, 16, 32}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".hdr",{8, 16, 32}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".hdr",{8, 16, 32}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".exr",{8, 16, 32}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".exr",{8, 16, 32}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".ppm",{8, 16}, boost::optional<int>(), boost::optional<int>(), boost::optional<int>(), boost::optional<int>()},
|
{L".ppm",{8, 16}, std::optional<int>(), std::optional<int>(), std::optional<int>(), std::optional<int>()},
|
||||||
{L".webp",{8}, 1, 100, 100, cv::IMWRITE_WEBP_QUALITY},
|
{L".webp",{8}, 1, 100, 100, cv::IMWRITE_WEBP_QUALITY},
|
||||||
{L".tga",{8}, 0, 1, 0, 0},
|
{L".tga",{8}, 0, 1, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename BufType>
|
template<typename BufType>
|
||||||
static bool readFile(boost::iostreams::stream<boost::iostreams::file_descriptor_source> &is, std::vector<BufType> &buf)
|
static bool readFile(const std::filesystem::path& path, std::vector<BufType>& buf)
|
||||||
{
|
|
||||||
if (!is)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const auto size = is.seekg(0, std::ios::end).tellg();
|
|
||||||
is.seekg(0, std::ios::beg);
|
|
||||||
|
|
||||||
buf.resize((size / sizeof(BufType)) + (size % sizeof(BufType)));
|
|
||||||
is.read(buf.data(), size);
|
|
||||||
if (is.gcount() != size)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename BufType>
|
|
||||||
static bool readFile(const boost::filesystem::path &path, std::vector<BufType> &buf)
|
|
||||||
{
|
{
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is;
|
||||||
|
|
||||||
@ -73,21 +56,7 @@ static bool readFile(const boost::filesystem::path &path, std::vector<BufType> &
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename BufType>
|
template<typename BufType>
|
||||||
static bool writeFile(boost::iostreams::stream<boost::iostreams::file_descriptor> &os, const std::vector<BufType> &buf)
|
static bool writeFile(const std::filesystem::path& path, std::vector<BufType>& buf)
|
||||||
{
|
|
||||||
if (!os)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const auto WriteSize = sizeof(BufType) * buf.size();
|
|
||||||
os.write((const char *)buf.data(), WriteSize);
|
|
||||||
if (os.fail())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename BufType>
|
|
||||||
static bool writeFile(const boost::filesystem::path &path, std::vector<BufType> &buf)
|
|
||||||
{
|
{
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor> os;
|
boost::iostreams::stream<boost::iostreams::file_descriptor> os;
|
||||||
|
|
||||||
@ -103,10 +72,10 @@ static bool writeFile(const boost::filesystem::path &path, std::vector<BufType>
|
|||||||
return writeFile(os, buf);
|
return writeFile(os, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Waifu2x_stbi_write_func(void *context, void *data, int size)
|
static void Waifu2x_stbi_write_func(void* context, void* data, int size)
|
||||||
{
|
{
|
||||||
boost::iostreams::stream<boost::iostreams::file_descriptor> *osp = (boost::iostreams::stream<boost::iostreams::file_descriptor> *)context;
|
boost::iostreams::stream<boost::iostreams::file_descriptor>* osp = (boost::iostreams::stream<boost::iostreams::file_descriptor> *)context;
|
||||||
osp->write((const char *)data, size);
|
osp->write((const char*)data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int stImage::DepthBitToCVDepth(const int depth_bit)
|
int stImage::DepthBitToCVDepth(const int depth_bit)
|
||||||
@ -164,7 +133,7 @@ double stImage::GetEPS(const int cv_depth)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector<cv::Mat> &planes, const cv::Mat &alpha, const int offset)
|
Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector<cv::Mat>& planes, const cv::Mat& alpha, const int offset)
|
||||||
{
|
{
|
||||||
// このカーネルと画像の畳込みを行うと、(x, y)を中心とした3×3領域の合計値が求まる
|
// このカーネルと画像の畳込みを行うと、(x, y)を中心とした3×3領域の合計値が求まる
|
||||||
const static cv::Mat sum2d_kernel = (cv::Mat_<double>(3, 3) <<
|
const static cv::Mat sum2d_kernel = (cv::Mat_<double>(3, 3) <<
|
||||||
@ -178,7 +147,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector<cv::Mat> &planes, co
|
|||||||
cv::Mat mask_nega;
|
cv::Mat mask_nega;
|
||||||
cv::threshold(mask, mask_nega, 0.0, 1.0, cv::THRESH_BINARY_INV); // 反転したマスク(値が1の箇所は完全透明でない有効な画素となる)
|
cv::threshold(mask, mask_nega, 0.0, 1.0, cv::THRESH_BINARY_INV); // 反転したマスク(値が1の箇所は完全透明でない有効な画素となる)
|
||||||
|
|
||||||
for (auto &p : planes) // 完全に透明なピクセルにあるゴミを取る
|
for (auto& p : planes) // 完全に透明なピクセルにあるゴミを取る
|
||||||
{
|
{
|
||||||
p = p.mul(mask);
|
p = p.mul(mask);
|
||||||
}
|
}
|
||||||
@ -191,7 +160,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector<cv::Mat> &planes, co
|
|||||||
cv::Mat mask_nega_u8;
|
cv::Mat mask_nega_u8;
|
||||||
mask_nega.convertTo(mask_nega_u8, CV_8U, 255.0, clip_eps8); // mask_negaのCV_U8版(OpenCVのAPI上必要になる)
|
mask_nega.convertTo(mask_nega_u8, CV_8U, 255.0, clip_eps8); // mask_negaのCV_U8版(OpenCVのAPI上必要になる)
|
||||||
|
|
||||||
for (auto &p : planes) // 1チャンネルずつ処理
|
for (auto& p : planes) // 1チャンネルずつ処理
|
||||||
{
|
{
|
||||||
// チャンネルの3×3領域内の有効画素の平均値を求める
|
// チャンネルの3×3領域内の有効画素の平均値を求める
|
||||||
cv::Mat border;
|
cv::Mat border;
|
||||||
@ -209,7 +178,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector<cv::Mat> &planes, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 画素を0から1にクリッピング
|
// 画素を0から1にクリッピング
|
||||||
for (auto &p : planes)
|
for (auto& p : planes)
|
||||||
{
|
{
|
||||||
cv::threshold(p, p, 1.0, 1.0, cv::THRESH_TRUNC);
|
cv::threshold(p, p, 1.0, 1.0, cv::THRESH_TRUNC);
|
||||||
cv::threshold(p, p, 0.0, 0.0, cv::THRESH_TOZERO);
|
cv::threshold(p, p, 0.0, 0.0, cv::THRESH_TOZERO);
|
||||||
@ -219,7 +188,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector<cv::Mat> &planes, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 画像を読み込んで値を0.0f~1.0fの範囲に変換
|
// 画像を読み込んで値を0.0f~1.0fの範囲に変換
|
||||||
Waifu2x::eWaifu2xError stImage::LoadMat(cv::Mat &im, const boost::filesystem::path &input_file)
|
Waifu2x::eWaifu2xError stImage::LoadMat(cv::Mat& im, const std::filesystem::path& input_file)
|
||||||
{
|
{
|
||||||
cv::Mat original_image;
|
cv::Mat original_image;
|
||||||
|
|
||||||
@ -228,7 +197,7 @@ Waifu2x::eWaifu2xError stImage::LoadMat(cv::Mat &im, const boost::filesystem::pa
|
|||||||
if (!readFile(input_file, img_data))
|
if (!readFile(input_file, img_data))
|
||||||
return Waifu2x::eWaifu2xError_FailedOpenInputFile;
|
return Waifu2x::eWaifu2xError_FailedOpenInputFile;
|
||||||
|
|
||||||
const boost::filesystem::path ipext(input_file.extension());
|
const std::filesystem::path ipext(input_file.extension());
|
||||||
if (!boost::iequals(ipext.string(), ".bmp")) // 特定のファイル形式の場合OpenCVで読むとバグることがあるのでSTBIを優先させる
|
if (!boost::iequals(ipext.string(), ".bmp")) // 特定のファイル形式の場合OpenCVで読むとバグることがあるのでSTBIを優先させる
|
||||||
{
|
{
|
||||||
cv::Mat im(img_data.size(), 1, CV_8U, img_data.data());
|
cv::Mat im(img_data.size(), 1, CV_8U, img_data.data());
|
||||||
@ -259,10 +228,10 @@ Waifu2x::eWaifu2xError stImage::LoadMat(cv::Mat &im, const boost::filesystem::pa
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError stImage::LoadMatBySTBI(cv::Mat &im, const std::vector<char> &img_data)
|
Waifu2x::eWaifu2xError stImage::LoadMatBySTBI(cv::Mat& im, const std::vector<char>& img_data)
|
||||||
{
|
{
|
||||||
int x, y, comp;
|
int x, y, comp;
|
||||||
stbi_uc *data = stbi_load_from_memory((const stbi_uc *)img_data.data(), img_data.size(), &x, &y, &comp, 0);
|
stbi_uc* data = stbi_load_from_memory((const stbi_uc*)img_data.data(), img_data.size(), &x, &y, &comp, 0);
|
||||||
if (!data)
|
if (!data)
|
||||||
return Waifu2x::eWaifu2xError_FailedOpenInputFile;
|
return Waifu2x::eWaifu2xError_FailedOpenInputFile;
|
||||||
|
|
||||||
@ -315,7 +284,7 @@ Waifu2x::eWaifu2xError stImage::LoadMatBySTBI(cv::Mat &im, const std::vector<cha
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Mat stImage::ConvertToFloat(const cv::Mat &im)
|
cv::Mat stImage::ConvertToFloat(const cv::Mat& im)
|
||||||
{
|
{
|
||||||
cv::Mat convert;
|
cv::Mat convert;
|
||||||
switch (im.depth())
|
switch (im.depth())
|
||||||
@ -354,7 +323,7 @@ void stImage::Clear()
|
|||||||
mEndImage.release();
|
mEndImage.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError stImage::Load(const boost::filesystem::path &input_file)
|
Waifu2x::eWaifu2xError stImage::Load(const std::filesystem::path& input_file)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
@ -369,8 +338,8 @@ Waifu2x::eWaifu2xError stImage::Load(const boost::filesystem::path &input_file)
|
|||||||
mOrgChannel = im.channels();
|
mOrgChannel = im.channels();
|
||||||
mOrgSize = im.size();
|
mOrgSize = im.size();
|
||||||
|
|
||||||
const boost::filesystem::path ip(input_file);
|
const std::filesystem::path ip(input_file);
|
||||||
const boost::filesystem::path ipext(ip.extension());
|
const std::filesystem::path ipext(ip.extension());
|
||||||
|
|
||||||
const bool isJpeg = boost::iequals(ipext.string(), ".jpg") || boost::iequals(ipext.string(), ".jpeg");
|
const bool isJpeg = boost::iequals(ipext.string(), ".jpg") || boost::iequals(ipext.string(), ".jpeg");
|
||||||
|
|
||||||
@ -383,7 +352,7 @@ Waifu2x::eWaifu2xError stImage::Load(const void* source, const int width, const
|
|||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
cv::Mat original_image(cv::Size(width, height), CV_MAKETYPE(CV_8U, channel), (void *)source, stride);
|
cv::Mat original_image(cv::Size(width, height), CV_MAKETYPE(CV_8U, channel), (void*)source, stride);
|
||||||
|
|
||||||
if (original_image.channels() >= 3) // RGBなのでBGRにする
|
if (original_image.channels() >= 3) // RGBなのでBGRにする
|
||||||
{
|
{
|
||||||
@ -426,7 +395,7 @@ void stImage::Preprocess(const int input_plane, const int net_offset)
|
|||||||
ConvertToNetFormat(input_plane, net_offset);
|
ConvertToNetFormat(input_plane, net_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool stImage::IsOneColor(const cv::Mat & im)
|
bool stImage::IsOneColor(const cv::Mat& im)
|
||||||
{
|
{
|
||||||
assert(im.channels() == 1);
|
assert(im.channels() == 1);
|
||||||
|
|
||||||
@ -437,7 +406,7 @@ bool stImage::IsOneColor(const cv::Mat & im)
|
|||||||
if (Width == 0 && Height == 0)
|
if (Width == 0 && Height == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const float *ptr = (const float *)im.data;
|
const float* ptr = (const float*)im.data;
|
||||||
const float color = ptr[0];
|
const float color = ptr[0];
|
||||||
|
|
||||||
for (size_t i = 0; i < Height; i++)
|
for (size_t i = 0; i < Height; i++)
|
||||||
@ -524,7 +493,7 @@ void stImage::ConvertToNetFormat(const int input_plane, const int alpha_offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 画像から輝度の画像を取り出す
|
// 画像から輝度の画像を取り出す
|
||||||
Waifu2x::eWaifu2xError stImage::CreateBrightnessImage(const cv::Mat &float_image, cv::Mat &im)
|
Waifu2x::eWaifu2xError stImage::CreateBrightnessImage(const cv::Mat& float_image, cv::Mat& im)
|
||||||
{
|
{
|
||||||
if (float_image.channels() > 1)
|
if (float_image.channels() > 1)
|
||||||
{
|
{
|
||||||
@ -548,29 +517,29 @@ bool stImage::HasAlpha() const
|
|||||||
return !mTmpImageA.empty();
|
return !mTmpImageA.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void stImage::GetScalePaddingedRGB(cv::Mat &im, cv::Size_<int> &size, const int net_offset, const int outer_padding,
|
void stImage::GetScalePaddingedRGB(cv::Mat& im, cv::Size_<int>& size, const int net_offset, const int outer_padding,
|
||||||
const int crop_w, const int crop_h, const int scale)
|
const int crop_w, const int crop_h, const int scale)
|
||||||
{
|
{
|
||||||
GetScalePaddingedImage(mTmpImageRGB, im, size, net_offset, outer_padding, crop_w, crop_h, scale);
|
GetScalePaddingedImage(mTmpImageRGB, im, size, net_offset, outer_padding, crop_w, crop_h, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stImage::SetReconstructedRGB(cv::Mat &im, const cv::Size_<int> &size, const int inner_scale)
|
void stImage::SetReconstructedRGB(cv::Mat& im, const cv::Size_<int>& size, const int inner_scale)
|
||||||
{
|
{
|
||||||
SetReconstructedImage(mTmpImageRGB, im, size, inner_scale);
|
SetReconstructedImage(mTmpImageRGB, im, size, inner_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stImage::GetScalePaddingedA(cv::Mat &im, cv::Size_<int> &size, const int net_offset, const int outer_padding,
|
void stImage::GetScalePaddingedA(cv::Mat& im, cv::Size_<int>& size, const int net_offset, const int outer_padding,
|
||||||
const int crop_w, const int crop_h, const int scale)
|
const int crop_w, const int crop_h, const int scale)
|
||||||
{
|
{
|
||||||
GetScalePaddingedImage(mTmpImageA, im, size, net_offset, outer_padding, crop_w, crop_h, scale);
|
GetScalePaddingedImage(mTmpImageA, im, size, net_offset, outer_padding, crop_w, crop_h, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stImage::SetReconstructedA(cv::Mat &im, const cv::Size_<int> &size, const int inner_scale)
|
void stImage::SetReconstructedA(cv::Mat& im, const cv::Size_<int>& size, const int inner_scale)
|
||||||
{
|
{
|
||||||
SetReconstructedImage(mTmpImageA, im, size, inner_scale);
|
SetReconstructedImage(mTmpImageA, im, size, inner_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stImage::GetScalePaddingedImage(cv::Mat &in, cv::Mat &out, cv::Size_<int> &size, const int net_offset, const int outer_padding,
|
void stImage::GetScalePaddingedImage(cv::Mat& in, cv::Mat& out, cv::Size_<int>& size, const int net_offset, const int outer_padding,
|
||||||
const int crop_w, const int crop_h, const int scale)
|
const int crop_w, const int crop_h, const int scale)
|
||||||
{
|
{
|
||||||
cv::Mat ret;
|
cv::Mat ret;
|
||||||
@ -597,8 +566,8 @@ void stImage::GetScalePaddingedImage(cv::Mat &in, cv::Mat &out, cv::Size_<int> &
|
|||||||
|
|
||||||
// 入力画像の(Photoshopでいう)キャンバスサイズをoutput_sizeの倍数に変更
|
// 入力画像の(Photoshopでいう)キャンバスサイズをoutput_sizeの倍数に変更
|
||||||
// 画像は左上配置、余白はcv::BORDER_REPLICATEで埋める
|
// 画像は左上配置、余白はcv::BORDER_REPLICATEで埋める
|
||||||
void stImage::PaddingImage(const cv::Mat &input, const int net_offset, const int outer_padding,
|
void stImage::PaddingImage(const cv::Mat& input, const int net_offset, const int outer_padding,
|
||||||
const int crop_w, const int crop_h, cv::Mat &output)
|
const int crop_w, const int crop_h, cv::Mat& output)
|
||||||
{
|
{
|
||||||
const auto pad_w1 = net_offset + outer_padding;
|
const auto pad_w1 = net_offset + outer_padding;
|
||||||
const auto pad_h1 = net_offset + outer_padding;
|
const auto pad_h1 = net_offset + outer_padding;
|
||||||
@ -609,7 +578,7 @@ void stImage::PaddingImage(const cv::Mat &input, const int net_offset, const int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拡大、パディングされた画像を設定
|
// 拡大、パディングされた画像を設定
|
||||||
void stImage::SetReconstructedImage(cv::Mat &dst, cv::Mat &src, const cv::Size_<int> &size, const int inner_scale)
|
void stImage::SetReconstructedImage(cv::Mat& dst, cv::Mat& src, const cv::Size_<int>& size, const int inner_scale)
|
||||||
{
|
{
|
||||||
const cv::Size_<int> s(size * inner_scale);
|
const cv::Size_<int> s(size * inner_scale);
|
||||||
|
|
||||||
@ -718,7 +687,7 @@ void stImage::DeconvertFromNetFormat(const int input_plane)
|
|||||||
if (!mTmpImageA.empty()) // Aもあるので合体
|
if (!mTmpImageA.empty()) // Aもあるので合体
|
||||||
{
|
{
|
||||||
// RGBから1chに戻す
|
// RGBから1chに戻す
|
||||||
cv::cvtColor(mTmpImageA, mTmpImageA, CV_RGB2GRAY);
|
cv::cvtColor(mTmpImageA, mTmpImageA, cv::COLOR_RGB2GRAY);
|
||||||
|
|
||||||
planes.push_back(mTmpImageA);
|
planes.push_back(mTmpImageA);
|
||||||
mTmpImageA.release();
|
mTmpImageA.release();
|
||||||
@ -775,7 +744,7 @@ void stImage::ShrinkImage(const int width, const int height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Mat stImage::DeconvertFromFloat(const cv::Mat &im, const int depth)
|
cv::Mat stImage::DeconvertFromFloat(const cv::Mat& im, const int depth)
|
||||||
{
|
{
|
||||||
const int cv_depth = DepthBitToCVDepth(depth);
|
const int cv_depth = DepthBitToCVDepth(depth);
|
||||||
const double max_val = GetValumeMaxFromCVDepth(cv_depth);
|
const double max_val = GetValumeMaxFromCVDepth(cv_depth);
|
||||||
@ -793,15 +762,15 @@ cv::Mat stImage::DeconvertFromFloat(const cv::Mat &im, const int depth)
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void AlphaZeroToZero(std::vector<cv::Mat> &planes)
|
void AlphaZeroToZero(std::vector<cv::Mat>& planes)
|
||||||
{
|
{
|
||||||
cv::Mat alpha(planes[3]);
|
cv::Mat alpha(planes[3]);
|
||||||
|
|
||||||
const T *aptr = (const T *)alpha.data;
|
const T* aptr = (const T*)alpha.data;
|
||||||
|
|
||||||
T *ptr0 = (T *)planes[0].data;
|
T* ptr0 = (T*)planes[0].data;
|
||||||
T *ptr1 = (T *)planes[1].data;
|
T* ptr1 = (T*)planes[1].data;
|
||||||
T *ptr2 = (T *)planes[2].data;
|
T* ptr2 = (T*)planes[2].data;
|
||||||
|
|
||||||
const size_t Line = alpha.step1();
|
const size_t Line = alpha.step1();
|
||||||
const size_t Width = alpha.size().width;
|
const size_t Width = alpha.size().width;
|
||||||
@ -820,7 +789,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stImage::AlphaCleanImage(cv::Mat &im)
|
void stImage::AlphaCleanImage(cv::Mat& im)
|
||||||
{
|
{
|
||||||
// 完全透明のピクセルの色を消す(処理の都合上、完全透明のピクセルにも色を付けたから)
|
// 完全透明のピクセルの色を消す(処理の都合上、完全透明のピクセルにも色を付けたから)
|
||||||
// モデルによっては画像全域の完全透明の場所にごく小さい値のアルファが広がることがある。それを消すためにcv_depthへ変換してからこの処理を行うことにした
|
// モデルによっては画像全域の完全透明の場所にごく小さい値のアルファが広がることがある。それを消すためにcv_depthへ変換してからこの処理を行うことにした
|
||||||
@ -858,7 +827,7 @@ void stImage::AlphaCleanImage(cv::Mat &im)
|
|||||||
|
|
||||||
|
|
||||||
// 入力画像をzoom_sizeの大きさにcv::INTER_CUBICで拡大し、色情報のみを残す
|
// 入力画像をzoom_sizeの大きさにcv::INTER_CUBICで拡大し、色情報のみを残す
|
||||||
Waifu2x::eWaifu2xError stImage::CreateZoomColorImage(const cv::Mat &float_image, const cv::Size_<int> &zoom_size, std::vector<cv::Mat> &cubic_planes)
|
Waifu2x::eWaifu2xError stImage::CreateZoomColorImage(const cv::Mat& float_image, const cv::Size_<int>& zoom_size, std::vector<cv::Mat>& cubic_planes)
|
||||||
{
|
{
|
||||||
cv::Mat zoom_cubic_image;
|
cv::Mat zoom_cubic_image;
|
||||||
cv::resize(float_image, zoom_cubic_image, zoom_size, 0.0, 0.0, cv::INTER_CUBIC);
|
cv::resize(float_image, zoom_cubic_image, zoom_size, 0.0, 0.0, cv::INTER_CUBIC);
|
||||||
@ -881,19 +850,19 @@ cv::Mat stImage::GetEndImage() const
|
|||||||
return mEndImage;
|
return mEndImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError stImage::Save(const boost::filesystem::path &output_file, const boost::optional<int> &output_quality)
|
Waifu2x::eWaifu2xError stImage::Save(const std::filesystem::path& output_file, const std::optional<int>& output_quality)
|
||||||
{
|
{
|
||||||
return WriteMat(mEndImage, output_file, output_quality);
|
return WriteMat(mEndImage, output_file, output_quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError stImage::WriteMat(const cv::Mat &im, const boost::filesystem::path &output_file, const boost::optional<int> &output_quality)
|
Waifu2x::eWaifu2xError stImage::WriteMat(const cv::Mat& im, const std::filesystem::path& output_file, const std::optional<int>& output_quality)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path ip(output_file);
|
const std::filesystem::path ip(output_file);
|
||||||
const std::string ext = ip.extension().string();
|
const std::string ext = ip.extension().string();
|
||||||
|
|
||||||
if (boost::iequals(ext, ".tga"))
|
if (boost::iequals(ext, ".tga"))
|
||||||
{
|
{
|
||||||
unsigned char *data = im.data;
|
unsigned char* data = im.data;
|
||||||
|
|
||||||
std::vector<unsigned char> rgbimg;
|
std::vector<unsigned char> rgbimg;
|
||||||
if (im.channels() >= 3 || im.step1() != im.size().width * im.channels()) // RGB用バッファにコピー(あるいはパディングをとる)
|
if (im.channels() >= 3 || im.step1() != im.size().width * im.channels()) // RGB用バッファにコピー(あるいはパディングをとる)
|
||||||
@ -943,8 +912,8 @@ Waifu2x::eWaifu2xError stImage::WriteMat(const cv::Mat &im, const boost::filesys
|
|||||||
|
|
||||||
// RLE圧縮の設定
|
// RLE圧縮の設定
|
||||||
bool isSet = false;
|
bool isSet = false;
|
||||||
const auto &OutputExtentionList = stImage::OutputExtentionList;
|
const auto& OutputExtentionList = stImage::OutputExtentionList;
|
||||||
for (const auto &elm : OutputExtentionList)
|
for (const auto& elm : OutputExtentionList)
|
||||||
{
|
{
|
||||||
if (elm.ext == L".tga")
|
if (elm.ext == L".tga")
|
||||||
{
|
{
|
||||||
@ -970,13 +939,13 @@ Waifu2x::eWaifu2xError stImage::WriteMat(const cv::Mat &im, const boost::filesys
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const boost::filesystem::path op(output_file);
|
const std::filesystem::path op(output_file);
|
||||||
const boost::filesystem::path opext(op.extension());
|
const std::filesystem::path opext(op.extension());
|
||||||
|
|
||||||
std::vector<int> params;
|
std::vector<int> params;
|
||||||
|
|
||||||
const auto &OutputExtentionList = stImage::OutputExtentionList;
|
const auto& OutputExtentionList = stImage::OutputExtentionList;
|
||||||
for (const auto &elm : OutputExtentionList)
|
for (const auto& elm : OutputExtentionList)
|
||||||
{
|
{
|
||||||
if (elm.ext == opext)
|
if (elm.ext == opext)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,10 +28,10 @@ public:
|
|||||||
{
|
{
|
||||||
std::wstring ext;
|
std::wstring ext;
|
||||||
std::vector<int> depthList;
|
std::vector<int> depthList;
|
||||||
boost::optional<int> imageQualityStart;
|
std::optional<int> imageQualityStart;
|
||||||
boost::optional<int> imageQualityEnd;
|
std::optional<int> imageQualityEnd;
|
||||||
boost::optional<int> imageQualityDefault;
|
std::optional<int> imageQualityDefault;
|
||||||
boost::optional<int> imageQualitySettingVolume;
|
std::optional<int> imageQualitySettingVolume;
|
||||||
};
|
};
|
||||||
|
|
||||||
const static std::vector<stOutputExtentionElement> OutputExtentionList;
|
const static std::vector<stOutputExtentionElement> OutputExtentionList;
|
||||||
@ -46,7 +46,7 @@ private:
|
|||||||
static cv::Mat DeconvertFromFloat(const cv::Mat &im, const int depth);
|
static cv::Mat DeconvertFromFloat(const cv::Mat &im, const int depth);
|
||||||
static void AlphaCleanImage(cv::Mat &im);
|
static void AlphaCleanImage(cv::Mat &im);
|
||||||
|
|
||||||
static Waifu2x::eWaifu2xError WriteMat(const cv::Mat &im, const boost::filesystem::path &output_file, const boost::optional<int> &output_quality);
|
static Waifu2x::eWaifu2xError WriteMat(const cv::Mat &im, const std::filesystem::path &output_file, const std::optional<int> &output_quality);
|
||||||
|
|
||||||
// im(1ch)が単色で構成されているか判定
|
// im(1ch)が単色で構成されているか判定
|
||||||
static bool IsOneColor(const cv::Mat &im);
|
static bool IsOneColor(const cv::Mat &im);
|
||||||
@ -81,9 +81,9 @@ public:
|
|||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
static Waifu2x::eWaifu2xError LoadMat(cv::Mat &im, const boost::filesystem::path &input_file);
|
static Waifu2x::eWaifu2xError LoadMat(cv::Mat &im, const std::filesystem::path &input_file);
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError Load(const boost::filesystem::path &input_file);
|
Waifu2x::eWaifu2xError Load(const std::filesystem::path &input_file);
|
||||||
|
|
||||||
// source: (4チャンネルの場合は)RGBAな画素配列
|
// source: (4チャンネルの場合は)RGBAな画素配列
|
||||||
// dest: (4チャンネルの場合は)処理したRGBAな画素配列
|
// dest: (4チャンネルの場合は)処理したRGBAな画素配列
|
||||||
@ -130,5 +130,5 @@ public:
|
|||||||
|
|
||||||
cv::Mat GetEndImage() const;
|
cv::Mat GetEndImage() const;
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError Save(const boost::filesystem::path &output_file, const boost::optional<int> &output_quality);
|
Waifu2x::eWaifu2xError Save(const std::filesystem::path &output_file, const std::optional<int> &output_quality);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -327,7 +327,7 @@ private:
|
|||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
boost::filesystem::remove(SavePath);
|
std::filesystem::remove(SavePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -550,7 +550,7 @@ Waifu2x::~Waifu2x()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noise_level,
|
Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noise_level,
|
||||||
const boost::filesystem::path &model_dir, const std::string &process, const int GPUNo)
|
const std::filesystem::path &model_dir, const std::string &process, const int GPUNo)
|
||||||
{
|
{
|
||||||
Waifu2x::eWaifu2xError ret;
|
Waifu2x::eWaifu2xError ret;
|
||||||
|
|
||||||
@ -581,38 +581,38 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
|
|||||||
if (Process == "cudnn")
|
if (Process == "cudnn")
|
||||||
{
|
{
|
||||||
// exeのディレクトリにcuDNNのアルゴリズムデータ保存
|
// exeのディレクトリにcuDNNのアルゴリズムデータ保存
|
||||||
boost::filesystem::path cudnn_data_base_dir_path(ExeDir);
|
std::filesystem::path cudnn_data_base_dir_path(ExeDir);
|
||||||
if (cudnn_data_base_dir_path.is_relative())
|
if (cudnn_data_base_dir_path.is_relative())
|
||||||
cudnn_data_base_dir_path = boost::filesystem::system_complete(cudnn_data_base_dir_path);
|
cudnn_data_base_dir_path = std::filesystem::system_complete(cudnn_data_base_dir_path);
|
||||||
|
|
||||||
if (!boost::filesystem::is_directory(cudnn_data_base_dir_path))
|
if (!std::filesystem::is_directory(cudnn_data_base_dir_path))
|
||||||
cudnn_data_base_dir_path = cudnn_data_base_dir_path.branch_path();
|
cudnn_data_base_dir_path = cudnn_data_base_dir_path.branch_path();
|
||||||
|
|
||||||
if (!boost::filesystem::exists(cudnn_data_base_dir_path))
|
if (!std::filesystem::exists(cudnn_data_base_dir_path))
|
||||||
{
|
{
|
||||||
// exeのディレクトリが取得できなければカレントディレクトリに保存
|
// exeのディレクトリが取得できなければカレントディレクトリに保存
|
||||||
|
|
||||||
cudnn_data_base_dir_path = boost::filesystem::current_path();
|
cudnn_data_base_dir_path = std::filesystem::current_path();
|
||||||
|
|
||||||
if (cudnn_data_base_dir_path.is_relative())
|
if (cudnn_data_base_dir_path.is_relative())
|
||||||
cudnn_data_base_dir_path = boost::filesystem::system_complete(cudnn_data_base_dir_path);
|
cudnn_data_base_dir_path = std::filesystem::system_complete(cudnn_data_base_dir_path);
|
||||||
|
|
||||||
if (!boost::filesystem::exists(cudnn_data_base_dir_path))
|
if (!std::filesystem::exists(cudnn_data_base_dir_path))
|
||||||
cudnn_data_base_dir_path = "./";
|
cudnn_data_base_dir_path = "./";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boost::filesystem::exists(cudnn_data_base_dir_path))
|
if (std::filesystem::exists(cudnn_data_base_dir_path))
|
||||||
{
|
{
|
||||||
const boost::filesystem::path cudnn_data_dir_path(cudnn_data_base_dir_path / "cudnn_data");
|
const std::filesystem::path cudnn_data_dir_path(cudnn_data_base_dir_path / "cudnn_data");
|
||||||
|
|
||||||
bool isOK = false;
|
bool isOK = false;
|
||||||
if (boost::filesystem::exists(cudnn_data_dir_path))
|
if (std::filesystem::exists(cudnn_data_dir_path))
|
||||||
isOK = true;
|
isOK = true;
|
||||||
|
|
||||||
if (!isOK)
|
if (!isOK)
|
||||||
{
|
{
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
const bool result = boost::filesystem::create_directory(cudnn_data_dir_path, error);
|
const bool result = std::filesystem::create_directory(cudnn_data_dir_path, error);
|
||||||
if (result && !error)
|
if (result && !error)
|
||||||
isOK = true;
|
isOK = true;
|
||||||
}
|
}
|
||||||
@ -628,8 +628,8 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
|
|||||||
std::string deconv_filename(prop.name);
|
std::string deconv_filename(prop.name);
|
||||||
deconv_filename += " deconv ";
|
deconv_filename += " deconv ";
|
||||||
|
|
||||||
const boost::filesystem::path conv_data_path = cudnn_data_dir_path / conv_filename;
|
const std::filesystem::path conv_data_path = cudnn_data_dir_path / conv_filename;
|
||||||
const boost::filesystem::path deconv_data_path = cudnn_data_dir_path / deconv_filename;
|
const std::filesystem::path deconv_data_path = cudnn_data_dir_path / deconv_filename;
|
||||||
|
|
||||||
g_ConvCcuDNNAlgorithm.SetDataPath(conv_data_path.string());
|
g_ConvCcuDNNAlgorithm.SetDataPath(conv_data_path.string());
|
||||||
g_DeconvCcuDNNAlgorithm.SetDataPath(deconv_data_path.string());
|
g_DeconvCcuDNNAlgorithm.SetDataPath(deconv_data_path.string());
|
||||||
@ -638,8 +638,8 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::filesystem::path mode_dir_path(GetModeDirPath(model_dir));
|
const std::filesystem::path mode_dir_path(GetModeDirPath(model_dir));
|
||||||
if (!boost::filesystem::exists(mode_dir_path))
|
if (!std::filesystem::exists(mode_dir_path))
|
||||||
return Waifu2x::eWaifu2xError_FailedOpenModelFile;
|
return Waifu2x::eWaifu2xError_FailedOpenModelFile;
|
||||||
|
|
||||||
CudaDeviceSet devset(process, mGPUNo);
|
CudaDeviceSet devset(process, mGPUNo);
|
||||||
@ -661,7 +661,7 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
|
|||||||
mInputPlane = 0;
|
mInputPlane = 0;
|
||||||
mMaxNetOffset = 0;
|
mMaxNetOffset = 0;
|
||||||
|
|
||||||
const boost::filesystem::path info_path = GetInfoPath(mode_dir_path);
|
const std::filesystem::path info_path = GetInfoPath(mode_dir_path);
|
||||||
|
|
||||||
stInfo info;
|
stInfo info;
|
||||||
ret = cNet::GetInfo(info_path, info);
|
ret = cNet::GetInfo(info_path, info);
|
||||||
@ -693,8 +693,8 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
|
|||||||
base_name = "noise" + std::to_string(noise_level) + "_model";
|
base_name = "noise" + std::to_string(noise_level) + "_model";
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::filesystem::path model_path = mode_dir_path / (base_name + ".prototxt");
|
const std::filesystem::path model_path = mode_dir_path / (base_name + ".prototxt");
|
||||||
const boost::filesystem::path param_path = mode_dir_path / (base_name + ".json");
|
const std::filesystem::path param_path = mode_dir_path / (base_name + ".json");
|
||||||
|
|
||||||
ret = mNoiseNet->ConstractNet(Mode, model_path, param_path, info, mProcess);
|
ret = mNoiseNet->ConstractNet(Mode, model_path, param_path, info, mProcess);
|
||||||
if (ret != Waifu2x::eWaifu2xError_OK)
|
if (ret != Waifu2x::eWaifu2xError_OK)
|
||||||
@ -708,8 +708,8 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
|
|||||||
{
|
{
|
||||||
const std::string base_name = "scale2.0x_model";
|
const std::string base_name = "scale2.0x_model";
|
||||||
|
|
||||||
const boost::filesystem::path model_path = mode_dir_path / (base_name + ".prototxt");
|
const std::filesystem::path model_path = mode_dir_path / (base_name + ".prototxt");
|
||||||
const boost::filesystem::path param_path = mode_dir_path / (base_name + ".json");
|
const std::filesystem::path param_path = mode_dir_path / (base_name + ".json");
|
||||||
|
|
||||||
mScaleNet.reset(new cNet);
|
mScaleNet.reset(new cNet);
|
||||||
|
|
||||||
@ -736,16 +736,16 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path Waifu2x::GetModeDirPath(const boost::filesystem::path &model_dir)
|
std::filesystem::path Waifu2x::GetModeDirPath(const std::filesystem::path &model_dir)
|
||||||
{
|
{
|
||||||
boost::filesystem::path mode_dir_path(model_dir);
|
std::filesystem::path mode_dir_path(model_dir);
|
||||||
if (!mode_dir_path.is_absolute()) // model_dirが相対パスなら絶対パスに直す
|
if (!mode_dir_path.is_absolute()) // model_dirが相対パスなら絶対パスに直す
|
||||||
{
|
{
|
||||||
// まずはカレントディレクトリ下にあるか探す
|
// まずはカレントディレクトリ下にあるか探す
|
||||||
mode_dir_path = boost::filesystem::absolute(model_dir);
|
mode_dir_path = std::filesystem::absolute(model_dir);
|
||||||
if (!boost::filesystem::exists(mode_dir_path) && !ExeDir.empty()) // 無かったらargv[0]から実行ファイルのあるフォルダを推定し、そのフォルダ下にあるか探す
|
if (!std::filesystem::exists(mode_dir_path) && !ExeDir.empty()) // 無かったらargv[0]から実行ファイルのあるフォルダを推定し、そのフォルダ下にあるか探す
|
||||||
{
|
{
|
||||||
boost::filesystem::path a0(ExeDir);
|
std::filesystem::path a0(ExeDir);
|
||||||
if (a0.is_absolute())
|
if (a0.is_absolute())
|
||||||
mode_dir_path = a0.branch_path() / model_dir;
|
mode_dir_path = a0.branch_path() / model_dir;
|
||||||
}
|
}
|
||||||
@ -754,17 +754,17 @@ boost::filesystem::path Waifu2x::GetModeDirPath(const boost::filesystem::path &m
|
|||||||
return mode_dir_path;
|
return mode_dir_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path Waifu2x::GetInfoPath(const boost::filesystem::path &mode_dir_path)
|
std::filesystem::path Waifu2x::GetInfoPath(const std::filesystem::path &mode_dir_path)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path info_path = mode_dir_path / "info.json";
|
const std::filesystem::path info_path = mode_dir_path / "info.json";
|
||||||
|
|
||||||
return info_path;
|
return info_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError Waifu2x::waifu2x(const boost::filesystem::path &input_file, const boost::filesystem::path &output_file,
|
Waifu2x::eWaifu2xError Waifu2x::waifu2x(const std::filesystem::path &input_file, const std::filesystem::path &output_file,
|
||||||
const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
const std::optional<double> scale_ratio, const std::optional<int> scale_width, const std::optional<int> scale_height,
|
||||||
const waifu2xCancelFunc cancel_func, const int crop_w, const int crop_h,
|
const waifu2xCancelFunc cancel_func, const int crop_w, const int crop_h,
|
||||||
const boost::optional<int> output_quality, const int output_depth, const bool use_tta,
|
const std::optional<int> output_quality, const int output_depth, const bool use_tta,
|
||||||
const int batch_size)
|
const int batch_size)
|
||||||
{
|
{
|
||||||
Waifu2x::eWaifu2xError ret;
|
Waifu2x::eWaifu2xError ret;
|
||||||
@ -867,7 +867,7 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const double factor, const void* source,
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Factor Waifu2x::CalcScaleRatio(const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
Factor Waifu2x::CalcScaleRatio(const std::optional<double> scale_ratio, const std::optional<int> scale_width, const std::optional<int> scale_height,
|
||||||
const stImage &image)
|
const stImage &image)
|
||||||
{
|
{
|
||||||
if (scale_ratio)
|
if (scale_ratio)
|
||||||
@ -1155,24 +1155,24 @@ const std::string& Waifu2x::used_process() const
|
|||||||
return mProcess;
|
return mProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Waifu2x::GetModelName(const boost::filesystem::path & model_dir)
|
std::string Waifu2x::GetModelName(const std::filesystem::path & model_dir)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path mode_dir_path(GetModeDirPath(model_dir));
|
const std::filesystem::path mode_dir_path(GetModeDirPath(model_dir));
|
||||||
if (!boost::filesystem::exists(mode_dir_path))
|
if (!std::filesystem::exists(mode_dir_path))
|
||||||
return std::string();
|
return std::string();
|
||||||
|
|
||||||
const boost::filesystem::path info_path = mode_dir_path / "info.json";
|
const std::filesystem::path info_path = mode_dir_path / "info.json";
|
||||||
|
|
||||||
return cNet::GetModelName(info_path);
|
return cNet::GetModelName(info_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Waifu2x::GetInfo(const boost::filesystem::path &model_dir, stInfo &info)
|
bool Waifu2x::GetInfo(const std::filesystem::path &model_dir, stInfo &info)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path mode_dir_path(GetModeDirPath(model_dir));
|
const std::filesystem::path mode_dir_path(GetModeDirPath(model_dir));
|
||||||
if (!boost::filesystem::exists(mode_dir_path))
|
if (!std::filesystem::exists(mode_dir_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const boost::filesystem::path info_path = mode_dir_path / "info.json";
|
const std::filesystem::path info_path = mode_dir_path / "info.json";
|
||||||
|
|
||||||
return cNet::GetInfo(info_path, info) == Waifu2x::eWaifu2xError_OK;
|
return cNet::GetInfo(info_path, info) == Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <memory>
|
||||||
#include <boost/filesystem.hpp>
|
#include <filesystem>
|
||||||
#include <boost/optional.hpp>
|
#include <optional>
|
||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
#define CUDNN_DLL_NAME "cudnn64_8.dll"
|
#define CUDNN_DLL_NAME "cudnn64_8.dll"
|
||||||
@ -146,31 +146,31 @@ private:
|
|||||||
int mMaxNetOffset; // ネットに入力するとどれくらい削れるか
|
int mMaxNetOffset; // ネットに入力するとどれくらい削れるか
|
||||||
bool mHasNoiseScaleOnly;
|
bool mHasNoiseScaleOnly;
|
||||||
|
|
||||||
float *mOutputBlock;
|
float* mOutputBlock;
|
||||||
size_t mOutputBlockSize;
|
size_t mOutputBlockSize;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static boost::filesystem::path GetModeDirPath(const boost::filesystem::path &model_dir);
|
static std::filesystem::path GetModeDirPath(const std::filesystem::path& model_dir);
|
||||||
static boost::filesystem::path GetInfoPath(const boost::filesystem::path &model_dir);
|
static std::filesystem::path GetInfoPath(const std::filesystem::path& model_dir);
|
||||||
|
|
||||||
static Factor CalcScaleRatio(const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
static Factor CalcScaleRatio(const std::optional<double> scale_ratio, const std::optional<int> scale_width, const std::optional<int> scale_height,
|
||||||
const stImage &image);
|
const stImage& image);
|
||||||
|
|
||||||
static int GetcuDNNAlgorithm(const char *layer_name, int num_input, int num_output, int batch_size,
|
static int GetcuDNNAlgorithm(const char* layer_name, int num_input, int num_output, int batch_size,
|
||||||
int width, int height, int kernel_w, int kernel_h, int pad_w, int pad_h, int stride_w, int stride_h);
|
int width, int height, int kernel_w, int kernel_h, int pad_w, int pad_h, int stride_w, int stride_h);
|
||||||
|
|
||||||
static void SetcuDNNAlgorithm(int algo, const char *layer_name, int num_input, int num_output, int batch_size,
|
static void SetcuDNNAlgorithm(int algo, const char* layer_name, int num_input, int num_output, int batch_size,
|
||||||
int width, int height, int kernel_w, int kernel_h, int pad_w, int pad_h, int stride_w, int stride_h);
|
int width, int height, int kernel_w, int kernel_h, int pad_w, int pad_h, int stride_w, int stride_h);
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError ReconstructImage(const Factor factor, const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
Waifu2x::eWaifu2xError ReconstructImage(const Factor factor, const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
||||||
const bool isReconstructNoise, const bool isReconstructScale, const Waifu2x::waifu2xCancelFunc cancel_func, stImage &image);
|
const bool isReconstructNoise, const bool isReconstructScale, const Waifu2x::waifu2xCancelFunc cancel_func, stImage& image);
|
||||||
Waifu2x::eWaifu2xError ReconstructScale(const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
Waifu2x::eWaifu2xError ReconstructScale(const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
||||||
const Waifu2x::waifu2xCancelFunc cancel_func, stImage &image);
|
const Waifu2x::waifu2xCancelFunc cancel_func, stImage& image);
|
||||||
Waifu2x::eWaifu2xError ReconstructNoiseScale(const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
Waifu2x::eWaifu2xError ReconstructNoiseScale(const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
||||||
const Waifu2x::waifu2xCancelFunc cancel_func, stImage &image);
|
const Waifu2x::waifu2xCancelFunc cancel_func, stImage& image);
|
||||||
Waifu2x::eWaifu2xError ReconstructByNet(std::shared_ptr<cNet> net, const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
Waifu2x::eWaifu2xError ReconstructByNet(std::shared_ptr<cNet> net, const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
||||||
const Waifu2x::waifu2xCancelFunc cancel_func, cv::Mat &im);
|
const Waifu2x::waifu2xCancelFunc cancel_func, cv::Mat& im);
|
||||||
Waifu2x::eWaifu2xError ProcessNet(std::shared_ptr<cNet> net, const int crop_w, const int crop_h, const bool use_tta, const int batch_size, cv::Mat &im);
|
Waifu2x::eWaifu2xError ProcessNet(std::shared_ptr<cNet> net, const int crop_w, const int crop_h, const bool use_tta, const int batch_size, cv::Mat& im);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Waifu2x();
|
Waifu2x();
|
||||||
@ -186,12 +186,12 @@ public:
|
|||||||
// mode: noise or scale or noise_scale or auto_scale
|
// mode: noise or scale or noise_scale or auto_scale
|
||||||
// process: cpu or gpu or cudnn
|
// process: cpu or gpu or cudnn
|
||||||
eWaifu2xError Init(const eWaifu2xModelType mode, const int noise_level,
|
eWaifu2xError Init(const eWaifu2xModelType mode, const int noise_level,
|
||||||
const boost::filesystem::path &model_dir, const std::string &process, const int gpu_no = 0);
|
const std::filesystem::path& model_dir, const std::string& process, const int gpu_no = 0);
|
||||||
|
|
||||||
eWaifu2xError waifu2x(const boost::filesystem::path &input_file, const boost::filesystem::path &output_file,
|
eWaifu2xError waifu2x(const std::filesystem::path& input_file, const std::filesystem::path& output_file,
|
||||||
const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
const std::optional<double> scale_ratio, const std::optional<int> scale_width, const std::optional<int> scale_height,
|
||||||
const waifu2xCancelFunc cancel_func = nullptr, const int crop_w = 128, const int crop_h = 128,
|
const waifu2xCancelFunc cancel_func = nullptr, const int crop_w = 128, const int crop_h = 128,
|
||||||
const boost::optional<int> output_quality = boost::optional<int>(), const int output_depth = 8, const bool use_tta = false,
|
const std::optional<int> output_quality = std::optional<int>(), const int output_depth = 8, const bool use_tta = false,
|
||||||
const int batch_size = 1);
|
const int batch_size = 1);
|
||||||
|
|
||||||
// factor: 倍率
|
// factor: 倍率
|
||||||
@ -201,12 +201,12 @@ public:
|
|||||||
// out_stride: destのストライド(バイト単位)
|
// out_stride: destのストライド(バイト単位)
|
||||||
eWaifu2xError waifu2x(const double factor, const void* source, void* dest, const int width, const int height,
|
eWaifu2xError waifu2x(const double factor, const void* source, void* dest, const int width, const int height,
|
||||||
const int in_channel, const int in_stride, const int out_channel, const int out_stride,
|
const int in_channel, const int in_stride, const int out_channel, const int out_stride,
|
||||||
const int crop_w = 128, const int crop_h = 128, const bool use_tta = false, const int batch_size = 1);
|
const int crop_w = 128, const int crop_h = 128, const bool use_tta = false, const int batch_size = 1);
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
const std::string& used_process() const;
|
const std::string& used_process() const;
|
||||||
|
|
||||||
static std::string GetModelName(const boost::filesystem::path &model_dir);
|
static std::string GetModelName(const std::filesystem::path& model_dir);
|
||||||
static bool GetInfo(const boost::filesystem::path &model_dir, stInfo &info);
|
static bool GetInfo(const std::filesystem::path& model_dir, stInfo& info);
|
||||||
};
|
};
|
||||||
|
|||||||
2
opencv
2
opencv
@ -1 +1 @@
|
|||||||
Subproject commit b38c50b3d0c31e82294315ec44b54b7ef559ef12
|
Subproject commit 6d889ee74c94124f6492eb8f0d50946d9c31d8e9
|
||||||
@ -1,10 +1,21 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
|
||||||
|
|
||||||
|
cd /d "%~dp0"
|
||||||
|
|
||||||
|
rem wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.12.0.zip
|
||||||
|
rem opencv_contrib.zip を解凍します。
|
||||||
|
rem cmake -D OPENCV_EXTRA_MODULES_PATH=%~dp0\opencv_contrib-4.12.0\modules
|
||||||
|
|
||||||
cd opencv
|
cd opencv
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
|
|
||||||
cmake .. -G "Visual Studio 15 Win64" ^
|
set CFLAGS=/Zc:preprocessor
|
||||||
|
set CXXFLAGS=/Zc:preprocessor
|
||||||
|
|
||||||
|
cmake .. -G Ninja ^
|
||||||
-DCMAKE_INSTALL_PREFIX=..\..\lib ^
|
-DCMAKE_INSTALL_PREFIX=..\..\lib ^
|
||||||
-DBUILD_WITH_STATIC_CRT=OFF ^
|
-DBUILD_WITH_STATIC_CRT=OFF ^
|
||||||
-DBUILD_IPP_IW=OFF ^
|
-DBUILD_IPP_IW=OFF ^
|
||||||
@ -12,8 +23,8 @@ cmake .. -G "Visual Studio 15 Win64" ^
|
|||||||
-DBUILD_JAVA=OFF ^
|
-DBUILD_JAVA=OFF ^
|
||||||
-DBUILD_SHARED_LIBS=OFF ^
|
-DBUILD_SHARED_LIBS=OFF ^
|
||||||
-DBUILD_TESTS=OFF ^
|
-DBUILD_TESTS=OFF ^
|
||||||
|
-DBUILD_PERF_TESTS=OFF ^
|
||||||
-DBUILD_opencv_calib3d=OFF ^
|
-DBUILD_opencv_calib3d=OFF ^
|
||||||
-DBUILD_opencv_dnn=OFF ^
|
|
||||||
-DBUILD_opencv_features2d=OFF ^
|
-DBUILD_opencv_features2d=OFF ^
|
||||||
-DBUILD_opencv_flann=OFF ^
|
-DBUILD_opencv_flann=OFF ^
|
||||||
-DBUILD_opencv_highgui=OFF ^
|
-DBUILD_opencv_highgui=OFF ^
|
||||||
@ -25,9 +36,60 @@ cmake .. -G "Visual Studio 15 Win64" ^
|
|||||||
-DBUILD_opencv_videostab=OFF ^
|
-DBUILD_opencv_videostab=OFF ^
|
||||||
-DBUILD_opencv_java_bindings_generator=OFF ^
|
-DBUILD_opencv_java_bindings_generator=OFF ^
|
||||||
-DBUILD_opencv_python_bindings_generator=OFF ^
|
-DBUILD_opencv_python_bindings_generator=OFF ^
|
||||||
|
-DBUILD_opencv_apps=OFF ^
|
||||||
|
-DBUILD_opencv_aruco=OFF ^
|
||||||
|
-DBUILD_opencv_bgsegm=OFF ^
|
||||||
|
-DBUILD_opencv_bioinspired=OFF ^
|
||||||
|
-DBUILD_opencv_ccalib=OFF ^
|
||||||
|
-DBUILD_opencv_cudaarithm=OFF ^
|
||||||
|
-DBUILD_opencv_cudabgsegm=OFF ^
|
||||||
|
-DBUILD_opencv_cudacodec=OFF ^
|
||||||
|
-DBUILD_opencv_cudafeatures2d=OFF ^
|
||||||
|
-DBUILD_opencv_cudafilters=OFF ^
|
||||||
|
-DBUILD_opencv_cudaimgproc=OFF ^
|
||||||
|
-DBUILD_opencv_cudalegacy=OFF ^
|
||||||
|
-DBUILD_opencv_cudaobjdetect=OFF ^
|
||||||
|
-DBUILD_opencv_cudaoptflow=OFF ^
|
||||||
|
-DBUILD_opencv_cudastereo=OFF ^
|
||||||
|
-DBUILD_opencv_cudawarping=OFF ^
|
||||||
|
-DBUILD_opencv_cudev=OFF ^
|
||||||
|
-DBUILD_opencv_datasets=OFF ^
|
||||||
|
-DBUILD_opencv_face=OFF ^
|
||||||
|
-DBUILD_opencv_freetype=OFF ^
|
||||||
|
-DBUILD_opencv_fuzzy=OFF ^
|
||||||
|
-DBUILD_opencv_hfs=OFF ^
|
||||||
|
-DBUILD_opencv_img_hash=OFF ^
|
||||||
|
-DBUILD_opencv_line_descriptor=OFF ^
|
||||||
|
-DBUILD_opencv_mcc=OFF ^
|
||||||
|
-DBUILD_opencv_objc_bindings_generator=OFF ^
|
||||||
|
-DBUILD_opencv_optflow=OFF ^
|
||||||
|
-DBUILD_opencv_phase_unwrapping=OFF ^
|
||||||
|
-DBUILD_opencv_plot=OFF ^
|
||||||
|
-DBUILD_opencv_reg=OFF ^
|
||||||
|
-DBUILD_opencv_rgbd=OFF ^
|
||||||
|
-DBUILD_opencv_saliency=OFF ^
|
||||||
|
-DBUILD_opencv_shape=OFF ^
|
||||||
|
-DBUILD_opencv_stereo=OFF ^
|
||||||
|
-DBUILD_opencv_structured_light=OFF ^
|
||||||
|
-DBUILD_opencv_surface_matching=OFF ^
|
||||||
|
-DBUILD_opencv_text=OFF ^
|
||||||
|
-DBUILD_opencv_tracking=OFF ^
|
||||||
|
-DBUILD_opencv_xfeatures2d=OFF ^
|
||||||
|
-DBUILD_opencv_ximgproc=OFF ^
|
||||||
|
-DBUILD_opencv_xobjdetect=OFF ^
|
||||||
|
-DBUILD_opencv_xphoto=OFF ^
|
||||||
|
-DBUILD_opencv_python3=OFF ^
|
||||||
|
-DBUILD_opencv_python_tests=OFF ^
|
||||||
|
-DBUILD_opencv_quality=OFF ^
|
||||||
|
-DBUILD_opencv_rapid=OFF ^
|
||||||
|
-DBUILD_opencv_signal=OFF ^
|
||||||
|
-DBUILD_opencv_stitching=OFF ^
|
||||||
|
-DBUILD_opencv_wechat_qrcode=OFF ^
|
||||||
|
-DBUILD_opencv_js_bindings_generator=OFF ^
|
||||||
-DWITH_1394=OFF ^
|
-DWITH_1394=OFF ^
|
||||||
-DWITH_CUDA=OFF ^
|
-DWITH_CUDA=ON ^
|
||||||
-DWITH_CUFFT=OFF ^
|
-DWITH_CUDNN=ON ^
|
||||||
|
-DWITH_CUFFT=ON ^
|
||||||
-DWITH_DIRECTX=OFF ^
|
-DWITH_DIRECTX=OFF ^
|
||||||
-DWITH_DSHOW=OFF ^
|
-DWITH_DSHOW=OFF ^
|
||||||
-DWITH_EIGEN=OFF ^
|
-DWITH_EIGEN=OFF ^
|
||||||
@ -37,10 +99,27 @@ cmake .. -G "Visual Studio 15 Win64" ^
|
|||||||
-DWITH_OPENCAMDBALSL=OFF ^
|
-DWITH_OPENCAMDBALSL=OFF ^
|
||||||
-DWITH_OPENCLAMDFFT=OFF ^
|
-DWITH_OPENCLAMDFFT=OFF ^
|
||||||
-DWITH_OPENCL_SVM=OFF ^
|
-DWITH_OPENCL_SVM=OFF ^
|
||||||
-DWITH_PROTOBUF=OFF ^
|
-DWITH_ADE=OFF ^
|
||||||
|
-DWITH_ARITH_DEC=OFF ^
|
||||||
|
-DWITH_ARITH_ENC=OFF ^
|
||||||
|
-DWITH_IPP=OFF ^
|
||||||
|
-DWITH_ITT=OFF ^
|
||||||
-DWITH_VFW=OFF ^
|
-DWITH_VFW=OFF ^
|
||||||
-DWITH_VTK=OFF ^
|
-DWITH_VTK=OFF ^
|
||||||
-DWITH_WIN32UI=OFF
|
-DWITH_TESSERACT=OFF ^
|
||||||
|
-DWITH_WIN32UI=OFF ^
|
||||||
|
-DBUILD_opencv_dnn=ON ^
|
||||||
|
-DBUILD_opencv_cudev=ON ^
|
||||||
|
-DWITH_PROTOBUF=ON ^
|
||||||
|
-DOPENCV_DNN_CUDA=ON ^
|
||||||
|
-DCUDA_ARCH_BIN=8.9 ^
|
||||||
|
-DCUDA_ARCH_PTX=12.0 ^
|
||||||
|
-DCUDA_USE_STATIC_CUDA_RUNTIME=OFF ^
|
||||||
|
-DCMAKE_C_FLAGS="/DWIN32 /D_WINDOWS /W3 /Zc:preprocessor" ^
|
||||||
|
-DCMAKE_CXX_FLAGS="/DWIN32 /D_WINDOWS /W3 /GR /EHsc /Zc:preprocessor" ^
|
||||||
|
-DOPENCV_EXTRA_MODULES_PATH=%~dp0\opencv_contrib-4.12.0\modules ^
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug
|
||||||
|
|
||||||
rem cmake --build . --config Debug --target install
|
|
||||||
cmake --build . --config Release --target install
|
cmake --build . --config Debug --target install
|
||||||
|
rem cmake --build . --config Release --target install
|
||||||
|
|||||||
@ -18,7 +18,7 @@ void* Waifu2xInit(const char *mode, const int noise_level, const char *model_dir
|
|||||||
else if (strcmp("auto_scale", mode) == 0)
|
else if (strcmp("auto_scale", mode) == 0)
|
||||||
mt = Waifu2x::eWaifu2xModelTypeAutoScale;
|
mt = Waifu2x::eWaifu2xModelTypeAutoScale;
|
||||||
|
|
||||||
// if (obj->Init(1, argv, mode, noise_level, 2.0, boost::optional<int>(), boost::optional<int>(), model_dir, process, boost::optional<int>(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK)
|
// if (obj->Init(1, argv, mode, noise_level, 2.0, std::optional<int>(), std::optional<int>(), model_dir, process, std::optional<int>(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK)
|
||||||
if (obj->Init(mt, noise_level, model_dir, process) != Waifu2x::eWaifu2xError_OK)
|
if (obj->Init(mt, noise_level, model_dir, process) != Waifu2x::eWaifu2xError_OK)
|
||||||
{
|
{
|
||||||
delete obj;
|
delete obj;
|
||||||
@ -43,7 +43,7 @@ void* Waifu2xInitNew(const char *mode, const int noise_level, const char *model_
|
|||||||
else if (strcmp("auto_scale", mode) == 0)
|
else if (strcmp("auto_scale", mode) == 0)
|
||||||
mt = Waifu2x::eWaifu2xModelTypeAutoScale;
|
mt = Waifu2x::eWaifu2xModelTypeAutoScale;
|
||||||
|
|
||||||
// if (obj->Init(1, argv, mode, noise_level, 2.0, boost::optional<int>(), boost::optional<int>(), model_dir, process, boost::optional<int>(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK)
|
// if (obj->Init(1, argv, mode, noise_level, 2.0, std::optional<int>(), std::optional<int>(), model_dir, process, std::optional<int>(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK)
|
||||||
if (obj->Init(mt, noise_level, model_dir, process) != Waifu2x::eWaifu2xError_OK)
|
if (obj->Init(mt, noise_level, model_dir, process) != Waifu2x::eWaifu2xError_OK)
|
||||||
{
|
{
|
||||||
delete obj;
|
delete obj;
|
||||||
|
|||||||
@ -14,19 +14,19 @@
|
|||||||
<ProjectGuid>{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}</ProjectGuid>
|
<ProjectGuid>{DFF94FEB-78AB-41B1-9B92-4D8B7D799E04}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>waifu2x-caffe-dll</RootNamespace>
|
<RootNamespace>waifu2x-caffe-dll</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -61,6 +61,7 @@
|
|||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -79,6 +80,7 @@
|
|||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|||||||
@ -58,22 +58,22 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
|
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
|
||||||
boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to)
|
std::filesystem::path relativePath(const std::filesystem::path &path, const std::filesystem::path &relative_to)
|
||||||
{
|
{
|
||||||
// create absolute paths
|
// create absolute paths
|
||||||
boost::filesystem::path p = boost::filesystem::absolute(path);
|
std::filesystem::path p = std::filesystem::absolute(path);
|
||||||
boost::filesystem::path r = boost::filesystem::absolute(relative_to);
|
std::filesystem::path r = std::filesystem::absolute(relative_to);
|
||||||
|
|
||||||
// if root paths are different, return absolute path
|
// if root paths are different, return absolute path
|
||||||
if (p.root_path() != r.root_path())
|
if (p.root_path() != r.root_path())
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
// initialize relative path
|
// initialize relative path
|
||||||
boost::filesystem::path result;
|
std::filesystem::path result;
|
||||||
|
|
||||||
// find out where the two paths diverge
|
// find out where the two paths diverge
|
||||||
boost::filesystem::path::const_iterator itr_path = p.begin();
|
std::filesystem::path::const_iterator itr_path = p.begin();
|
||||||
boost::filesystem::path::const_iterator itr_relative_to = r.begin();
|
std::filesystem::path::const_iterator itr_relative_to = r.begin();
|
||||||
while (*itr_path == *itr_relative_to && itr_path != p.end() && itr_relative_to != r.end())
|
while (*itr_path == *itr_relative_to && itr_path != p.end() && itr_relative_to != r.end())
|
||||||
{
|
{
|
||||||
++itr_path;
|
++itr_path;
|
||||||
@ -497,7 +497,7 @@ bool DialogEvent::SyncMember(const bool NotSyncCropSize, const bool silent)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogEvent::SetCropSizeList(const boost::filesystem::path & input_path)
|
void DialogEvent::SetCropSizeList(const std::filesystem::path & input_path)
|
||||||
{
|
{
|
||||||
if (isSetInitCrop)
|
if (isSetInitCrop)
|
||||||
return;
|
return;
|
||||||
@ -505,7 +505,7 @@ void DialogEvent::SetCropSizeList(const boost::filesystem::path & input_path)
|
|||||||
HWND hcrop = GetDlgItem(dh, IDC_COMBO_CROP_SIZE);
|
HWND hcrop = GetDlgItem(dh, IDC_COMBO_CROP_SIZE);
|
||||||
|
|
||||||
int gcd = 1;
|
int gcd = 1;
|
||||||
if (boost::filesystem::exists(input_path) && !boost::filesystem::is_directory(input_path))
|
if (std::filesystem::exists(input_path) && !std::filesystem::is_directory(input_path))
|
||||||
{
|
{
|
||||||
cv::Mat mat;
|
cv::Mat mat;
|
||||||
const auto ret = stImage::LoadMat(mat, input_path.string());
|
const auto ret = stImage::LoadMat(mat, input_path.string());
|
||||||
@ -620,17 +620,17 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
|
|
||||||
const auto inputFunc = [this, &file_paths](const tstring &input)
|
const auto inputFunc = [this, &file_paths](const tstring &input)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path input_path(boost::filesystem::absolute(input));
|
const std::filesystem::path input_path(std::filesystem::absolute(input));
|
||||||
|
|
||||||
if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
|
if (std::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
|
||||||
{
|
{
|
||||||
boost::filesystem::path output_path(output_str);
|
std::filesystem::path output_path(output_str);
|
||||||
|
|
||||||
output_path = boost::filesystem::absolute(output_path);
|
output_path = std::filesystem::absolute(output_path);
|
||||||
|
|
||||||
if (!boost::filesystem::exists(output_path))
|
if (!std::filesystem::exists(output_path))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::create_directory(output_path))
|
if (!std::filesystem::create_directory(output_path))
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&output_path, 0);
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&output_path, 0);
|
||||||
PostMessage(dh, WM_END_THREAD, 0, 0);
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
||||||
@ -640,12 +640,12 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 変換する画像の入力、出力パスを取得
|
// 変換する画像の入力、出力パスを取得
|
||||||
const auto func = [this, &input_path, &output_path, &file_paths](const boost::filesystem::path &path)
|
const auto func = [this, &input_path, &output_path, &file_paths](const std::filesystem::path &path)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path),
|
BOOST_FOREACH(const std::filesystem::path& p, std::make_pair(std::filesystem::recursive_directory_iterator(path),
|
||||||
boost::filesystem::recursive_directory_iterator()))
|
std::filesystem::recursive_directory_iterator()))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::is_directory(p))
|
if (!std::filesystem::is_directory(p))
|
||||||
{
|
{
|
||||||
tstring ext(getTString(p.extension()));
|
tstring ext(getTString(p.extension()));
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
@ -674,12 +674,12 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
|
|
||||||
for (const auto &p : file_paths)
|
for (const auto &p : file_paths)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path out_path(p.second);
|
const std::filesystem::path out_path(p.second);
|
||||||
const boost::filesystem::path out_dir(out_path.parent_path());
|
const std::filesystem::path out_dir(out_path.parent_path());
|
||||||
|
|
||||||
if (!boost::filesystem::exists(out_dir))
|
if (!std::filesystem::exists(out_dir))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::create_directories(out_dir))
|
if (!std::filesystem::create_directories(out_dir))
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&out_dir, 0);
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&out_dir, 0);
|
||||||
PostMessage(dh, WM_END_THREAD, 0, 0);
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
||||||
@ -691,12 +691,12 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const boost::filesystem::path output_path(output_str);
|
const std::filesystem::path output_path(output_str);
|
||||||
const auto outDir = output_path.branch_path();
|
const auto outDir = output_path.branch_path();
|
||||||
|
|
||||||
if (!outDir.empty() && !boost::filesystem::exists(outDir))
|
if (!outDir.empty() && !std::filesystem::exists(outDir))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::create_directories(outDir))
|
if (!std::filesystem::create_directories(outDir))
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&outDir, 0);
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&outDir, 0);
|
||||||
PostMessage(dh, WM_END_THREAD, 0, 0);
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
||||||
@ -711,8 +711,8 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
|
|
||||||
const auto inputFuncMulti = [this, &file_paths](const tstring &input)
|
const auto inputFuncMulti = [this, &file_paths](const tstring &input)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path input_path(boost::filesystem::absolute(input));
|
const std::filesystem::path input_path(std::filesystem::absolute(input));
|
||||||
const boost::filesystem::path output_path(boost::filesystem::absolute(output_str));
|
const std::filesystem::path output_path(std::filesystem::absolute(output_str));
|
||||||
|
|
||||||
const auto outilenameFunc = [&output_path](const tstring &path) -> std::wstring
|
const auto outilenameFunc = [&output_path](const tstring &path) -> std::wstring
|
||||||
{
|
{
|
||||||
@ -720,11 +720,11 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
return out.wstring();
|
return out.wstring();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
|
if (std::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::exists(output_path))
|
if (!std::filesystem::exists(output_path))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::create_directory(output_path))
|
if (!std::filesystem::create_directory(output_path))
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&output_path, 0);
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&output_path, 0);
|
||||||
PostMessage(dh, WM_END_THREAD, 0, 0);
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
||||||
@ -736,12 +736,12 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
const auto inputDirName = input_path.filename();
|
const auto inputDirName = input_path.filename();
|
||||||
|
|
||||||
// 変換する画像の入力、出力パスを取得
|
// 変換する画像の入力、出力パスを取得
|
||||||
const auto func = [this, &input_path, &output_path, &file_paths, &inputDirName](const boost::filesystem::path &path)
|
const auto func = [this, &input_path, &output_path, &file_paths, &inputDirName](const std::filesystem::path &path)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path),
|
BOOST_FOREACH(const std::filesystem::path& p, std::make_pair(std::filesystem::recursive_directory_iterator(path),
|
||||||
boost::filesystem::recursive_directory_iterator()))
|
std::filesystem::recursive_directory_iterator()))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::is_directory(p))
|
if (!std::filesystem::is_directory(p))
|
||||||
{
|
{
|
||||||
tstring ext(getTString(p.extension()));
|
tstring ext(getTString(p.extension()));
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
@ -770,12 +770,12 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
|
|
||||||
for (const auto &p : file_paths)
|
for (const auto &p : file_paths)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path out_path(p.second);
|
const std::filesystem::path out_path(p.second);
|
||||||
const boost::filesystem::path out_dir(out_path.parent_path());
|
const std::filesystem::path out_dir(out_path.parent_path());
|
||||||
|
|
||||||
if (!boost::filesystem::exists(out_dir))
|
if (!std::filesystem::exists(out_dir))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::create_directories(out_dir))
|
if (!std::filesystem::create_directories(out_dir))
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&out_dir, 0);
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&out_dir, 0);
|
||||||
PostMessage(dh, WM_END_THREAD, 0, 0);
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
||||||
@ -789,9 +789,9 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
{
|
{
|
||||||
const auto &outDir = output_path;
|
const auto &outDir = output_path;
|
||||||
|
|
||||||
if (!boost::filesystem::exists(outDir))
|
if (!std::filesystem::exists(outDir))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::create_directories(outDir))
|
if (!std::filesystem::create_directories(outDir))
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&outDir, 0);
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&outDir, 0);
|
||||||
PostMessage(dh, WM_END_THREAD, 0, 0);
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
||||||
@ -849,8 +849,8 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
|
|
||||||
ProgessFunc(maxFile, 0);
|
ProgessFunc(maxFile, 0);
|
||||||
|
|
||||||
boost::optional<double> ScaleRatio;
|
std::optional<double> ScaleRatio;
|
||||||
boost::optional<int> ScaleWidth, ScaleHeight;
|
std::optional<int> ScaleWidth, ScaleHeight;
|
||||||
switch (scaleType)
|
switch (scaleType)
|
||||||
{
|
{
|
||||||
case eScaleTypeRatio:
|
case eScaleTypeRatio:
|
||||||
@ -875,7 +875,7 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
const auto fileNum = file_paths.size();
|
const auto fileNum = file_paths.size();
|
||||||
for (const auto &p : file_paths)
|
for (const auto &p : file_paths)
|
||||||
{
|
{
|
||||||
if (isOutputNoOverwrite && boost::filesystem::exists(p.second)) // 上書き禁止ならメッセージ表示して無視
|
if (isOutputNoOverwrite && std::filesystem::exists(p.second)) // 上書き禁止ならメッセージ表示して無視
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_ON_WAIFU2X_NO_OVERWRITE, (WPARAM)p.first.c_str(), (LPARAM)p.second.c_str());
|
SendMessage(dh, WM_ON_WAIFU2X_NO_OVERWRITE, (WPARAM)p.first.c_str(), (LPARAM)p.second.c_str());
|
||||||
|
|
||||||
@ -943,10 +943,10 @@ void DialogEvent::ReplaceAddString() //
|
|||||||
{
|
{
|
||||||
SyncMember(true, true);
|
SyncMember(true, true);
|
||||||
|
|
||||||
const boost::filesystem::path output_path(output_str);
|
const std::filesystem::path output_path(output_str);
|
||||||
tstring stem;
|
tstring stem;
|
||||||
|
|
||||||
if (input_str_multi.size() == 0 && !boost::filesystem::is_directory(input_str))
|
if (input_str_multi.size() == 0 && !std::filesystem::is_directory(input_str))
|
||||||
stem = getTString(output_path.stem());
|
stem = getTString(output_path.stem());
|
||||||
else
|
else
|
||||||
stem = getTString(output_path.filename());
|
stem = getTString(output_path.filename());
|
||||||
@ -963,8 +963,8 @@ void DialogEvent::ReplaceAddString() //
|
|||||||
|
|
||||||
autoSetAddName = addstr;
|
autoSetAddName = addstr;
|
||||||
|
|
||||||
boost::filesystem::path new_out_path;
|
std::filesystem::path new_out_path;
|
||||||
if (input_str_multi.size() == 0 && !boost::filesystem::is_directory(input_str))
|
if (input_str_multi.size() == 0 && !std::filesystem::is_directory(input_str))
|
||||||
new_out_path = output_path.branch_path() / (new_name + outputExt);
|
new_out_path = output_path.branch_path() / (new_name + outputExt);
|
||||||
else
|
else
|
||||||
new_out_path = output_path.branch_path() / (new_name);
|
new_out_path = output_path.branch_path() / (new_name);
|
||||||
@ -1040,7 +1040,7 @@ void DialogEvent::SaveIni(const bool isSyncMember)
|
|||||||
if (isNotSaveParam)
|
if (isNotSaveParam)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const boost::filesystem::path SettingFilePath(exeDir / SettingFileName);
|
const std::filesystem::path SettingFilePath(exeDir / SettingFileName);
|
||||||
|
|
||||||
tstring tScaleRatio;
|
tstring tScaleRatio;
|
||||||
tstring tScaleWidth;
|
tstring tScaleWidth;
|
||||||
@ -1338,8 +1338,8 @@ UINT_PTR DialogEvent::OFNHookProcOut(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARA
|
|||||||
{
|
{
|
||||||
szPath[_countof(szPath) - 1] = TEXT('\0');
|
szPath[_countof(szPath) - 1] = TEXT('\0');
|
||||||
|
|
||||||
boost::filesystem::path p(szPath);
|
std::filesystem::path p(szPath);
|
||||||
if (boost::filesystem::exists(p) && (boost::filesystem::is_empty(p) || boost::filesystem::is_directory(p)))
|
if (std::filesystem::exists(p) && (std::filesystem::is_empty(p) || std::filesystem::is_directory(p)))
|
||||||
{
|
{
|
||||||
const auto filename = getTString(p.filename());
|
const auto filename = getTString(p.filename());
|
||||||
|
|
||||||
@ -1505,7 +1505,7 @@ void DialogEvent::OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lp
|
|||||||
|
|
||||||
void DialogEvent::OnFaildCreateDir(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
void DialogEvent::OnFaildCreateDir(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
||||||
{
|
{
|
||||||
const boost::filesystem::path *p = (const boost::filesystem::path *)wParam;
|
const std::filesystem::path *p = (const std::filesystem::path *)wParam;
|
||||||
|
|
||||||
TCHAR msg[1024 * 2];
|
TCHAR msg[1024 * 2];
|
||||||
_stprintf(msg, langStringList.GetString(L"MessageCreateOutDirError").c_str(), getTString(*p).c_str());
|
_stprintf(msg, langStringList.GetString(L"MessageCreateOutDirError").c_str(), getTString(*p).c_str());
|
||||||
@ -1730,15 +1730,15 @@ void DialogEvent::Create(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|||||||
GetModuleFileName(NULL, texepath, _countof(texepath));
|
GetModuleFileName(NULL, texepath, _countof(texepath));
|
||||||
texepath[_countof(texepath) - 1] = TEXT('\0');
|
texepath[_countof(texepath) - 1] = TEXT('\0');
|
||||||
|
|
||||||
const boost::filesystem::path exePath(texepath);
|
const std::filesystem::path exePath(texepath);
|
||||||
exeDir = exePath.branch_path();
|
exeDir = exePath.branch_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::filesystem::path SettingFilePath(exeDir / SettingFileName);
|
const std::filesystem::path SettingFilePath(exeDir / SettingFileName);
|
||||||
|
|
||||||
{
|
{
|
||||||
const boost::filesystem::path LangDirPath(exeDir / LangDir);
|
const std::filesystem::path LangDirPath(exeDir / LangDir);
|
||||||
const boost::filesystem::path LangListPath(exeDir / LangListFileName);
|
const std::filesystem::path LangListPath(exeDir / LangListFileName);
|
||||||
langStringList.SetLangBaseDir(getTString(LangDirPath));
|
langStringList.SetLangBaseDir(getTString(LangDirPath));
|
||||||
langStringList.ReadLangList(getTString(LangListPath));
|
langStringList.ReadLangList(getTString(LangListPath));
|
||||||
}
|
}
|
||||||
@ -1811,7 +1811,7 @@ void DialogEvent::Create(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|||||||
SendMessage(houtext, CB_SETCURSEL, 0, 0);
|
SendMessage(houtext, CB_SETCURSEL, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::filesystem::path CropSizeListPath(exeDir / CropSizeListName);
|
const std::filesystem::path CropSizeListPath(exeDir / CropSizeListName);
|
||||||
std::ifstream ifs(CropSizeListPath.wstring());
|
std::ifstream ifs(CropSizeListPath.wstring());
|
||||||
if (ifs)
|
if (ifs)
|
||||||
{
|
{
|
||||||
@ -2132,7 +2132,7 @@ void DialogEvent::Create(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|||||||
|
|
||||||
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_INPUT_EXT_LIST), inputFileExt.c_str());
|
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_INPUT_EXT_LIST), inputFileExt.c_str());
|
||||||
|
|
||||||
if (tOutputDirFix.length() > 0 && boost::filesystem::exists(tOutputDirFix))
|
if (tOutputDirFix.length() > 0 && std::filesystem::exists(tOutputDirFix))
|
||||||
{
|
{
|
||||||
output_dir = tOutputDirFix;
|
output_dir = tOutputDirFix;
|
||||||
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_OUTPUT), output_dir.c_str());
|
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_OUTPUT), output_dir.c_str());
|
||||||
@ -2758,9 +2758,9 @@ LRESULT DialogEvent::OnSetInputFilePath(const TCHAR * tPath)
|
|||||||
{
|
{
|
||||||
HWND hWnd = GetDlgItem(dh, IDC_EDIT_INPUT);
|
HWND hWnd = GetDlgItem(dh, IDC_EDIT_INPUT);
|
||||||
|
|
||||||
boost::filesystem::path path(tPath);
|
std::filesystem::path path(tPath);
|
||||||
|
|
||||||
if (!boost::filesystem::exists(path))
|
if (!std::filesystem::exists(path))
|
||||||
{
|
{
|
||||||
MessageBox(dh, langStringList.GetString(L"MessageInputCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
MessageBox(dh, langStringList.GetString(L"MessageInputCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
||||||
return 0L;
|
return 0L;
|
||||||
@ -2770,9 +2770,9 @@ LRESULT DialogEvent::OnSetInputFilePath(const TCHAR * tPath)
|
|||||||
|
|
||||||
SyncMember(true, true);
|
SyncMember(true, true);
|
||||||
|
|
||||||
boost::filesystem::path outpath(output_dir);
|
std::filesystem::path outpath(output_dir);
|
||||||
|
|
||||||
if (boost::filesystem::is_directory(path))
|
if (std::filesystem::is_directory(path))
|
||||||
{
|
{
|
||||||
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
|
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
|
||||||
|
|
||||||
@ -2832,7 +2832,7 @@ LRESULT DialogEvent::OnSetInputFilePath()
|
|||||||
const tstring addstr(AddName());
|
const tstring addstr(AddName());
|
||||||
autoSetAddName = AddName();
|
autoSetAddName = AddName();
|
||||||
|
|
||||||
boost::filesystem::path outpath(output_dir);
|
std::filesystem::path outpath(output_dir);
|
||||||
|
|
||||||
if (output_dir.length() == 0) // 出力パス未設定なら入力ファイルと同じフォルダ
|
if (output_dir.length() == 0) // 出力パス未設定なら入力ファイルと同じフォルダ
|
||||||
{
|
{
|
||||||
@ -2840,10 +2840,10 @@ LRESULT DialogEvent::OnSetInputFilePath()
|
|||||||
outpath = outpath.branch_path();
|
outpath = outpath.branch_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path baseDir(input_str_multi[0]);
|
std::filesystem::path baseDir(input_str_multi[0]);
|
||||||
|
|
||||||
tstring filename;
|
tstring filename;
|
||||||
if (boost::filesystem::is_directory(baseDir))
|
if (std::filesystem::is_directory(baseDir))
|
||||||
filename = baseDir.filename().wstring();
|
filename = baseDir.filename().wstring();
|
||||||
else
|
else
|
||||||
filename = baseDir.stem().wstring();
|
filename = baseDir.stem().wstring();
|
||||||
@ -2865,15 +2865,15 @@ LRESULT DialogEvent::OnSetOutputFilePath(const TCHAR * tPath)
|
|||||||
|
|
||||||
if (input_str.length() > 0 || input_str_multi.size() > 0)
|
if (input_str.length() > 0 || input_str_multi.size() > 0)
|
||||||
{
|
{
|
||||||
boost::filesystem::path path(input_str);
|
std::filesystem::path path(input_str);
|
||||||
boost::filesystem::path outpath(tPath);
|
std::filesystem::path outpath(tPath);
|
||||||
|
|
||||||
if (input_str_multi.size() > 0)
|
if (input_str_multi.size() > 0)
|
||||||
{
|
{
|
||||||
path = input_str_multi[0];
|
path = input_str_multi[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boost::filesystem::is_directory(path))
|
if (std::filesystem::is_directory(path))
|
||||||
{
|
{
|
||||||
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
|
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
|
||||||
|
|
||||||
@ -2952,7 +2952,7 @@ LRESULT DialogEvent::DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tAutoMode == TEXT("one") ||
|
if (tAutoMode == TEXT("one") ||
|
||||||
(tAutoMode == TEXT("multi") && (input_str_multi.size() > 0 || boost::filesystem::is_directory(szTmp))))
|
(tAutoMode == TEXT("multi") && (input_str_multi.size() > 0 || std::filesystem::is_directory(szTmp))))
|
||||||
{
|
{
|
||||||
::PostMessage(GetDlgItem(dh, IDC_BUTTON_EXEC), BM_CLICK, 0, 0);
|
::PostMessage(GetDlgItem(dh, IDC_BUTTON_EXEC), BM_CLICK, 0, 0);
|
||||||
}
|
}
|
||||||
@ -3037,7 +3037,7 @@ void DialogEvent::InputRef(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpDat
|
|||||||
*tfp = TEXT('\0');
|
*tfp = TEXT('\0');
|
||||||
tfp++;
|
tfp++;
|
||||||
|
|
||||||
if (tInputDirFix.length() > 0 && boost::filesystem::exists(tInputDirFix))
|
if (tInputDirFix.length() > 0 && std::filesystem::exists(tInputDirFix))
|
||||||
ofn.lpstrInitialDir = tInputDirFix.c_str();
|
ofn.lpstrInitialDir = tInputDirFix.c_str();
|
||||||
else
|
else
|
||||||
ofn.lpstrInitialDir = szPath;
|
ofn.lpstrInitialDir = szPath;
|
||||||
@ -3104,7 +3104,7 @@ void DialogEvent::InputRef(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpDat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tAutoMode == TEXT("one") ||
|
if (tAutoMode == TEXT("one") ||
|
||||||
(tAutoMode == TEXT("multi") && (input_str_multi.size() > 0 || boost::filesystem::is_directory(szFile.data()))))
|
(tAutoMode == TEXT("multi") && (input_str_multi.size() > 0 || std::filesystem::is_directory(szFile.data()))))
|
||||||
{
|
{
|
||||||
::PostMessage(GetDlgItem(dh, IDC_BUTTON_EXEC), BM_CLICK, 0, 0);
|
::PostMessage(GetDlgItem(dh, IDC_BUTTON_EXEC), BM_CLICK, 0, 0);
|
||||||
}
|
}
|
||||||
@ -3139,7 +3139,7 @@ void DialogEvent::OutputRef(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpDa
|
|||||||
memcpy(tfp, allFilesExt.c_str(), allFilesExt.length() * sizeof(TCHAR));
|
memcpy(tfp, allFilesExt.c_str(), allFilesExt.length() * sizeof(TCHAR));
|
||||||
tfp += allFilesExt.length();
|
tfp += allFilesExt.length();
|
||||||
|
|
||||||
if (tOutputDirFix.length() > 0 && boost::filesystem::exists(tOutputDirFix))
|
if (tOutputDirFix.length() > 0 && std::filesystem::exists(tOutputDirFix))
|
||||||
ofn.lpstrInitialDir = tOutputDirFix.c_str();
|
ofn.lpstrInitialDir = tOutputDirFix.c_str();
|
||||||
else
|
else
|
||||||
ofn.lpstrInitialDir = szPath;
|
ofn.lpstrInitialDir = szPath;
|
||||||
@ -3417,7 +3417,7 @@ void DialogEvent::AppSetting(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpD
|
|||||||
tOutputDirFix = cAppSettingDialogEvent.tOutputDirFix;
|
tOutputDirFix = cAppSettingDialogEvent.tOutputDirFix;
|
||||||
gpu_no = cAppSettingDialogEvent.gpu_no;
|
gpu_no = cAppSettingDialogEvent.gpu_no;
|
||||||
|
|
||||||
if (tOutputDirFix.length() > 0 && boost::filesystem::exists(tOutputDirFix))
|
if (tOutputDirFix.length() > 0 && std::filesystem::exists(tOutputDirFix))
|
||||||
{
|
{
|
||||||
output_dir = tOutputDirFix;
|
output_dir = tOutputDirFix;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <boost/filesystem.hpp>
|
#include <filesystem>
|
||||||
#include <boost/optional.hpp>
|
#include <optional>
|
||||||
#include "../common/waifu2x.h"
|
#include "../common/waifu2x.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "tstring.h"
|
#include "tstring.h"
|
||||||
@ -77,7 +77,7 @@ private:
|
|||||||
|
|
||||||
static LangStringList langStringList;
|
static LangStringList langStringList;
|
||||||
|
|
||||||
boost::filesystem::path exeDir;
|
std::filesystem::path exeDir;
|
||||||
std::vector<int> CropSizeList;
|
std::vector<int> CropSizeList;
|
||||||
|
|
||||||
tstring input_str;
|
tstring input_str;
|
||||||
@ -96,7 +96,7 @@ private:
|
|||||||
|
|
||||||
bool use_tta;
|
bool use_tta;
|
||||||
|
|
||||||
boost::optional<int> output_quality;
|
std::optional<int> output_quality;
|
||||||
int output_depth;
|
int output_depth;
|
||||||
|
|
||||||
int crop_size;
|
int crop_size;
|
||||||
@ -158,11 +158,11 @@ private:
|
|||||||
|
|
||||||
bool SyncMember(const bool NotSyncCropSize, const bool silent = false);
|
bool SyncMember(const bool NotSyncCropSize, const bool silent = false);
|
||||||
|
|
||||||
void SetCropSizeList(const boost::filesystem::path &input_path);
|
void SetCropSizeList(const std::filesystem::path& input_path);
|
||||||
|
|
||||||
static boost::filesystem::path GetFileName(const boost::filesystem::path &input_path)
|
static std::filesystem::path GetFileName(const std::filesystem::path& input_path)
|
||||||
{
|
{
|
||||||
if (boost::filesystem::is_directory(input_path))
|
if (std::filesystem::is_directory(input_path))
|
||||||
return input_path.stem();
|
return input_path.stem();
|
||||||
else
|
else
|
||||||
return input_path.filename();
|
return input_path.filename();
|
||||||
@ -172,7 +172,7 @@ private:
|
|||||||
|
|
||||||
void ReplaceAddString();
|
void ReplaceAddString();
|
||||||
|
|
||||||
void AddLogMessage(const TCHAR *msg);
|
void AddLogMessage(const TCHAR* msg);
|
||||||
|
|
||||||
void Waifu2xTime();
|
void Waifu2xTime();
|
||||||
|
|
||||||
@ -231,11 +231,11 @@ public:
|
|||||||
|
|
||||||
void OnModelChange(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData);
|
void OnModelChange(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData);
|
||||||
|
|
||||||
LRESULT OnSetInputFilePath(const TCHAR *tPath);
|
LRESULT OnSetInputFilePath(const TCHAR* tPath);
|
||||||
|
|
||||||
LRESULT OnSetInputFilePath();
|
LRESULT OnSetInputFilePath();
|
||||||
|
|
||||||
LRESULT OnSetOutputFilePath(const TCHAR *tPath);
|
LRESULT OnSetOutputFilePath(const TCHAR* tPath);
|
||||||
|
|
||||||
// ここで渡されるhWndはIDC_EDITのHWND(コントロールのイベントだから)
|
// ここで渡されるhWndはIDC_EDITのHWND(コントロールのイベントだから)
|
||||||
LRESULT DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData);
|
LRESULT DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData);
|
||||||
|
|||||||
@ -6,13 +6,13 @@
|
|||||||
|
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
typedef std::wstring tstring;
|
typedef std::wstring tstring;
|
||||||
inline tstring getTString(const boost::filesystem::path& p)
|
inline tstring getTString(const std::filesystem::path& p)
|
||||||
{
|
{
|
||||||
return p.wstring();
|
return p.wstring();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
typedef std::string tstring;
|
typedef std::string tstring;
|
||||||
inline tstring getTString(const boost::filesystem::path& p)
|
inline tstring getTString(const std::filesystem::path& p)
|
||||||
{
|
{
|
||||||
return p.string();
|
return p.string();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,19 +14,19 @@
|
|||||||
<ProjectGuid>{63FB3EFC-63B0-401C-BB54-F3A984DC233F}</ProjectGuid>
|
<ProjectGuid>{63FB3EFC-63B0-401C-BB54-F3A984DC233F}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>waifu2xcaffegui</RootNamespace>
|
<RootNamespace>waifu2xcaffegui</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -61,6 +61,7 @@
|
|||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@ -82,6 +83,7 @@
|
|||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/filesystem.hpp>
|
#include <filesystem>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/tokenizer.hpp>
|
|
||||||
#include <boost/tokenizer.hpp>
|
|
||||||
#include <glog/logging.h>
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include "../common/waifu2x.h"
|
#include "../common/waifu2x.h"
|
||||||
|
|
||||||
@ -17,6 +14,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
using namespace TCLAPW;
|
using namespace TCLAPW;
|
||||||
typedef std::wstring tstring;
|
typedef std::wstring tstring;
|
||||||
|
typedef std::wstringstream tstringstream;
|
||||||
typedef wchar_t TCHAR;
|
typedef wchar_t TCHAR;
|
||||||
#ifndef TEXT
|
#ifndef TEXT
|
||||||
#define TEXT(x) L##x
|
#define TEXT(x) L##x
|
||||||
@ -26,7 +24,7 @@ typedef wchar_t TCHAR;
|
|||||||
#define tprintf wprintf
|
#define tprintf wprintf
|
||||||
#define CHAR_STR_FORMAT L"%S"
|
#define CHAR_STR_FORMAT L"%S"
|
||||||
|
|
||||||
const tstring& path_to_tstring(const boost::filesystem::path &p)
|
tstring path_to_tstring(const std::filesystem::path& p)
|
||||||
{
|
{
|
||||||
return p.wstring();
|
return p.wstring();
|
||||||
}
|
}
|
||||||
@ -34,6 +32,7 @@ const tstring& path_to_tstring(const boost::filesystem::path &p)
|
|||||||
#include <tclap/CmdLine.h>
|
#include <tclap/CmdLine.h>
|
||||||
using namespace TCLAP;
|
using namespace TCLAP;
|
||||||
typedef std::string tstring;
|
typedef std::string tstring;
|
||||||
|
typedef std::stringstream tstringstream;
|
||||||
typedef char TCHAR;
|
typedef char TCHAR;
|
||||||
#ifndef TEXT
|
#ifndef TEXT
|
||||||
#define TEXT(x) x
|
#define TEXT(x) x
|
||||||
@ -43,7 +42,7 @@ typedef char TCHAR;
|
|||||||
#define tprintf printf
|
#define tprintf printf
|
||||||
#define CHAR_STR_FORMAT "%s"
|
#define CHAR_STR_FORMAT "%s"
|
||||||
|
|
||||||
const tstring& path_to_tstring(const boost::filesystem::path &p)
|
tstring path_to_tstring(const std::filesystem::path& p)
|
||||||
{
|
{
|
||||||
return p.string();
|
return p.string();
|
||||||
}
|
}
|
||||||
@ -51,22 +50,22 @@ const tstring& path_to_tstring(const boost::filesystem::path &p)
|
|||||||
|
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
|
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
|
||||||
boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to)
|
std::filesystem::path relativePath(const std::filesystem::path& path, const std::filesystem::path& relative_to)
|
||||||
{
|
{
|
||||||
// create absolute paths
|
// create absolute paths
|
||||||
boost::filesystem::path p = boost::filesystem::absolute(path);
|
std::filesystem::path p = std::filesystem::absolute(path);
|
||||||
boost::filesystem::path r = boost::filesystem::absolute(relative_to);
|
std::filesystem::path r = std::filesystem::absolute(relative_to);
|
||||||
|
|
||||||
// if root paths are different, return absolute path
|
// if root paths are different, return absolute path
|
||||||
if (p.root_path() != r.root_path())
|
if (p.root_path() != r.root_path())
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
// initialize relative path
|
// initialize relative path
|
||||||
boost::filesystem::path result;
|
std::filesystem::path result;
|
||||||
|
|
||||||
// find out where the two paths diverge
|
// find out where the two paths diverge
|
||||||
boost::filesystem::path::const_iterator itr_path = p.begin();
|
std::filesystem::path::const_iterator itr_path = p.begin();
|
||||||
boost::filesystem::path::const_iterator itr_relative_to = r.begin();
|
std::filesystem::path::const_iterator itr_relative_to = r.begin();
|
||||||
while (*itr_path == *itr_relative_to && itr_path != p.end() && itr_relative_to != r.end()) {
|
while (*itr_path == *itr_relative_to && itr_path != p.end() && itr_relative_to != r.end()) {
|
||||||
++itr_path;
|
++itr_path;
|
||||||
++itr_relative_to;
|
++itr_relative_to;
|
||||||
@ -99,14 +98,6 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
Waifu2x::init_liblary(argc, argv);
|
Waifu2x::init_liblary(argc, argv);
|
||||||
|
|
||||||
// Caffeのエラーでないログを保存しないようにする
|
|
||||||
google::SetLogDestination(google::GLOG_INFO, "");
|
|
||||||
google::SetLogDestination(google::GLOG_WARNING, "");
|
|
||||||
|
|
||||||
// Caffeのエラーログを「error_log_~」に出力
|
|
||||||
google::SetLogDestination(google::GLOG_ERROR, "error_log_");
|
|
||||||
google::SetLogDestination(google::GLOG_FATAL, "error_log_");
|
|
||||||
|
|
||||||
// definition of command line arguments
|
// definition of command line arguments
|
||||||
CmdLine cmd(TEXT("waifu2x reimplementation using Caffe"), ' ', TEXT("1.0.0"));
|
CmdLine cmd(TEXT("waifu2x reimplementation using Caffe"), ' ', TEXT("1.0.0"));
|
||||||
|
|
||||||
@ -209,22 +200,22 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
#ifdef WIN_UNICODE
|
#ifdef WIN_UNICODE
|
||||||
int nArgs = 0;
|
int nArgs = 0;
|
||||||
LPTSTR *lplpszArgs = CommandLineToArgvW(GetCommandLine(), &nArgs);
|
LPTSTR* lplpszArgs = CommandLineToArgvW(GetCommandLine(), &nArgs);
|
||||||
cmd.parse(nArgs, lplpszArgs);
|
cmd.parse(nArgs, lplpszArgs);
|
||||||
LocalFree(lplpszArgs);
|
LocalFree(lplpszArgs);
|
||||||
#else
|
#else
|
||||||
cmd.parse(argc, argv);
|
cmd.parse(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
tprintf(TEXT("エラー: ") CHAR_STR_FORMAT TEXT("\n"), e.what());
|
tprintf(TEXT("エラー: ") CHAR_STR_FORMAT TEXT("\n"), e.what());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<double> ScaleRatio;
|
std::optional<double> ScaleRatio;
|
||||||
boost::optional<int> ScaleWidth;
|
std::optional<int> ScaleWidth;
|
||||||
boost::optional<int> ScaleHeight;
|
std::optional<int> ScaleHeight;
|
||||||
|
|
||||||
int crop_w = cmdCropSizeFile.getValue();
|
int crop_w = cmdCropSizeFile.getValue();
|
||||||
int crop_h = cmdCropSizeFile.getValue();
|
int crop_h = cmdCropSizeFile.getValue();
|
||||||
@ -236,14 +227,14 @@ int main(int argc, char** argv)
|
|||||||
crop_h = cmdCropHeight.getValue();
|
crop_h = cmdCropHeight.getValue();
|
||||||
|
|
||||||
if (cmdScaleWidth.getValue() > 0)
|
if (cmdScaleWidth.getValue() > 0)
|
||||||
ScaleWidth = cmdScaleWidth.getValue();
|
ScaleWidth = (int)cmdScaleWidth.getValue();
|
||||||
if (cmdScaleHeight.getValue() > 0)
|
if (cmdScaleHeight.getValue() > 0)
|
||||||
ScaleHeight = cmdScaleHeight.getValue();
|
ScaleHeight = (int)cmdScaleHeight.getValue();
|
||||||
|
|
||||||
if (cmdScaleWidth.getValue() == 0 && cmdScaleHeight.getValue() == 0)
|
if (cmdScaleWidth.getValue() == 0 && cmdScaleHeight.getValue() == 0)
|
||||||
ScaleRatio = cmdScaleRatio.getValue();
|
ScaleRatio = cmdScaleRatio.getValue();
|
||||||
|
|
||||||
const boost::filesystem::path input_path(boost::filesystem::absolute((cmdInputFile.getValue())));
|
const std::filesystem::path input_path(std::filesystem::absolute((cmdInputFile.getValue())));
|
||||||
|
|
||||||
tstring outputExt = cmdOutputFileExt.getValue();
|
tstring outputExt = cmdOutputFileExt.getValue();
|
||||||
if (outputExt.length() > 0 && outputExt[0] != TEXT('.'))
|
if (outputExt.length() > 0 && outputExt[0] != TEXT('.'))
|
||||||
@ -265,9 +256,9 @@ int main(int argc, char** argv)
|
|||||||
const bool use_tta = cmdTTALevel.getValue() == 1;
|
const bool use_tta = cmdTTALevel.getValue() == 1;
|
||||||
|
|
||||||
std::vector<std::pair<tstring, tstring>> file_paths;
|
std::vector<std::pair<tstring, tstring>> file_paths;
|
||||||
if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
|
if (std::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
|
||||||
{
|
{
|
||||||
boost::filesystem::path output_path;
|
std::filesystem::path output_path;
|
||||||
|
|
||||||
if (cmdOutputFile.getValue() == TEXT("(auto)"))
|
if (cmdOutputFile.getValue() == TEXT("(auto)"))
|
||||||
{
|
{
|
||||||
@ -277,7 +268,7 @@ int main(int argc, char** argv)
|
|||||||
addstr += tModelName;
|
addstr += tModelName;
|
||||||
addstr += TEXT(")");
|
addstr += TEXT(")");
|
||||||
|
|
||||||
const tstring &mode = cmdMode.getValue();
|
const tstring& mode = cmdMode.getValue();
|
||||||
|
|
||||||
addstr += TEXT("(") + mode + TEXT(")");
|
addstr += TEXT("(") + mode + TEXT(")");
|
||||||
|
|
||||||
@ -288,7 +279,7 @@ int main(int argc, char** argv)
|
|||||||
addstr += TEXT("(tta)");
|
addstr += TEXT("(tta)");
|
||||||
if (mode.find(TEXT("scale")) != mode.npos)
|
if (mode.find(TEXT("scale")) != mode.npos)
|
||||||
{
|
{
|
||||||
if(ScaleRatio)
|
if (ScaleRatio)
|
||||||
addstr += TEXT("(x") + to_tstring(*ScaleRatio) + TEXT(")");
|
addstr += TEXT("(x") + to_tstring(*ScaleRatio) + TEXT(")");
|
||||||
else if (ScaleWidth && ScaleHeight)
|
else if (ScaleWidth && ScaleHeight)
|
||||||
addstr += TEXT("(") + to_tstring(*ScaleWidth) + TEXT("x") + to_tstring(*ScaleHeight) + TEXT(")");
|
addstr += TEXT("(") + to_tstring(*ScaleWidth) + TEXT("x") + to_tstring(*ScaleHeight) + TEXT(")");
|
||||||
@ -301,16 +292,16 @@ int main(int argc, char** argv)
|
|||||||
if (cmdOutputDepth.getValue() != 8)
|
if (cmdOutputDepth.getValue() != 8)
|
||||||
addstr += TEXT("(") + to_tstring(cmdOutputDepth.getValue()) + TEXT("bit)");
|
addstr += TEXT("(") + to_tstring(cmdOutputDepth.getValue()) + TEXT("bit)");
|
||||||
|
|
||||||
output_path = input_path.branch_path() / (path_to_tstring(input_path.stem()) + addstr);
|
output_path = input_path.parent_path() / (path_to_tstring(input_path.stem()) + addstr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
output_path = cmdOutputFile.getValue();
|
output_path = cmdOutputFile.getValue();
|
||||||
|
|
||||||
output_path = boost::filesystem::absolute(output_path);
|
output_path = std::filesystem::absolute(output_path);
|
||||||
|
|
||||||
if (!boost::filesystem::exists(output_path))
|
if (!std::filesystem::exists(output_path))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::create_directory(output_path))
|
if (!std::filesystem::create_directory(output_path))
|
||||||
{
|
{
|
||||||
tprintf(TEXT("エラー: 出力フォルダ「%s」の作成に失敗しました\n"), path_to_tstring(output_path).c_str());
|
tprintf(TEXT("エラー: 出力フォルダ「%s」の作成に失敗しました\n"), path_to_tstring(output_path).c_str());
|
||||||
return 1;
|
return 1;
|
||||||
@ -321,58 +312,69 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
// input_extention_listを文字列の配列にする
|
// input_extention_listを文字列の配列にする
|
||||||
|
|
||||||
typedef boost::char_separator<TCHAR> char_separator;
|
tstringstream check1(cmdInputFileExt.getValue());
|
||||||
typedef boost::tokenizer<char_separator, tstring::const_iterator, tstring> tokenizer;
|
tstring ext;
|
||||||
|
while (std::getline(check1, ext, TEXT(':')))
|
||||||
char_separator sep(TEXT(":"), TEXT(""), boost::drop_empty_tokens);
|
|
||||||
tokenizer tokens(cmdInputFileExt.getValue(), sep);
|
|
||||||
|
|
||||||
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
|
|
||||||
{
|
{
|
||||||
tstring ext(*tok_iter);
|
|
||||||
std::transform(ext.begin(), ext.end(), ext.begin(), totlower);
|
std::transform(ext.begin(), ext.end(), ext.begin(), totlower);
|
||||||
extList.push_back(TEXT(".") + ext);
|
extList.push_back(TEXT(".") + ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//typedef boost::char_separator<TCHAR> char_separator;
|
||||||
|
//typedef boost::tokenizer<char_separator, tstring::const_iterator, tstring> tokenizer;
|
||||||
|
|
||||||
|
//char_separator sep(TEXT(":"), TEXT(""), boost::drop_empty_tokens);
|
||||||
|
//tokenizer tokens(cmdInputFileExt.getValue(), sep);
|
||||||
|
|
||||||
|
//for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
|
||||||
|
//{
|
||||||
|
// tstring ext(*tok_iter);
|
||||||
|
// std::transform(ext.begin(), ext.end(), ext.begin(), totlower);
|
||||||
|
// extList.push_back(TEXT(".") + ext);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 変換する画像の入力、出力パスを取得
|
|
||||||
const auto func = [&extList, &input_path, &output_path, &outputExt, &file_paths](const boost::filesystem::path &path)
|
|
||||||
{
|
|
||||||
BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path),
|
|
||||||
boost::filesystem::recursive_directory_iterator()))
|
|
||||||
{
|
|
||||||
if (boost::filesystem::is_directory(p))
|
|
||||||
{
|
|
||||||
const auto out_relative = relativePath(p, input_path);
|
|
||||||
const auto out_absolute = output_path / out_relative;
|
|
||||||
|
|
||||||
if (!boost::filesystem::exists(out_absolute))
|
|
||||||
{
|
// 変換する画像の入力、出力パスを取得
|
||||||
if (!boost::filesystem::create_directory(out_absolute))
|
const auto func = [&extList, &input_path, &output_path, &outputExt, &file_paths](const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
tprintf(TEXT("エラー: 出力フォルダ「%s」の作成に失敗しました\n"), path_to_tstring(out_absolute).c_str());
|
for (const auto& i : std::filesystem::recursive_directory_iterator(path))
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
tstring ext(path_to_tstring(p.extension()));
|
const std::filesystem::path& p = i.path();
|
||||||
std::transform(ext.begin(), ext.end(), ext.begin(), totlower);
|
|
||||||
if (std::find(extList.begin(), extList.end(), ext) != extList.end())
|
if (std::filesystem::is_directory(p))
|
||||||
{
|
{
|
||||||
const auto out_relative = relativePath(p, input_path);
|
const auto out_relative = relativePath(p, input_path);
|
||||||
const auto out_absolute = output_path / out_relative;
|
const auto out_absolute = output_path / out_relative;
|
||||||
|
|
||||||
const auto out = path_to_tstring(out_absolute.branch_path() / out_absolute.stem()) + outputExt;
|
if (!std::filesystem::exists(out_absolute))
|
||||||
|
{
|
||||||
|
if (!std::filesystem::create_directory(out_absolute))
|
||||||
|
{
|
||||||
|
tprintf(TEXT("エラー: 出力フォルダ「%s」の作成に失敗しました\n"), path_to_tstring(out_absolute).c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tstring ext(path_to_tstring(p.extension()));
|
||||||
|
std::transform(ext.begin(), ext.end(), ext.begin(), totlower);
|
||||||
|
if (std::find(extList.begin(), extList.end(), ext) != extList.end())
|
||||||
|
{
|
||||||
|
const auto out_relative = relativePath(p, input_path);
|
||||||
|
const auto out_absolute = output_path / out_relative;
|
||||||
|
|
||||||
file_paths.emplace_back(path_to_tstring(p), out);
|
const auto out = path_to_tstring(out_absolute.parent_path() / out_absolute.stem()) + outputExt;
|
||||||
|
|
||||||
|
file_paths.emplace_back(path_to_tstring(p), out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!func(input_path))
|
if (!func(input_path))
|
||||||
return 1;
|
return 1;
|
||||||
@ -393,7 +395,7 @@ int main(int argc, char** argv)
|
|||||||
addstr += tModelName;
|
addstr += tModelName;
|
||||||
addstr += TEXT(")");
|
addstr += TEXT(")");
|
||||||
|
|
||||||
const tstring &mode = cmdMode.getValue();
|
const tstring& mode = cmdMode.getValue();
|
||||||
|
|
||||||
addstr += TEXT("(") + mode + TEXT(")");
|
addstr += TEXT("(") + mode + TEXT(")");
|
||||||
|
|
||||||
@ -461,11 +463,11 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isError = false;
|
bool isError = false;
|
||||||
for (const auto &p : file_paths)
|
for (const auto& p : file_paths)
|
||||||
{
|
{
|
||||||
const Waifu2x::eWaifu2xError ret = w.waifu2x(p.first, p.second, ScaleRatio, ScaleWidth, ScaleHeight, nullptr,
|
const Waifu2x::eWaifu2xError ret = w.waifu2x(p.first, p.second, ScaleRatio, ScaleWidth, ScaleHeight, nullptr,
|
||||||
crop_w, crop_h,
|
crop_w, crop_h,
|
||||||
cmdOutputQuality.getValue() == -1 ? boost::optional<int>() : cmdOutputQuality.getValue(), cmdOutputDepth.getValue(), use_tta, cmdBatchSizeFile.getValue());
|
cmdOutputQuality.getValue() == -1 ? std::optional<int>() : cmdOutputQuality.getValue(), cmdOutputDepth.getValue(), use_tta, cmdBatchSizeFile.getValue());
|
||||||
if (ret != Waifu2x::eWaifu2xError_OK)
|
if (ret != Waifu2x::eWaifu2xError_OK)
|
||||||
{
|
{
|
||||||
switch (ret)
|
switch (ret)
|
||||||
|
|||||||
@ -14,19 +14,19 @@
|
|||||||
<ProjectGuid>{7C406EE4-2309-4D4C-98BB-CB7BA865FC41}</ProjectGuid>
|
<ProjectGuid>{7C406EE4-2309-4D4C-98BB-CB7BA865FC41}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>waifu2x-caffe</RootNamespace>
|
<RootNamespace>waifu2x-caffe</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -42,15 +42,15 @@
|
|||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<LinkIncremental>true</LinkIncremental>
|
<LinkIncremental>true</LinkIncremental>
|
||||||
<IncludePath>$(CUDA_PATH_V11_0)\include;$(SolutionDir)lib\include;$(USERPROFILE)\.caffe\dependencies\libraries_v140_x64_py27_1.1.0\libraries\include;$(USERPROFILE)\.caffe\dependencies\libraries_v140_x64_py27_1.1.0\libraries\include\boost-1_61;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(SolutionDir)msgpack-c\include;$(IncludePath)</IncludePath>
|
<IncludePath>$(CUDA_PATH_V13_0)\include;$(SolutionDir)lib\include;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(SolutionDir)msgpack-c\include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>$(CUDA_PATH_V11_0)\lib\$(PlatformName);$(SolutionDir)lib\$(PlatformName)\vc15\staticlib;$(SolutionDir)lib\lib;$(USERPROFILE)\.caffe\dependencies\libraries_v140_x64_py27_1.1.0\libraries\lib;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(CUDA_PATH_V13_0)\lib\$(PlatformName);$(SolutionDir)lib\$(PlatformName)\vc17\staticlib;$(SolutionDir)lib\lib;$(LibraryPath)</LibraryPath>
|
||||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||||
<TargetName>$(ProjectName)d</TargetName>
|
<TargetName>$(ProjectName)d</TargetName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
<IncludePath>$(CUDA_PATH_V11_0)\include;$(SolutionDir)lib\include;$(USERPROFILE)\.caffe\dependencies\libraries_v140_x64_py27_1.1.0\libraries\include;$(USERPROFILE)\.caffe\dependencies\libraries_v140_x64_py27_1.1.0\libraries\include\boost-1_61;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(SolutionDir)msgpack-c\include;$(IncludePath)</IncludePath>
|
<IncludePath>$(CUDA_PATH_V13_0)\include;$(SolutionDir)lib\include;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(SolutionDir)msgpack-c\include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>$(CUDA_PATH_V11_0)\lib\$(PlatformName);$(SolutionDir)lib\$(PlatformName)\vc15\staticlib;$(SolutionDir)lib\lib;$(USERPROFILE)\.caffe\dependencies\libraries_v140_x64_py27_1.1.0\libraries\lib;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(CUDA_PATH_V13_0)\lib\$(PlatformName);$(SolutionDir)lib\$(PlatformName)\vc17\staticlib;$(SolutionDir)lib\lib;$(LibraryPath)</LibraryPath>
|
||||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@ -59,8 +59,9 @@
|
|||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -77,8 +78,9 @@
|
|||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user