From e6270364ed88ceb0a794af84e2192b2ab50fc2d3 Mon Sep 17 00:00:00 2001 From: lltcggie <7032792+lltcggie@users.noreply.github.com> Date: Sun, 7 Sep 2025 21:28:26 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + .gitmodules | 4 - caffe | 1 - caffe_build.bat | 7 +- common/cNet.cpp | 30 ++-- common/cNet.h | 18 +-- common/stImage.cpp | 157 ++++++++------------ common/stImage.h | 16 +- common/waifu2x.cpp | 82 +++++----- common/waifu2x.h | 44 +++--- opencv | 2 +- opencv_build.bat | 95 +++++++++++- waifu2x-caffe-dll/Source.cpp | 4 +- waifu2x-caffe-dll/waifu2x-caffe-dll.vcxproj | 8 +- waifu2x-caffe-gui/MainDialog.cpp | 144 +++++++++--------- waifu2x-caffe-gui/MainDialog.h | 20 +-- waifu2x-caffe-gui/tstring.h | 4 +- waifu2x-caffe-gui/waifu2x-caffe-gui.vcxproj | 8 +- waifu2x-caffe/Source.cpp | 154 +++++++++---------- waifu2x-caffe/waifu2x-caffe.vcxproj | 20 +-- 20 files changed, 438 insertions(+), 383 deletions(-) delete mode 160000 caffe diff --git a/.gitignore b/.gitignore index 902f4de..cccb6ca 100644 --- a/.gitignore +++ b/.gitignore @@ -243,5 +243,8 @@ ModelManifest.xml # FAKE - F# Make .fake/ + *.caffemodel *.protobin +/lib/ +/opencv_contrib-*/ diff --git a/.gitmodules b/.gitmodules index 3828a4f..8aeafec 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,10 +7,6 @@ [submodule "msgpack-c"] path = 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"] path = opencv url = https://github.com/opencv/opencv.git diff --git a/caffe b/caffe deleted file mode 160000 index 9d5aa36..0000000 --- a/caffe +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9d5aa36c65a0082768f10c1d474c56d8a7cc9934 diff --git a/caffe_build.bat b/caffe_build.bat index d0d207a..bea6d88 100644 --- a/caffe_build.bat +++ b/caffe_build.bat @@ -4,7 +4,7 @@ cd /d "%~dp0" cd caffe -set MSVC_VERSION=14 +set MSVC_VERSION=17 set USE_CUDNN=1 set USE_NCCL=0 set USE_OPENCV=0 @@ -21,7 +21,8 @@ set BUILD_PYTHON_LAYER=0 set RUN_TESTS=0 set CMAKE_INSTALL_PREFIX=../../lib set RUN_INSTALL=1 -set CUDA_ARCH_BIN=35 50 52 53 60 61 62 70 75 80 -set CUDA_ARCH_PTX=80 +rem set CUDA_ARCH_BIN=75 80 86 89 90 100 120 +set CUDA_ARCH_BIN=89 +set CUDA_ARCH_PTX=120 scripts\build_win.cmd \ No newline at end of file diff --git a/common/cNet.cpp b/common/cNet.cpp index 71686de..3cfedef 100644 --- a/common/cNet.cpp +++ b/common/cNet.cpp @@ -29,7 +29,7 @@ static bool readFile(boost::iostreams::stream -static bool readFile(const boost::filesystem::path &path, std::vector &buf) +static bool readFile(const std::filesystem::path &path, std::vector &buf) { boost::iostreams::stream is; @@ -45,7 +45,7 @@ static bool readFile(const boost::filesystem::path &path, std::vector & 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 is; @@ -74,7 +74,7 @@ static Waifu2x::eWaifu2xError readProtoText(const boost::filesystem::path &path, 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 os; @@ -96,7 +96,7 @@ static Waifu2x::eWaifu2xError writeProtoBinary(const ::google::protobuf::Message 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 is; @@ -130,7 +130,7 @@ static Waifu2x::eWaifu2xError readProtoBinary(const boost::filesystem::path &pat namespace { - Waifu2x::eWaifu2xError ReadJson(const boost::filesystem::path &info_path, rapidjson::Document &d, std::vector &jsonBuf) + Waifu2x::eWaifu2xError ReadJson(const std::filesystem::path &info_path, rapidjson::Document &d, std::vector &jsonBuf) { try { @@ -174,7 +174,7 @@ cNet::cNet() : mModelScale(0), mInnerScale(0), mNetOffset(0), mInputPlane(0), mH 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; std::vector jsonBuf; @@ -291,7 +291,7 @@ Waifu2x::eWaifu2xError cNet::GetInfo(const boost::filesystem::path & info_path, // モデルファイルからネットワークを構築 // 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; @@ -299,9 +299,9 @@ Waifu2x::eWaifu2xError cNet::ConstractNet(const Waifu2x::eWaifu2xModelType mode, LoadParamFromInfo(mode, info); - boost::filesystem::path modelbin_path = model_path; + std::filesystem::path modelbin_path = model_path; modelbin_path += ".protobin"; - boost::filesystem::path caffemodel_path = param_path; + std::filesystem::path caffemodel_path = param_path; caffemodel_path += ".caffemodel"; caffe::NetParameter param_model; @@ -331,7 +331,7 @@ Waifu2x::eWaifu2xError cNet::ConstractNet(const Waifu2x::eWaifu2xModelType mode, if (!caffe::UpgradeNetAsNeeded(caffemodel_path.string(), ¶m_caffemodel)) return Waifu2x::eWaifu2xError_FailedParseModelFile; - mNet = boost::shared_ptr>(new caffe::Net(param_model)); + mNet = std::shared_ptr>(new caffe::Net(param_model)); mNet->CopyTrainedLayersFrom(param_caffemodel); } else @@ -437,8 +437,8 @@ Waifu2x::eWaifu2xError cNet::SetParameter(caffe::NetParameter ¶m, const std: return Waifu2x::eWaifu2xError_OK; } -Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const boost::filesystem::path &model_path, const boost::filesystem::path ¶m_path - , const boost::filesystem::path &modelbin_path, const boost::filesystem::path &caffemodel_path, const std::string &process) +Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const std::filesystem::path &model_path, const std::filesystem::path ¶m_path + , const std::filesystem::path &modelbin_path, const std::filesystem::path &caffemodel_path, const std::string &process) { Waifu2x::eWaifu2xError ret; @@ -455,7 +455,7 @@ Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const boost::filesystem::path if (ret != Waifu2x::eWaifu2xError_OK) return ret; - mNet = boost::shared_ptr>(new caffe::Net(param)); + mNet = std::shared_ptr>(new caffe::Net(param)); rapidjson::Document d; std::vector jsonBuf; @@ -509,7 +509,7 @@ Waifu2x::eWaifu2xError cNet::LoadParameterFromJson(const boost::filesystem::path if (inputPlane != outputPlane) return Waifu2x::eWaifu2xError_FailedParseModelFile; - std::vector>> list; + std::vector>> list; auto &v = mNet->layers(); for (auto &l : v) { @@ -858,7 +858,7 @@ Waifu2x::eWaifu2xError cNet::ReconstructImage(const bool UseTTA, const int crop_ 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; diff --git a/common/cNet.h b/common/cNet.h index fe7cf2e..0c69cbe 100644 --- a/common/cNet.h +++ b/common/cNet.h @@ -9,7 +9,7 @@ class cNet private: Waifu2x::eWaifu2xModelType mMode; - boost::shared_ptr> mNet; + std::shared_ptr> mNet; int mModelScale; // モデルが対象とする拡大率 int mInnerScale; // ネット内部で拡大される倍率 @@ -18,18 +18,18 @@ private: bool mHasNoiseScaleModel; private: - 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 - , const boost::filesystem::path &modelbin_path, const boost::filesystem::path &caffemodel_path, const std::string &process); - Waifu2x::eWaifu2xError SetParameter(caffe::NetParameter ¶m, const std::string &process) const; + void LoadParamFromInfo(const Waifu2x::eWaifu2xModelType mode, const Waifu2x::stInfo& info); + Waifu2x::eWaifu2xError LoadParameterFromJson(const std::filesystem::path& model_path, const std::filesystem::path& param_path + , const std::filesystem::path& modelbin_path, const std::filesystem::path& caffemodel_path, const std::string& process); + Waifu2x::eWaifu2xError SetParameter(caffe::NetParameter& param, const std::string& process) const; public: 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 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 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); }; diff --git a/common/stImage.cpp b/common/stImage.cpp index 8f9b601..f9ebde8 100644 --- a/common/stImage.cpp +++ b/common/stImage.cpp @@ -1,7 +1,7 @@ #include "stImage.h" -#include -#include -#include +//#include +//#include +//#include #include #include #include @@ -11,10 +11,10 @@ #define STB_IMAGE_WRITE_IMPLEMENTATION #include -const int YToRGBConvertMode = CV_GRAY2RGB; -const int YToRGBConverInversetMode = CV_RGB2GRAY; -const int BGRToYConvertMode = CV_BGR2YUV; -const int BGRToConvertInverseMode = CV_YUV2BGR; +const int YToRGBConvertMode = cv::COLOR_GRAY2RGB; +const int YToRGBConverInversetMode = cv::COLOR_RGB2GRAY; +const int BGRToYConvertMode = cv::COLOR_BGR2YUV; +const int BGRToConvertInverseMode = cv::COLOR_YUV2BGR; // floatな画像をuint8_tな画像に変換する際の四捨五入に使う値 // 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::OutputExtentionList = { - {L".png",{8, 16}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, - {L".bmp",{8}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, + {L".png",{8, 16}, std::optional(), std::optional(), std::optional(), std::optional()}, + {L".bmp",{8}, std::optional(), std::optional(), std::optional(), std::optional()}, {L".jpg",{8}, 0, 100, 95, cv::IMWRITE_JPEG_QUALITY}, - {L".jp2",{8, 16}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, - {L".sr",{8}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, - {L".tif",{8, 16, 32}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, - {L".hdr",{8, 16, 32}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, - {L".exr",{8, 16, 32}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, - {L".ppm",{8, 16}, boost::optional(), boost::optional(), boost::optional(), boost::optional()}, + {L".jp2",{8, 16}, std::optional(), std::optional(), std::optional(), std::optional()}, + {L".sr",{8}, std::optional(), std::optional(), std::optional(), std::optional()}, + {L".tif",{8, 16, 32}, std::optional(), std::optional(), std::optional(), std::optional()}, + {L".hdr",{8, 16, 32}, std::optional(), std::optional(), std::optional(), std::optional()}, + {L".exr",{8, 16, 32}, std::optional(), std::optional(), std::optional(), std::optional()}, + {L".ppm",{8, 16}, std::optional(), std::optional(), std::optional(), std::optional()}, {L".webp",{8}, 1, 100, 100, cv::IMWRITE_WEBP_QUALITY}, {L".tga",{8}, 0, 1, 0, 0}, }; template -static bool readFile(boost::iostreams::stream &is, std::vector &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 -static bool readFile(const boost::filesystem::path &path, std::vector &buf) +static bool readFile(const std::filesystem::path& path, std::vector& buf) { boost::iostreams::stream is; @@ -73,21 +56,7 @@ static bool readFile(const boost::filesystem::path &path, std::vector & } template -static bool writeFile(boost::iostreams::stream &os, const std::vector &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 -static bool writeFile(const boost::filesystem::path &path, std::vector &buf) +static bool writeFile(const std::filesystem::path& path, std::vector& buf) { boost::iostreams::stream os; @@ -103,10 +72,10 @@ static bool writeFile(const boost::filesystem::path &path, std::vector 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 *osp = (boost::iostreams::stream *)context; - osp->write((const char *)data, size); + boost::iostreams::stream* osp = (boost::iostreams::stream *)context; + osp->write((const char*)data, size); } int stImage::DepthBitToCVDepth(const int depth_bit) @@ -164,7 +133,7 @@ double stImage::GetEPS(const int cv_depth) } -Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector &planes, const cv::Mat &alpha, const int offset) +Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector& planes, const cv::Mat& alpha, const int offset) { // このカーネルと画像の畳込みを行うと、(x, y)を中心とした3×3領域の合計値が求まる const static cv::Mat sum2d_kernel = (cv::Mat_(3, 3) << @@ -178,7 +147,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector &planes, co cv::Mat mask_nega; 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); } @@ -191,7 +160,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector &planes, co cv::Mat mask_nega_u8; 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領域内の有効画素の平均値を求める cv::Mat border; @@ -209,7 +178,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector &planes, co } // 画素を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, 0.0, 0.0, cv::THRESH_TOZERO); @@ -219,7 +188,7 @@ Waifu2x::eWaifu2xError stImage::AlphaMakeBorder(std::vector &planes, co } // 画像を読み込んで値を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; @@ -228,7 +197,7 @@ Waifu2x::eWaifu2xError stImage::LoadMat(cv::Mat &im, const boost::filesystem::pa if (!readFile(input_file, img_data)) 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を優先させる { 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; } -Waifu2x::eWaifu2xError stImage::LoadMatBySTBI(cv::Mat &im, const std::vector &img_data) +Waifu2x::eWaifu2xError stImage::LoadMatBySTBI(cv::Mat& im, const std::vector& img_data) { 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) return Waifu2x::eWaifu2xError_FailedOpenInputFile; @@ -315,7 +284,7 @@ Waifu2x::eWaifu2xError stImage::LoadMatBySTBI(cv::Mat &im, const std::vector= 3) // RGBなのでBGRにする { @@ -426,7 +395,7 @@ void stImage::Preprocess(const int input_plane, const int 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); @@ -437,7 +406,7 @@ bool stImage::IsOneColor(const cv::Mat & im) if (Width == 0 && Height == 0) return true; - const float *ptr = (const float *)im.data; + const float* ptr = (const float*)im.data; const float color = ptr[0]; 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) { @@ -548,29 +517,29 @@ bool stImage::HasAlpha() const return !mTmpImageA.empty(); } -void stImage::GetScalePaddingedRGB(cv::Mat &im, cv::Size_ &size, const int net_offset, const int outer_padding, +void stImage::GetScalePaddingedRGB(cv::Mat& im, cv::Size_& size, const int net_offset, const int outer_padding, const int crop_w, const int crop_h, const int scale) { GetScalePaddingedImage(mTmpImageRGB, im, size, net_offset, outer_padding, crop_w, crop_h, scale); } -void stImage::SetReconstructedRGB(cv::Mat &im, const cv::Size_ &size, const int inner_scale) +void stImage::SetReconstructedRGB(cv::Mat& im, const cv::Size_& size, const int inner_scale) { SetReconstructedImage(mTmpImageRGB, im, size, inner_scale); } -void stImage::GetScalePaddingedA(cv::Mat &im, cv::Size_ &size, const int net_offset, const int outer_padding, +void stImage::GetScalePaddingedA(cv::Mat& im, cv::Size_& size, const int net_offset, const int outer_padding, const int crop_w, const int crop_h, const int scale) { GetScalePaddingedImage(mTmpImageA, im, size, net_offset, outer_padding, crop_w, crop_h, scale); } -void stImage::SetReconstructedA(cv::Mat &im, const cv::Size_ &size, const int inner_scale) +void stImage::SetReconstructedA(cv::Mat& im, const cv::Size_& size, const int inner_scale) { SetReconstructedImage(mTmpImageA, im, size, inner_scale); } -void stImage::GetScalePaddingedImage(cv::Mat &in, cv::Mat &out, cv::Size_ &size, const int net_offset, const int outer_padding, +void stImage::GetScalePaddingedImage(cv::Mat& in, cv::Mat& out, cv::Size_& size, const int net_offset, const int outer_padding, const int crop_w, const int crop_h, const int scale) { cv::Mat ret; @@ -597,8 +566,8 @@ void stImage::GetScalePaddingedImage(cv::Mat &in, cv::Mat &out, cv::Size_ & // 入力画像の(Photoshopでいう)キャンバスサイズをoutput_sizeの倍数に変更 // 画像は左上配置、余白はcv::BORDER_REPLICATEで埋める -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) +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 auto pad_w1 = 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_ &size, const int inner_scale) +void stImage::SetReconstructedImage(cv::Mat& dst, cv::Mat& src, const cv::Size_& size, const int inner_scale) { const cv::Size_ s(size * inner_scale); @@ -718,7 +687,7 @@ void stImage::DeconvertFromNetFormat(const int input_plane) if (!mTmpImageA.empty()) // Aもあるので合体 { // RGBから1chに戻す - cv::cvtColor(mTmpImageA, mTmpImageA, CV_RGB2GRAY); + cv::cvtColor(mTmpImageA, mTmpImageA, cv::COLOR_RGB2GRAY); planes.push_back(mTmpImageA); 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 double max_val = GetValumeMaxFromCVDepth(cv_depth); @@ -793,15 +762,15 @@ cv::Mat stImage::DeconvertFromFloat(const cv::Mat &im, const int depth) namespace { template - void AlphaZeroToZero(std::vector &planes) + void AlphaZeroToZero(std::vector& planes) { 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 *ptr1 = (T *)planes[1].data; - T *ptr2 = (T *)planes[2].data; + T* ptr0 = (T*)planes[0].data; + T* ptr1 = (T*)planes[1].data; + T* ptr2 = (T*)planes[2].data; const size_t Line = alpha.step1(); 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へ変換してからこの処理を行うことにした @@ -858,7 +827,7 @@ void stImage::AlphaCleanImage(cv::Mat &im) // 入力画像をzoom_sizeの大きさにcv::INTER_CUBICで拡大し、色情報のみを残す -Waifu2x::eWaifu2xError stImage::CreateZoomColorImage(const cv::Mat &float_image, const cv::Size_ &zoom_size, std::vector &cubic_planes) +Waifu2x::eWaifu2xError stImage::CreateZoomColorImage(const cv::Mat& float_image, const cv::Size_& zoom_size, std::vector& cubic_planes) { cv::Mat zoom_cubic_image; 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; } -Waifu2x::eWaifu2xError stImage::Save(const boost::filesystem::path &output_file, const boost::optional &output_quality) +Waifu2x::eWaifu2xError stImage::Save(const std::filesystem::path& output_file, const std::optional& 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 &output_quality) +Waifu2x::eWaifu2xError stImage::WriteMat(const cv::Mat& im, const std::filesystem::path& output_file, const std::optional& output_quality) { - const boost::filesystem::path ip(output_file); + const std::filesystem::path ip(output_file); const std::string ext = ip.extension().string(); if (boost::iequals(ext, ".tga")) { - unsigned char *data = im.data; + unsigned char* data = im.data; std::vector rgbimg; 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圧縮の設定 bool isSet = false; - const auto &OutputExtentionList = stImage::OutputExtentionList; - for (const auto &elm : OutputExtentionList) + const auto& OutputExtentionList = stImage::OutputExtentionList; + for (const auto& elm : OutputExtentionList) { if (elm.ext == L".tga") { @@ -970,13 +939,13 @@ Waifu2x::eWaifu2xError stImage::WriteMat(const cv::Mat &im, const boost::filesys try { - const boost::filesystem::path op(output_file); - const boost::filesystem::path opext(op.extension()); + const std::filesystem::path op(output_file); + const std::filesystem::path opext(op.extension()); std::vector params; - const auto &OutputExtentionList = stImage::OutputExtentionList; - for (const auto &elm : OutputExtentionList) + const auto& OutputExtentionList = stImage::OutputExtentionList; + for (const auto& elm : OutputExtentionList) { if (elm.ext == opext) { diff --git a/common/stImage.h b/common/stImage.h index 0272224..de35a23 100644 --- a/common/stImage.h +++ b/common/stImage.h @@ -28,10 +28,10 @@ public: { std::wstring ext; std::vector depthList; - boost::optional imageQualityStart; - boost::optional imageQualityEnd; - boost::optional imageQualityDefault; - boost::optional imageQualitySettingVolume; + std::optional imageQualityStart; + std::optional imageQualityEnd; + std::optional imageQualityDefault; + std::optional imageQualitySettingVolume; }; const static std::vector OutputExtentionList; @@ -46,7 +46,7 @@ private: static cv::Mat DeconvertFromFloat(const cv::Mat &im, const int depth); static void AlphaCleanImage(cv::Mat &im); - static Waifu2x::eWaifu2xError WriteMat(const cv::Mat &im, const boost::filesystem::path &output_file, const boost::optional &output_quality); + static Waifu2x::eWaifu2xError WriteMat(const cv::Mat &im, const std::filesystem::path &output_file, const std::optional &output_quality); // im(1ch)が単色で構成されているか判定 static bool IsOneColor(const cv::Mat &im); @@ -81,9 +81,9 @@ public: 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な画素配列 // dest: (4チャンネルの場合は)処理したRGBAな画素配列 @@ -130,5 +130,5 @@ public: cv::Mat GetEndImage() const; - Waifu2x::eWaifu2xError Save(const boost::filesystem::path &output_file, const boost::optional &output_quality); + Waifu2x::eWaifu2xError Save(const std::filesystem::path &output_file, const std::optional &output_quality); }; diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index ac7faff..3f31c87 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -327,7 +327,7 @@ private: } catch (...) { - boost::filesystem::remove(SavePath); + std::filesystem::remove(SavePath); } return true; @@ -550,7 +550,7 @@ Waifu2x::~Waifu2x() } 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; @@ -581,38 +581,38 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi if (Process == "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()) - 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(); - if (!boost::filesystem::exists(cudnn_data_base_dir_path)) + if (!std::filesystem::exists(cudnn_data_base_dir_path)) { // 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()) - 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 = "./"; } - 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; - if (boost::filesystem::exists(cudnn_data_dir_path)) + if (std::filesystem::exists(cudnn_data_dir_path)) isOK = true; if (!isOK) { 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) isOK = true; } @@ -628,8 +628,8 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi std::string deconv_filename(prop.name); deconv_filename += " deconv "; - const boost::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 conv_data_path = cudnn_data_dir_path / conv_filename; + const std::filesystem::path deconv_data_path = cudnn_data_dir_path / deconv_filename; g_ConvCcuDNNAlgorithm.SetDataPath(conv_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)); - if (!boost::filesystem::exists(mode_dir_path)) + const std::filesystem::path mode_dir_path(GetModeDirPath(model_dir)); + if (!std::filesystem::exists(mode_dir_path)) return Waifu2x::eWaifu2xError_FailedOpenModelFile; CudaDeviceSet devset(process, mGPUNo); @@ -661,7 +661,7 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi mInputPlane = 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; 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"; } - const boost::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 model_path = mode_dir_path / (base_name + ".prototxt"); + const std::filesystem::path param_path = mode_dir_path / (base_name + ".json"); ret = mNoiseNet->ConstractNet(Mode, model_path, param_path, info, mProcess); 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 boost::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 model_path = mode_dir_path / (base_name + ".prototxt"); + const std::filesystem::path param_path = mode_dir_path / (base_name + ".json"); mScaleNet.reset(new cNet); @@ -736,16 +736,16 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi 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が相対パスなら絶対パスに直す { // まずはカレントディレクトリ下にあるか探す - mode_dir_path = boost::filesystem::absolute(model_dir); - if (!boost::filesystem::exists(mode_dir_path) && !ExeDir.empty()) // 無かったらargv[0]から実行ファイルのあるフォルダを推定し、そのフォルダ下にあるか探す + mode_dir_path = std::filesystem::absolute(model_dir); + 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()) 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; } -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; } -Waifu2x::eWaifu2xError Waifu2x::waifu2x(const boost::filesystem::path &input_file, const boost::filesystem::path &output_file, - const boost::optional scale_ratio, const boost::optional scale_width, const boost::optional scale_height, +Waifu2x::eWaifu2xError Waifu2x::waifu2x(const std::filesystem::path &input_file, const std::filesystem::path &output_file, + const std::optional scale_ratio, const std::optional scale_width, const std::optional scale_height, const waifu2xCancelFunc cancel_func, const int crop_w, const int crop_h, - const boost::optional output_quality, const int output_depth, const bool use_tta, + const std::optional output_quality, const int output_depth, const bool use_tta, const int batch_size) { Waifu2x::eWaifu2xError ret; @@ -867,7 +867,7 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const double factor, const void* source, return Waifu2x::eWaifu2xError_OK; } -Factor Waifu2x::CalcScaleRatio(const boost::optional scale_ratio, const boost::optional scale_width, const boost::optional scale_height, +Factor Waifu2x::CalcScaleRatio(const std::optional scale_ratio, const std::optional scale_width, const std::optional scale_height, const stImage &image) { if (scale_ratio) @@ -1155,24 +1155,24 @@ const std::string& Waifu2x::used_process() const 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)); - if (!boost::filesystem::exists(mode_dir_path)) + const std::filesystem::path mode_dir_path(GetModeDirPath(model_dir)); + if (!std::filesystem::exists(mode_dir_path)) 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); } -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)); - if (!boost::filesystem::exists(mode_dir_path)) + const std::filesystem::path mode_dir_path(GetModeDirPath(model_dir)); + if (!std::filesystem::exists(mode_dir_path)) 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; } diff --git a/common/waifu2x.h b/common/waifu2x.h index c70a554..29d4e08 100644 --- a/common/waifu2x.h +++ b/common/waifu2x.h @@ -5,9 +5,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #define CUDNN_DLL_NAME "cudnn64_8.dll" @@ -146,31 +146,31 @@ private: int mMaxNetOffset; // ネットに入力するとどれくらい削れるか bool mHasNoiseScaleOnly; - float *mOutputBlock; + float* mOutputBlock; size_t mOutputBlockSize; private: - static boost::filesystem::path GetModeDirPath(const boost::filesystem::path &model_dir); - static boost::filesystem::path GetInfoPath(const boost::filesystem::path &model_dir); + static std::filesystem::path GetModeDirPath(const std::filesystem::path& model_dir); + static std::filesystem::path GetInfoPath(const std::filesystem::path& model_dir); - static Factor CalcScaleRatio(const boost::optional scale_ratio, const boost::optional scale_width, const boost::optional scale_height, - const stImage &image); + static Factor CalcScaleRatio(const std::optional scale_ratio, const std::optional scale_width, const std::optional scale_height, + 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); - 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); 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, - 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, - const Waifu2x::waifu2xCancelFunc cancel_func, stImage &image); + const Waifu2x::waifu2xCancelFunc cancel_func, stImage& image); Waifu2x::eWaifu2xError ReconstructByNet(std::shared_ptr 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); - Waifu2x::eWaifu2xError ProcessNet(std::shared_ptr net, const int crop_w, const int crop_h, const bool use_tta, const int batch_size, cv::Mat &im); + const Waifu2x::waifu2xCancelFunc cancel_func, cv::Mat& im); + Waifu2x::eWaifu2xError ProcessNet(std::shared_ptr net, const int crop_w, const int crop_h, const bool use_tta, const int batch_size, cv::Mat& im); public: Waifu2x(); @@ -186,12 +186,12 @@ public: // mode: noise or scale or noise_scale or auto_scale // process: cpu or gpu or cudnn 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, - const boost::optional scale_ratio, const boost::optional scale_width, const boost::optional scale_height, + eWaifu2xError waifu2x(const std::filesystem::path& input_file, const std::filesystem::path& output_file, + const std::optional scale_ratio, const std::optional scale_width, const std::optional scale_height, const waifu2xCancelFunc cancel_func = nullptr, const int crop_w = 128, const int crop_h = 128, - const boost::optional output_quality = boost::optional(), const int output_depth = 8, const bool use_tta = false, + const std::optional output_quality = std::optional(), const int output_depth = 8, const bool use_tta = false, const int batch_size = 1); // factor: 倍率 @@ -201,12 +201,12 @@ public: // out_stride: destのストライド(バイト単位) 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 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(); const std::string& used_process() const; - static std::string GetModelName(const boost::filesystem::path &model_dir); - static bool GetInfo(const boost::filesystem::path &model_dir, stInfo &info); + static std::string GetModelName(const std::filesystem::path& model_dir); + static bool GetInfo(const std::filesystem::path& model_dir, stInfo& info); }; diff --git a/opencv b/opencv index b38c50b..6d889ee 160000 --- a/opencv +++ b/opencv @@ -1 +1 @@ -Subproject commit b38c50b3d0c31e82294315ec44b54b7ef559ef12 +Subproject commit 6d889ee74c94124f6492eb8f0d50946d9c31d8e9 diff --git a/opencv_build.bat b/opencv_build.bat index 73c6b4a..2a2df94 100644 --- a/opencv_build.bat +++ b/opencv_build.bat @@ -1,10 +1,21 @@ @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 mkdir build cd build -cmake .. -G "Visual Studio 15 Win64" ^ +set CFLAGS=/Zc:preprocessor +set CXXFLAGS=/Zc:preprocessor + +cmake .. -G Ninja ^ -DCMAKE_INSTALL_PREFIX=..\..\lib ^ -DBUILD_WITH_STATIC_CRT=OFF ^ -DBUILD_IPP_IW=OFF ^ @@ -12,8 +23,8 @@ cmake .. -G "Visual Studio 15 Win64" ^ -DBUILD_JAVA=OFF ^ -DBUILD_SHARED_LIBS=OFF ^ -DBUILD_TESTS=OFF ^ +-DBUILD_PERF_TESTS=OFF ^ -DBUILD_opencv_calib3d=OFF ^ --DBUILD_opencv_dnn=OFF ^ -DBUILD_opencv_features2d=OFF ^ -DBUILD_opencv_flann=OFF ^ -DBUILD_opencv_highgui=OFF ^ @@ -25,9 +36,60 @@ cmake .. -G "Visual Studio 15 Win64" ^ -DBUILD_opencv_videostab=OFF ^ -DBUILD_opencv_java_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_CUDA=OFF ^ --DWITH_CUFFT=OFF ^ +-DWITH_CUDA=ON ^ +-DWITH_CUDNN=ON ^ +-DWITH_CUFFT=ON ^ -DWITH_DIRECTX=OFF ^ -DWITH_DSHOW=OFF ^ -DWITH_EIGEN=OFF ^ @@ -37,10 +99,27 @@ cmake .. -G "Visual Studio 15 Win64" ^ -DWITH_OPENCAMDBALSL=OFF ^ -DWITH_OPENCLAMDFFT=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_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 diff --git a/waifu2x-caffe-dll/Source.cpp b/waifu2x-caffe-dll/Source.cpp index bb4a2ff..0f7892a 100644 --- a/waifu2x-caffe-dll/Source.cpp +++ b/waifu2x-caffe-dll/Source.cpp @@ -18,7 +18,7 @@ void* Waifu2xInit(const char *mode, const int noise_level, const char *model_dir else if (strcmp("auto_scale", mode) == 0) mt = Waifu2x::eWaifu2xModelTypeAutoScale; - // if (obj->Init(1, argv, mode, noise_level, 2.0, boost::optional(), boost::optional(), model_dir, process, boost::optional(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK) + // if (obj->Init(1, argv, mode, noise_level, 2.0, std::optional(), std::optional(), model_dir, process, std::optional(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK) if (obj->Init(mt, noise_level, model_dir, process) != Waifu2x::eWaifu2xError_OK) { 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) mt = Waifu2x::eWaifu2xModelTypeAutoScale; - // if (obj->Init(1, argv, mode, noise_level, 2.0, boost::optional(), boost::optional(), model_dir, process, boost::optional(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK) + // if (obj->Init(1, argv, mode, noise_level, 2.0, std::optional(), std::optional(), model_dir, process, std::optional(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK) if (obj->Init(mt, noise_level, model_dir, process) != Waifu2x::eWaifu2xError_OK) { delete obj; diff --git a/waifu2x-caffe-dll/waifu2x-caffe-dll.vcxproj b/waifu2x-caffe-dll/waifu2x-caffe-dll.vcxproj index c53563e..c720501 100644 --- a/waifu2x-caffe-dll/waifu2x-caffe-dll.vcxproj +++ b/waifu2x-caffe-dll/waifu2x-caffe-dll.vcxproj @@ -14,19 +14,19 @@ {DFF94FEB-78AB-41B1-9B92-4D8B7D799E04} Win32Proj waifu2x-caffe-dll - 8.1 + 10.0 DynamicLibrary true - v140 + v143 Unicode DynamicLibrary false - v140 + v143 true Unicode @@ -61,6 +61,7 @@ Disabled BOOST_ALL_NO_LIB;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreadedDebugDLL + stdcpp17 Console @@ -79,6 +80,7 @@ true BOOST_ALL_NO_LIB;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreadedDLL + stdcpp17 Console diff --git a/waifu2x-caffe-gui/MainDialog.cpp b/waifu2x-caffe-gui/MainDialog.cpp index d22194e..1ffad3d 100644 --- a/waifu2x-caffe-gui/MainDialog.cpp +++ b/waifu2x-caffe-gui/MainDialog.cpp @@ -58,22 +58,22 @@ namespace } // 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 - boost::filesystem::path p = boost::filesystem::absolute(path); - boost::filesystem::path r = boost::filesystem::absolute(relative_to); + std::filesystem::path p = std::filesystem::absolute(path); + std::filesystem::path r = std::filesystem::absolute(relative_to); // if root paths are different, return absolute path if (p.root_path() != r.root_path()) return p; // initialize relative path - boost::filesystem::path result; + std::filesystem::path result; // find out where the two paths diverge - boost::filesystem::path::const_iterator itr_path = p.begin(); - boost::filesystem::path::const_iterator itr_relative_to = r.begin(); + std::filesystem::path::const_iterator itr_path = p.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()) { ++itr_path; @@ -497,7 +497,7 @@ bool DialogEvent::SyncMember(const bool NotSyncCropSize, const bool silent) return ret; } -void DialogEvent::SetCropSizeList(const boost::filesystem::path & input_path) +void DialogEvent::SetCropSizeList(const std::filesystem::path & input_path) { if (isSetInitCrop) return; @@ -505,7 +505,7 @@ void DialogEvent::SetCropSizeList(const boost::filesystem::path & input_path) HWND hcrop = GetDlgItem(dh, IDC_COMBO_CROP_SIZE); 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; 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 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); 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::filesystem::recursive_directory_iterator())) + BOOST_FOREACH(const std::filesystem::path& p, std::make_pair(std::filesystem::recursive_directory_iterator(path), + std::filesystem::recursive_directory_iterator())) { - if (!boost::filesystem::is_directory(p)) + if (!std::filesystem::is_directory(p)) { tstring ext(getTString(p.extension())); #ifdef UNICODE @@ -674,12 +674,12 @@ void DialogEvent::ProcessWaifu2x() for (const auto &p : file_paths) { - const boost::filesystem::path out_path(p.second); - const boost::filesystem::path out_dir(out_path.parent_path()); + const std::filesystem::path out_path(p.second); + 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); PostMessage(dh, WM_END_THREAD, 0, 0); @@ -691,12 +691,12 @@ void DialogEvent::ProcessWaifu2x() } else { - const boost::filesystem::path output_path(output_str); + const std::filesystem::path output_path(output_str); 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); PostMessage(dh, WM_END_THREAD, 0, 0); @@ -711,8 +711,8 @@ void DialogEvent::ProcessWaifu2x() const auto inputFuncMulti = [this, &file_paths](const tstring &input) { - const boost::filesystem::path input_path(boost::filesystem::absolute(input)); - const boost::filesystem::path output_path(boost::filesystem::absolute(output_str)); + const std::filesystem::path input_path(std::filesystem::absolute(input)); + const std::filesystem::path output_path(std::filesystem::absolute(output_str)); const auto outilenameFunc = [&output_path](const tstring &path) -> std::wstring { @@ -720,11 +720,11 @@ void DialogEvent::ProcessWaifu2x() 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); PostMessage(dh, WM_END_THREAD, 0, 0); @@ -736,12 +736,12 @@ void DialogEvent::ProcessWaifu2x() 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::filesystem::recursive_directory_iterator())) + BOOST_FOREACH(const std::filesystem::path& p, std::make_pair(std::filesystem::recursive_directory_iterator(path), + std::filesystem::recursive_directory_iterator())) { - if (!boost::filesystem::is_directory(p)) + if (!std::filesystem::is_directory(p)) { tstring ext(getTString(p.extension())); #ifdef UNICODE @@ -770,12 +770,12 @@ void DialogEvent::ProcessWaifu2x() for (const auto &p : file_paths) { - const boost::filesystem::path out_path(p.second); - const boost::filesystem::path out_dir(out_path.parent_path()); + const std::filesystem::path out_path(p.second); + 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); PostMessage(dh, WM_END_THREAD, 0, 0); @@ -789,9 +789,9 @@ void DialogEvent::ProcessWaifu2x() { 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); PostMessage(dh, WM_END_THREAD, 0, 0); @@ -849,8 +849,8 @@ void DialogEvent::ProcessWaifu2x() ProgessFunc(maxFile, 0); - boost::optional ScaleRatio; - boost::optional ScaleWidth, ScaleHeight; + std::optional ScaleRatio; + std::optional ScaleWidth, ScaleHeight; switch (scaleType) { case eScaleTypeRatio: @@ -875,7 +875,7 @@ void DialogEvent::ProcessWaifu2x() const auto fileNum = file_paths.size(); 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()); @@ -943,10 +943,10 @@ void DialogEvent::ReplaceAddString() // { SyncMember(true, true); - const boost::filesystem::path output_path(output_str); + const std::filesystem::path output_path(output_str); 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()); else stem = getTString(output_path.filename()); @@ -963,8 +963,8 @@ void DialogEvent::ReplaceAddString() // autoSetAddName = addstr; - boost::filesystem::path new_out_path; - if (input_str_multi.size() == 0 && !boost::filesystem::is_directory(input_str)) + std::filesystem::path new_out_path; + if (input_str_multi.size() == 0 && !std::filesystem::is_directory(input_str)) new_out_path = output_path.branch_path() / (new_name + outputExt); else new_out_path = output_path.branch_path() / (new_name); @@ -1040,7 +1040,7 @@ void DialogEvent::SaveIni(const bool isSyncMember) if (isNotSaveParam) return; - const boost::filesystem::path SettingFilePath(exeDir / SettingFileName); + const std::filesystem::path SettingFilePath(exeDir / SettingFileName); tstring tScaleRatio; tstring tScaleWidth; @@ -1338,8 +1338,8 @@ UINT_PTR DialogEvent::OFNHookProcOut(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARA { szPath[_countof(szPath) - 1] = TEXT('\0'); - boost::filesystem::path p(szPath); - if (boost::filesystem::exists(p) && (boost::filesystem::is_empty(p) || boost::filesystem::is_directory(p))) + std::filesystem::path p(szPath); + if (std::filesystem::exists(p) && (std::filesystem::is_empty(p) || std::filesystem::is_directory(p))) { 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) { - const boost::filesystem::path *p = (const boost::filesystem::path *)wParam; + const std::filesystem::path *p = (const std::filesystem::path *)wParam; TCHAR msg[1024 * 2]; _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)); texepath[_countof(texepath) - 1] = TEXT('\0'); - const boost::filesystem::path exePath(texepath); + const std::filesystem::path exePath(texepath); 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 boost::filesystem::path LangListPath(exeDir / LangListFileName); + const std::filesystem::path LangDirPath(exeDir / LangDir); + const std::filesystem::path LangListPath(exeDir / LangListFileName); langStringList.SetLangBaseDir(getTString(LangDirPath)); 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); } - const boost::filesystem::path CropSizeListPath(exeDir / CropSizeListName); + const std::filesystem::path CropSizeListPath(exeDir / CropSizeListName); std::ifstream ifs(CropSizeListPath.wstring()); 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()); - if (tOutputDirFix.length() > 0 && boost::filesystem::exists(tOutputDirFix)) + if (tOutputDirFix.length() > 0 && std::filesystem::exists(tOutputDirFix)) { output_dir = tOutputDirFix; 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); - 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); return 0L; @@ -2770,9 +2770,9 @@ LRESULT DialogEvent::OnSetInputFilePath(const TCHAR * tPath) 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); @@ -2832,7 +2832,7 @@ LRESULT DialogEvent::OnSetInputFilePath() const tstring addstr(AddName()); autoSetAddName = AddName(); - boost::filesystem::path outpath(output_dir); + std::filesystem::path outpath(output_dir); if (output_dir.length() == 0) // 出力パス未設定なら入力ファイルと同じフォルダ { @@ -2840,10 +2840,10 @@ LRESULT DialogEvent::OnSetInputFilePath() outpath = outpath.branch_path(); } - boost::filesystem::path baseDir(input_str_multi[0]); + std::filesystem::path baseDir(input_str_multi[0]); tstring filename; - if (boost::filesystem::is_directory(baseDir)) + if (std::filesystem::is_directory(baseDir)) filename = baseDir.filename().wstring(); else filename = baseDir.stem().wstring(); @@ -2865,15 +2865,15 @@ LRESULT DialogEvent::OnSetOutputFilePath(const TCHAR * tPath) if (input_str.length() > 0 || input_str_multi.size() > 0) { - boost::filesystem::path path(input_str); - boost::filesystem::path outpath(tPath); + std::filesystem::path path(input_str); + std::filesystem::path outpath(tPath); if (input_str_multi.size() > 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); @@ -2952,7 +2952,7 @@ LRESULT DialogEvent::DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC } 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); } @@ -3037,7 +3037,7 @@ void DialogEvent::InputRef(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpDat *tfp = TEXT('\0'); tfp++; - if (tInputDirFix.length() > 0 && boost::filesystem::exists(tInputDirFix)) + if (tInputDirFix.length() > 0 && std::filesystem::exists(tInputDirFix)) ofn.lpstrInitialDir = tInputDirFix.c_str(); else ofn.lpstrInitialDir = szPath; @@ -3104,7 +3104,7 @@ void DialogEvent::InputRef(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpDat } 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); } @@ -3139,7 +3139,7 @@ void DialogEvent::OutputRef(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpDa memcpy(tfp, allFilesExt.c_str(), allFilesExt.length() * sizeof(TCHAR)); tfp += allFilesExt.length(); - if (tOutputDirFix.length() > 0 && boost::filesystem::exists(tOutputDirFix)) + if (tOutputDirFix.length() > 0 && std::filesystem::exists(tOutputDirFix)) ofn.lpstrInitialDir = tOutputDirFix.c_str(); else ofn.lpstrInitialDir = szPath; @@ -3417,7 +3417,7 @@ void DialogEvent::AppSetting(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpD tOutputDirFix = cAppSettingDialogEvent.tOutputDirFix; gpu_no = cAppSettingDialogEvent.gpu_no; - if (tOutputDirFix.length() > 0 && boost::filesystem::exists(tOutputDirFix)) + if (tOutputDirFix.length() > 0 && std::filesystem::exists(tOutputDirFix)) { output_dir = tOutputDirFix; } diff --git a/waifu2x-caffe-gui/MainDialog.h b/waifu2x-caffe-gui/MainDialog.h index 102d7dd..df943f4 100644 --- a/waifu2x-caffe-gui/MainDialog.h +++ b/waifu2x-caffe-gui/MainDialog.h @@ -7,8 +7,8 @@ #include #include #include -#include -#include +#include +#include #include "../common/waifu2x.h" #include "resource.h" #include "tstring.h" @@ -77,7 +77,7 @@ private: static LangStringList langStringList; - boost::filesystem::path exeDir; + std::filesystem::path exeDir; std::vector CropSizeList; tstring input_str; @@ -96,7 +96,7 @@ private: bool use_tta; - boost::optional output_quality; + std::optional output_quality; int output_depth; int crop_size; @@ -158,11 +158,11 @@ private: 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(); else return input_path.filename(); @@ -172,7 +172,7 @@ private: void ReplaceAddString(); - void AddLogMessage(const TCHAR *msg); + void AddLogMessage(const TCHAR* msg); void Waifu2xTime(); @@ -231,11 +231,11 @@ public: void OnModelChange(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData); - LRESULT OnSetInputFilePath(const TCHAR *tPath); + LRESULT OnSetInputFilePath(const TCHAR* tPath); LRESULT OnSetInputFilePath(); - LRESULT OnSetOutputFilePath(const TCHAR *tPath); + LRESULT OnSetOutputFilePath(const TCHAR* tPath); // ここで渡されるhWndはIDC_EDITのHWND(コントロールのイベントだから) LRESULT DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData); diff --git a/waifu2x-caffe-gui/tstring.h b/waifu2x-caffe-gui/tstring.h index a44758f..c9ba19c 100644 --- a/waifu2x-caffe-gui/tstring.h +++ b/waifu2x-caffe-gui/tstring.h @@ -6,13 +6,13 @@ #ifdef UNICODE typedef std::wstring tstring; -inline tstring getTString(const boost::filesystem::path& p) +inline tstring getTString(const std::filesystem::path& p) { return p.wstring(); } #else typedef std::string tstring; -inline tstring getTString(const boost::filesystem::path& p) +inline tstring getTString(const std::filesystem::path& p) { return p.string(); } diff --git a/waifu2x-caffe-gui/waifu2x-caffe-gui.vcxproj b/waifu2x-caffe-gui/waifu2x-caffe-gui.vcxproj index d685474..6099d07 100644 --- a/waifu2x-caffe-gui/waifu2x-caffe-gui.vcxproj +++ b/waifu2x-caffe-gui/waifu2x-caffe-gui.vcxproj @@ -14,19 +14,19 @@ {63FB3EFC-63B0-401C-BB54-F3A984DC233F} Win32Proj waifu2xcaffegui - 8.1 + 10.0 Application true - v140 + v143 Unicode Application false - v140 + v143 true Unicode @@ -61,6 +61,7 @@ Disabled BOOST_ALL_NO_LIB;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDebugDLL + stdcpp17 Windows @@ -82,6 +83,7 @@ true BOOST_ALL_NO_LIB;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDLL + stdcpp17 Windows diff --git a/waifu2x-caffe/Source.cpp b/waifu2x-caffe/Source.cpp index 6fb3f58..6d3cd99 100644 --- a/waifu2x-caffe/Source.cpp +++ b/waifu2x-caffe/Source.cpp @@ -1,11 +1,8 @@ #include +#include #include -#include -#include +#include #include -#include -#include -#include #include #include "../common/waifu2x.h" @@ -17,6 +14,7 @@ #include using namespace TCLAPW; typedef std::wstring tstring; +typedef std::wstringstream tstringstream; typedef wchar_t TCHAR; #ifndef TEXT #define TEXT(x) L##x @@ -26,7 +24,7 @@ typedef wchar_t TCHAR; #define tprintf wprintf #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(); } @@ -34,6 +32,7 @@ const tstring& path_to_tstring(const boost::filesystem::path &p) #include using namespace TCLAP; typedef std::string tstring; +typedef std::stringstream tstringstream; typedef char TCHAR; #ifndef TEXT #define TEXT(x) x @@ -43,7 +42,7 @@ typedef char TCHAR; #define tprintf printf #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(); } @@ -51,22 +50,22 @@ const tstring& path_to_tstring(const boost::filesystem::path &p) // 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 - boost::filesystem::path p = boost::filesystem::absolute(path); - boost::filesystem::path r = boost::filesystem::absolute(relative_to); + std::filesystem::path p = std::filesystem::absolute(path); + std::filesystem::path r = std::filesystem::absolute(relative_to); // if root paths are different, return absolute path if (p.root_path() != r.root_path()) return p; // initialize relative path - boost::filesystem::path result; + std::filesystem::path result; // find out where the two paths diverge - boost::filesystem::path::const_iterator itr_path = p.begin(); - boost::filesystem::path::const_iterator itr_relative_to = r.begin(); + std::filesystem::path::const_iterator itr_path = p.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()) { ++itr_path; ++itr_relative_to; @@ -99,14 +98,6 @@ int main(int argc, char** 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 CmdLine cmd(TEXT("waifu2x reimplementation using Caffe"), ' ', TEXT("1.0.0")); @@ -209,22 +200,22 @@ int main(int argc, char** argv) { #ifdef WIN_UNICODE int nArgs = 0; - LPTSTR *lplpszArgs = CommandLineToArgvW(GetCommandLine(), &nArgs); + LPTSTR* lplpszArgs = CommandLineToArgvW(GetCommandLine(), &nArgs); cmd.parse(nArgs, lplpszArgs); LocalFree(lplpszArgs); #else cmd.parse(argc, argv); #endif } - catch (std::exception &e) + catch (std::exception& e) { tprintf(TEXT("エラー: ") CHAR_STR_FORMAT TEXT("\n"), e.what()); return 1; } - boost::optional ScaleRatio; - boost::optional ScaleWidth; - boost::optional ScaleHeight; + std::optional ScaleRatio; + std::optional ScaleWidth; + std::optional ScaleHeight; int crop_w = cmdCropSizeFile.getValue(); int crop_h = cmdCropSizeFile.getValue(); @@ -236,14 +227,14 @@ int main(int argc, char** argv) crop_h = cmdCropHeight.getValue(); if (cmdScaleWidth.getValue() > 0) - ScaleWidth = cmdScaleWidth.getValue(); + ScaleWidth = (int)cmdScaleWidth.getValue(); if (cmdScaleHeight.getValue() > 0) - ScaleHeight = cmdScaleHeight.getValue(); + ScaleHeight = (int)cmdScaleHeight.getValue(); if (cmdScaleWidth.getValue() == 0 && cmdScaleHeight.getValue() == 0) 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(); if (outputExt.length() > 0 && outputExt[0] != TEXT('.')) @@ -265,9 +256,9 @@ int main(int argc, char** argv) const bool use_tta = cmdTTALevel.getValue() == 1; std::vector> 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)")) { @@ -277,7 +268,7 @@ int main(int argc, char** argv) addstr += tModelName; addstr += TEXT(")"); - const tstring &mode = cmdMode.getValue(); + const tstring& mode = cmdMode.getValue(); addstr += TEXT("(") + mode + TEXT(")"); @@ -288,7 +279,7 @@ int main(int argc, char** argv) addstr += TEXT("(tta)"); if (mode.find(TEXT("scale")) != mode.npos) { - if(ScaleRatio) + if (ScaleRatio) addstr += TEXT("(x") + to_tstring(*ScaleRatio) + TEXT(")"); else if (ScaleWidth && ScaleHeight) 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) 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 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()); return 1; @@ -321,58 +312,69 @@ int main(int argc, char** argv) { // input_extention_listを文字列の配列にする - typedef boost::char_separator char_separator; - typedef boost::tokenizer 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) + tstringstream check1(cmdInputFileExt.getValue()); + tstring ext; + while (std::getline(check1, ext, TEXT(':'))) { - tstring ext(*tok_iter); std::transform(ext.begin(), ext.end(), ext.begin(), totlower); extList.push_back(TEXT(".") + ext); } + + //typedef boost::char_separator char_separator; + //typedef boost::tokenizer 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)) - { - tprintf(TEXT("エラー: 出力フォルダ「%s」の作成に失敗しました\n"), path_to_tstring(out_absolute).c_str()); - return false; - } - } - } - else + + // 変換する画像の入力、出力パスを取得 + const auto func = [&extList, &input_path, &output_path, &outputExt, &file_paths](const std::filesystem::path& path) + { + for (const auto& i : std::filesystem::recursive_directory_iterator(path)) { - 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 std::filesystem::path& p = i.path(); + + if (std::filesystem::is_directory(p)) { const auto out_relative = relativePath(p, input_path); 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)) return 1; @@ -393,7 +395,7 @@ int main(int argc, char** argv) addstr += tModelName; addstr += TEXT(")"); - const tstring &mode = cmdMode.getValue(); + const tstring& mode = cmdMode.getValue(); addstr += TEXT("(") + mode + TEXT(")"); @@ -461,11 +463,11 @@ int main(int argc, char** argv) } 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, crop_w, crop_h, - cmdOutputQuality.getValue() == -1 ? boost::optional() : cmdOutputQuality.getValue(), cmdOutputDepth.getValue(), use_tta, cmdBatchSizeFile.getValue()); + cmdOutputQuality.getValue() == -1 ? std::optional() : cmdOutputQuality.getValue(), cmdOutputDepth.getValue(), use_tta, cmdBatchSizeFile.getValue()); if (ret != Waifu2x::eWaifu2xError_OK) { switch (ret) diff --git a/waifu2x-caffe/waifu2x-caffe.vcxproj b/waifu2x-caffe/waifu2x-caffe.vcxproj index 3881221..2af00c3 100644 --- a/waifu2x-caffe/waifu2x-caffe.vcxproj +++ b/waifu2x-caffe/waifu2x-caffe.vcxproj @@ -14,19 +14,19 @@ {7C406EE4-2309-4D4C-98BB-CB7BA865FC41} Win32Proj waifu2x-caffe - 8.1 + 10.0 Application true - v140 + v143 Unicode Application false - v140 + v143 true Unicode @@ -42,15 +42,15 @@ true - $(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) - $(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) + $(CUDA_PATH_V13_0)\include;$(SolutionDir)lib\include;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(SolutionDir)msgpack-c\include;$(IncludePath) + $(CUDA_PATH_V13_0)\lib\$(PlatformName);$(SolutionDir)lib\$(PlatformName)\vc17\staticlib;$(SolutionDir)lib\lib;$(LibraryPath) $(SolutionDir)bin\ $(ProjectName)d false - $(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) - $(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) + $(CUDA_PATH_V13_0)\include;$(SolutionDir)lib\include;$(SolutionDir)rapidjson\include;$(SolutionDir)stb;$(SolutionDir)include;$(SolutionDir)msgpack-c\include;$(IncludePath) + $(CUDA_PATH_V13_0)\lib\$(PlatformName);$(SolutionDir)lib\$(PlatformName)\vc17\staticlib;$(SolutionDir)lib\lib;$(LibraryPath) $(SolutionDir)bin\ @@ -59,8 +59,9 @@ Level3 Disabled - BOOST_ALL_NO_LIB;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreadedDebugDLL + stdcpp17 Console @@ -77,8 +78,9 @@ MaxSpeed true true - BOOST_ALL_NO_LIB;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreadedDLL + stdcpp17 Console