From c8cb9dd5206c7813ffdd625ef74dc0f46c33dc96 Mon Sep 17 00:00:00 2001 From: TianZerL Date: Sat, 11 Apr 2020 20:01:16 +0800 Subject: [PATCH] Add push color control --- Anime4K09/include/Anime4K.h | 6 ++++-- Anime4K09/src/Anime4K.cpp | 15 ++++++++------- Anime4K09/src/main.cpp | 5 ++++- README.md | 7 ++++--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Anime4K09/include/Anime4K.h b/Anime4K09/include/Anime4K.h index f0bb5d52..a310824f 100644 --- a/Anime4K09/include/Anime4K.h +++ b/Anime4K09/include/Anime4K.h @@ -28,6 +28,7 @@ class Anime4K public: Anime4K( int passes = 2, + int pushColorCount = 2, double strengthColor = 0.3, double strengthGradient = 1.0, double zoomFactor = 2.0, @@ -56,6 +57,7 @@ class Anime4K private: const static int B = 0, G = 1, R = 2, A = 3; int orgH, orgW, H, W; + double fps; size_t totalFrameCount, frameCount; cv::Mat orgImg, dstImg; cv::VideoCapture video; @@ -64,8 +66,8 @@ class Anime4K std::condition_variable cnd; private://arguments unsigned int mt; - int ps; - double sc, sg, zf, fps; + int ps, pcc; + double sc, sg, zf; bool fm, vm, pp; uint8_t fl; }; diff --git a/Anime4K09/src/Anime4K.cpp b/Anime4K09/src/Anime4K.cpp index 2ed1af78..77c860a1 100644 --- a/Anime4K09/src/Anime4K.cpp +++ b/Anime4K09/src/Anime4K.cpp @@ -2,6 +2,7 @@ Anime4K::Anime4K( int passes, + int pushColorCount, double strengthColor, double strengthGradient, double zoomFactor, @@ -11,9 +12,9 @@ Anime4K::Anime4K( uint8_t filters, unsigned int maxThreads ) : - ps(passes), sc(strengthColor), - sg(strengthGradient), zf(zoomFactor), - fm(fastMode), vm(videoMode), + ps(passes), pcc(pushColorCount), + sc(strengthColor), sg(strengthGradient), + zf(zoomFactor), fm(fastMode), vm(videoMode), pp(postProcessing), fl(filters), mt(maxThreads) { orgH = orgW = H = W = 0; @@ -74,6 +75,7 @@ void Anime4K::showInfo() std::cout << orgW << "x" << orgH << " to " << W << "x" << H << std::endl; std::cout << "----------------------------------------------" << std::endl; std::cout << "Passes: " << ps << std::endl + << "pushColorCount: " << pcc << std::endl << "Zoom Factor: " << zf << std::endl << "Video Mode: " << std::boolalpha << vm << std::endl << "Fast Mode: " << std::boolalpha << fm << std::endl @@ -125,7 +127,7 @@ void Anime4K::process() for (int i = 0; i < ps; i++) { getGray(dstImg); - if (sc) + if (sc && (pcc-- > 0)) pushColor(dstImg); getGradient(dstImg); pushGradient(dstImg); @@ -135,7 +137,6 @@ void Anime4K::process() cv::cvtColor(dstImg, dstImg, cv::COLOR_BGRA2BGR); PostProcessor(dstImg, fl).process(); } - } else { @@ -152,7 +153,7 @@ void Anime4K::process() break; } - pool.exec>([orgFrame = orgFrame.clone(), dstFrame = dstFrame.clone(), this, curFrame]()mutable + pool.exec>([orgFrame = orgFrame.clone(), dstFrame = dstFrame.clone(), this, curFrame, pcc = this->pcc]()mutable { cv::resize(orgFrame, dstFrame, cv::Size(0, 0), zf, zf, cv::INTER_CUBIC); if (dstFrame.channels() == 3) @@ -160,7 +161,7 @@ void Anime4K::process() for (int i = 0; i < ps; i++) { getGray(dstFrame); - if (sc) + if (sc && (pcc-- > 0)) pushColor(dstFrame); getGradient(dstFrame); pushGradient(dstFrame); diff --git a/Anime4K09/src/main.cpp b/Anime4K09/src/main.cpp index bf48aad5..6d2fb42a 100644 --- a/Anime4K09/src/main.cpp +++ b/Anime4K09/src/main.cpp @@ -29,6 +29,7 @@ int main(int argc, char* argv[]) opt.add("input", 'i', "File for loading", false, "./pic/p1.png"); opt.add("output", 'o', "File for outputting", false, "output.png"); opt.add("passes", 'p', "Passes for processing", false, 2); + opt.add("pushColorCount", 'n', "Limit the number of color pushes", false, 2); opt.add("strengthColor", 'c', "Strength for pushing color,range 0 to 1,higher for thinner", false, 0.3, cmdline::range(0.0, 1.0)); opt.add("strengthGradient", 'g', "Strength for pushing gradient,range 0 to 1,higher for sharper", false, 1.0, cmdline::range(0.0, 1.0)); opt.add("zoomFactor", 'z', "zoom factor for resizing", false, 2.0); @@ -40,7 +41,7 @@ int main(int argc, char* argv[]) opt.add("filters", 'e', "Enhancement filter, only working when postProcessing is true,there are 5 options by binary:\ Median blur=000001, Mean blur=000010, Gaussian blur weak=000100, Gaussian blur=001000, Bilateral filter=010000, Bilateral filter faster=100000, \ -you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 & 010000 = 010100 = 20(D), \ +you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 | 010000 = 010100 = 20(D), \ so you can put 20 to enable Gaussian blur weak and Bilateral filter, which also is what I recommend for image that < 1080P, \ 24 for image that >= 1080P, and for performance I recommend to use 36 for video that < 1080P, 40 for video that >=1080P", false, 20, cmdline::range(1, 63)); @@ -50,6 +51,7 @@ false, 20, cmdline::range(1, 63)); std::string input = opt.get("input"); std::string output = opt.get("output"); int passes = opt.get("passes"); + int pushColorCount = opt.get("pushColorCount"); double strengthColor = opt.get("strengthColor"); double strengthGradient = opt.get("strengthGradient"); double zoomFactor = opt.get("zoomFactor"); @@ -63,6 +65,7 @@ false, 20, cmdline::range(1, 63)); //Anime4K Anime4K anime4k( passes, + pushColorCount, strengthColor, strengthGradient, zoomFactor, diff --git a/README.md b/README.md index 5aa5fa2b..68399be1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is an implementation of Anime4K in C++. It based on the [bloc97's Anime4K](https://github.com/bloc97/Anime4K) algorithm version 0.9 and some optimizations have been made, it can process both image and video. This project is for learning and the exploration task of algorithm course in SWJTU. -***NOTICE: Thanks for the high performance of pointer, the C++ version will be very fast. It is about 6.5 times faster than [Go version](https://github.com/TianZerL/Anime4KGo), and 650 times faster than [Python version](https://github.com/TianZerL/Anime4KPython), but please understand, this is executed in CPU, for video preprocessing, it will take a while. Therefore, if your graphic card is good enough, I recommend you to use the real-time process version by [bloc97](https://github.com/bloc97/Anime4K), if your CPU is powerful or you want higher quality, just try this.*** +***NOTICE: Thanks for the high performance of pointer and parallel, the C++ version will be very fast. It is about 12 times faster than [Go version](https://github.com/TianZerL/Anime4KGo), and 1300 times faster than [Python version](https://github.com/TianZerL/Anime4KPython), just try this for higher quality and speed.*** # pyanime4k [pyanime4k](https://github.com/TianZerL/pyanime4k) is a simply package to use anime4k in python, easy, fast and powerful, which support both image and video processing, based on Anime4KCPP. @@ -24,6 +24,7 @@ This project uses [cmake](https://cmake.org) to build. -i, --input File for loading (string [=./pic/p1.png]) -o, --output File for outputting (string [=output.png]) -p, --passes Passes for processing (int [=2]) + -n, --pushColorCount Limit the number of color pushes (int [=2]) -c, --strengthColor Strength for pushing color,range 0 to 1,higher for thinner (double [=0.3]) -g, --strengthGradient Strength for pushing gradient,range 0 to 1,higher for sharper (double [=1]) -z, --zoomFactor zoom factor for resizing (double [=2]) @@ -32,7 +33,7 @@ This project uses [cmake](https://cmake.org) to build. -v, --videoMode Video process -s, --preview Preview image -a, --postProcessing Enable post processing - -e, --filters Enhancement filter, only working when postProcessing is true,there are 5 options by binary:Median blur=000001, Mean blur=000010, Gaussian blur weak=000100, Gaussian blur=001000, Bilateral filter=010000, Bilateral filter faster=100000, you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 & 010000 = 010100 = 20(D), so you can put 20 to enable Gaussian blur weak and Bilateral filter, which also is what I recommend for image that < 1080P, 24 for image that >= 1080P, and for performance I recommend to use 36 for video that < 1080P, 40 for video that >=1080P (unsigned int [=20]) + -e, --filters Enhancement filter, only working when postProcessing is true,there are 5 options by binary:Median blur=000001, Mean blur=000010, Gaussian blur weak=000100, Gaussian blur=001000, Bilateral filter=010000, Bilateral filter faster=100000, you can freely combine them, eg: Gaussian blur weak + Bilateral filter = 000100 | 010000 = 010100 = 20(D), so you can put 20 to enable Gaussian blur weak and Bilateral filter, which also is what I recommend for image that < 1080P, 24 for image that >= 1080P, and for performance I recommend to use 36 for video that < 1080P, 40 for video that >=1080P (unsigned int [=20]) -?, --help print this message # Filters @@ -46,7 +47,7 @@ Enable filters can make the result like better, now Anime4kCPP support 5 filters - Bilateral filter faster [100000] You can freely combine them by their binary. -eg: Gaussian blur weak + Bilateral filter = 000100 & 010000 = 010100(B)= 20(D) +eg: Gaussian blur weak + Bilateral filter = 000100 | 010000 = 010100(B)= 20(D) Easily use ```-a``` to enable filters function, and then use ```-e``` to custom your own combination, normally, if you don't specify the ```-e``` manually it will be 20. You can use command like this to enable Gaussian blur and Bilateral filter: