mirror of
https://github.com/lltcggie/waifu2x-caffe.git
synced 2025-06-26 05:32:47 +00:00
サイズ指定変換に対応
This commit is contained in:
parent
41fdf561d8
commit
f3bb4fe182
@ -382,6 +382,16 @@ Waifu2x::eWaifu2xError stImage::Load(const void* source, const int width, const
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double stImage::GetScaleFromWidth(const int width) const
|
||||||
|
{
|
||||||
|
return (double)width / (double)mOrgSize.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
double stImage::GetScaleFromHeight(const int height) const
|
||||||
|
{
|
||||||
|
return (double)height / (double)mOrgSize.height;
|
||||||
|
}
|
||||||
|
|
||||||
bool stImage::RequestDenoise() const
|
bool stImage::RequestDenoise() const
|
||||||
{
|
{
|
||||||
return mIsRequestDenoise;
|
return mIsRequestDenoise;
|
||||||
|
@ -89,6 +89,9 @@ public:
|
|||||||
// sourceはPostprocess()が終わるまで存在している必要がある
|
// sourceはPostprocess()が終わるまで存在している必要がある
|
||||||
Waifu2x::eWaifu2xError Load(const void* source, const int width, const int height, const int channel, const int stride);
|
Waifu2x::eWaifu2xError Load(const void* source, const int width, const int height, const int channel, const int stride);
|
||||||
|
|
||||||
|
double GetScaleFromWidth(const int width) const;
|
||||||
|
double GetScaleFromHeight(const int width) const;
|
||||||
|
|
||||||
bool RequestDenoise() const;
|
bool RequestDenoise() const;
|
||||||
|
|
||||||
// 前処理
|
// 前処理
|
||||||
|
@ -401,7 +401,8 @@ boost::filesystem::path Waifu2x::GetInfoPath(const boost::filesystem::path &mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError Waifu2x::waifu2x(const boost::filesystem::path &input_file, const boost::filesystem::path &output_file,
|
Waifu2x::eWaifu2xError Waifu2x::waifu2x(const boost::filesystem::path &input_file, const boost::filesystem::path &output_file,
|
||||||
const double factor, const waifu2xCancelFunc cancel_func, const int crop_w, const int crop_h,
|
const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
||||||
|
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 boost::optional<int> output_quality, const int output_depth, const bool use_tta,
|
||||||
const int batch_size)
|
const int batch_size)
|
||||||
{
|
{
|
||||||
@ -420,7 +421,8 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const boost::filesystem::path &input_fil
|
|||||||
const bool isReconstructNoise = mMode == eWaifu2xModelTypeNoise || mMode == eWaifu2xModelTypeNoiseScale || (mMode == eWaifu2xModelTypeAutoScale && image.RequestDenoise());
|
const bool isReconstructNoise = mMode == eWaifu2xModelTypeNoise || mMode == eWaifu2xModelTypeNoiseScale || (mMode == eWaifu2xModelTypeAutoScale && image.RequestDenoise());
|
||||||
const bool isReconstructScale = mMode == eWaifu2xModelTypeScale || mMode == eWaifu2xModelTypeNoiseScale || mMode == eWaifu2xModelTypeAutoScale;
|
const bool isReconstructScale = mMode == eWaifu2xModelTypeScale || mMode == eWaifu2xModelTypeNoiseScale || mMode == eWaifu2xModelTypeAutoScale;
|
||||||
|
|
||||||
double Factor = factor;
|
double Factor = CalcScaleRatio(scale_ratio, scale_width, scale_height, image);
|
||||||
|
|
||||||
if (!isReconstructScale)
|
if (!isReconstructScale)
|
||||||
Factor = 1.0;
|
Factor = 1.0;
|
||||||
|
|
||||||
@ -482,6 +484,21 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const double factor, const void* source,
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Waifu2x::CalcScaleRatio(const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
||||||
|
const stImage &image)
|
||||||
|
{
|
||||||
|
if (scale_ratio)
|
||||||
|
return *scale_ratio;
|
||||||
|
|
||||||
|
if (scale_width)
|
||||||
|
return image.GetScaleFromWidth(*scale_width);
|
||||||
|
|
||||||
|
if(scale_height)
|
||||||
|
return image.GetScaleFromWidth(*scale_height);
|
||||||
|
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError Waifu2x::ReconstructImage(const double factor, const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
Waifu2x::eWaifu2xError Waifu2x::ReconstructImage(const double 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)
|
||||||
{
|
{
|
||||||
@ -691,17 +708,6 @@ Waifu2x::eWaifu2xError Waifu2x::ProcessNet(std::shared_ptr<cNet> net, const int
|
|||||||
return Waifu2x::eWaifu2xError_OK;
|
return Waifu2x::eWaifu2xError_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//double Waifu2x::CalcScaleRatio(const cv::Size_<int> &size) const
|
|
||||||
//{
|
|
||||||
// if (scale_ratio)
|
|
||||||
// return *scale_ratio;
|
|
||||||
//
|
|
||||||
// if (scale_width)
|
|
||||||
// return (double)*scale_width / (double)size.width;
|
|
||||||
//
|
|
||||||
// return (double)*scale_height / (double)size.height;
|
|
||||||
//}
|
|
||||||
|
|
||||||
void Waifu2x::Destroy()
|
void Waifu2x::Destroy()
|
||||||
{
|
{
|
||||||
mNoiseNet.reset();
|
mNoiseNet.reset();
|
||||||
|
@ -96,6 +96,9 @@ private:
|
|||||||
static boost::filesystem::path GetModeDirPath(const boost::filesystem::path &model_dir);
|
static boost::filesystem::path GetModeDirPath(const boost::filesystem::path &model_dir);
|
||||||
static boost::filesystem::path GetInfoPath(const boost::filesystem::path &model_dir);
|
static boost::filesystem::path GetInfoPath(const boost::filesystem::path &model_dir);
|
||||||
|
|
||||||
|
static double CalcScaleRatio(const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
||||||
|
const stImage &image);
|
||||||
|
|
||||||
Waifu2x::eWaifu2xError ReconstructImage(const double factor, const int crop_w, const int crop_h, const bool use_tta, const int batch_size,
|
Waifu2x::eWaifu2xError ReconstructImage(const double 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,
|
||||||
@ -106,8 +109,6 @@ private:
|
|||||||
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);
|
||||||
|
|
||||||
// double CalcScaleRatio(const cv::Size_<int> &size) const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Waifu2x();
|
Waifu2x();
|
||||||
~Waifu2x();
|
~Waifu2x();
|
||||||
@ -124,7 +125,8 @@ public:
|
|||||||
const boost::filesystem::path &model_dir, const std::string &process);
|
const boost::filesystem::path &model_dir, const std::string &process);
|
||||||
|
|
||||||
eWaifu2xError waifu2x(const boost::filesystem::path &input_file, const boost::filesystem::path &output_file,
|
eWaifu2xError waifu2x(const boost::filesystem::path &input_file, const boost::filesystem::path &output_file,
|
||||||
const double factor, const waifu2xCancelFunc cancel_func = nullptr, const int crop_w = 128, const int crop_h = 128,
|
const boost::optional<double> scale_ratio, const boost::optional<int> scale_width, const boost::optional<int> scale_height,
|
||||||
|
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 boost::optional<int> output_quality = boost::optional<int>(), const int output_depth = 8, const bool use_tta = false,
|
||||||
const int batch_size = 1);
|
const int batch_size = 1);
|
||||||
|
|
||||||
|
@ -706,6 +706,21 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
|
|
||||||
ProgessFunc(maxFile, 0);
|
ProgessFunc(maxFile, 0);
|
||||||
|
|
||||||
|
boost::optional<double> ScaleRatio;
|
||||||
|
boost::optional<int> ScaleWidth, ScaleHeight;
|
||||||
|
switch (scaleType)
|
||||||
|
{
|
||||||
|
case eScaleTypeRatio:
|
||||||
|
ScaleRatio = scale_ratio;
|
||||||
|
break;
|
||||||
|
case eScaleTypeWidth:
|
||||||
|
ScaleWidth = scale_width;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ScaleHeight = scale_height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
DWORD startTime = 0;
|
DWORD startTime = 0;
|
||||||
|
|
||||||
int64_t processeNum = 0;
|
int64_t processeNum = 0;
|
||||||
@ -725,24 +740,7 @@ void DialogEvent::ProcessWaifu2x()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double factor;
|
ret = w.waifu2x(p.first, p.second, ScaleRatio, ScaleWidth, ScaleHeight, [this]()
|
||||||
|
|
||||||
//switch (scaleType)
|
|
||||||
//{
|
|
||||||
//case eScaleTypeRatio:
|
|
||||||
// ScaleRatio = scale_ratio;
|
|
||||||
// break;
|
|
||||||
//case eScaleTypeWidth:
|
|
||||||
// ScaleWidth = scale_width;
|
|
||||||
// break;
|
|
||||||
//default:
|
|
||||||
// ScaleHeight = scale_height;
|
|
||||||
// break;
|
|
||||||
//}
|
|
||||||
|
|
||||||
factor = scale_ratio;
|
|
||||||
|
|
||||||
ret = w.waifu2x(p.first, p.second, factor, [this]()
|
|
||||||
{
|
{
|
||||||
return cancelFlag;
|
return cancelFlag;
|
||||||
}, crop_size, crop_size, output_quality, output_depth, use_tta, batch_size);
|
}, crop_size, crop_size, output_quality, output_depth, use_tta, batch_size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user