From 2c46d8f22e6d7b0a92679222dd8dd8b4eee0601f Mon Sep 17 00:00:00 2001 From: lltcggie Date: Sat, 19 Mar 2016 18:25:30 +0900 Subject: [PATCH] =?UTF-8?q?CUI=E3=81=A8DLL=E3=82=82=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- waifu2x-caffe-dll/Source.cpp | 2 +- waifu2x-caffe/Source.cpp | 40 ++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/waifu2x-caffe-dll/Source.cpp b/waifu2x-caffe-dll/Source.cpp index 2712d59..b2d02eb 100644 --- a/waifu2x-caffe-dll/Source.cpp +++ b/waifu2x-caffe-dll/Source.cpp @@ -10,7 +10,7 @@ void* Waifu2xInit(const char *mode, const int noise_level, const char *model_dir char *argv[] = { "" }; - if (obj->init(1, argv, mode, noise_level, 2.0, 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, boost::optional(), boost::optional(), model_dir, process, boost::optional(), output_depth, use_tta, crop_size, batch_size) != Waifu2x::eWaifu2xError_OK) { delete obj; return nullptr; diff --git a/waifu2x-caffe/Source.cpp b/waifu2x-caffe/Source.cpp index 873c996..039e746 100644 --- a/waifu2x-caffe/Source.cpp +++ b/waifu2x-caffe/Source.cpp @@ -100,6 +100,12 @@ int main(int argc, char** argv) TCLAP::ValueArg cmdScaleRatio("s", "scale_ratio", "custom scale ratio", false, 2.0, "double", cmd); + TCLAP::ValueArg cmdScaleWidth("w", "scale_width", + "custom scale width", false, 0, "double", cmd); + + TCLAP::ValueArg cmdScaleHeight("h", "scale_height", + "custom scale height", false, 0, "double", cmd); + TCLAP::ValueArg cmdModelPath("", "model_dir", "path to custom model directory (don't append last / )", false, "models/anime_style_art_rgb", "string", cmd); @@ -150,6 +156,29 @@ int main(int argc, char** argv) return 1; } + boost::optional ScaleRatio; + boost::optional ScaleWidth; + boost::optional ScaleHeight; + + int valid_num = 0; + if (cmdScaleWidth.getValue() > 0) + valid_num++; + if (cmdScaleHeight.getValue() > 0) + valid_num++; + + if (valid_num > 1) + { + printf("エラー: scale_widthとscale_heightは同時に指定できません\n"); + return 1; + } + + if (cmdScaleWidth.getValue() > 0) + ScaleWidth = cmdScaleWidth.getValue(); + else if (cmdScaleHeight.getValue() > 0) + ScaleHeight = cmdScaleHeight.getValue(); + else + ScaleRatio = cmdScaleRatio.getValue(); + const boost::filesystem::path input_path(boost::filesystem::absolute((cmdInputFile.getValue()))); std::string outputExt = cmdOutputFileExt.getValue(); @@ -175,7 +204,14 @@ int main(int argc, char** argv) if (use_tta) addstr += "(tta)"; if (mode.find("scale") != mode.npos) - addstr += "(x" + std::to_string(cmdScaleRatio.getValue()) + ")"; + { + if(ScaleRatio) + addstr += "(x" + std::to_string(*ScaleRatio) + ")"; + else if (ScaleWidth) + addstr += "(width " + std::to_string(*ScaleWidth) + ")"; + else + addstr += "(height " + std::to_string(*ScaleHeight) + ")"; + } output_path = input_path.branch_path() / (input_path.stem().string() + addstr); } @@ -280,7 +316,7 @@ int main(int argc, char** argv) Waifu2x::eWaifu2xError ret; Waifu2x w; - ret = w.init(argc, argv, cmdMode.getValue(), cmdNRLevel.getValue(), cmdScaleRatio.getValue(), cmdModelPath.getValue(), cmdProcess.getValue(), + ret = w.init(argc, argv, cmdMode.getValue(), cmdNRLevel.getValue(), ScaleRatio, ScaleWidth, ScaleHeight, cmdModelPath.getValue(), cmdProcess.getValue(), cmdOutputQuality.getValue() == -1 ? boost::optional() : cmdOutputQuality.getValue(), cmdOutputDepth.getValue(), use_tta, cmdCropSizeFile.getValue(), cmdBatchSizeFile.getValue()); switch (ret)