31 July 2017

How to build waifu2x command-line version on osx

UPDATE 23/10/2017: recent changes seem to be incompatible with clang. I have updated the steps below to check out the last commit that is known as working.
Waifu2x is a popular image converter backed by neural-network models, typically used to upscale images from anime. The various web versions are easy to use but typically don't allow for batch-processing, because it's a relatively intensive operation. However, there is a command-line version that is fairly easy to compile on Windows and Linux. OSX support was notably absent... until now.
These are the steps required to get it working on Mac:
  1. brew tap science && brew install opencv3
    (if you don't have Homebrew, go install it now - it's wonderful)
  2. git clone https://github.com/DeadSix27/waifu2x-converter-cpp.git
  3. cd waifu2x-converter-cpp
  4. git checkout d69313040b0784662465fb1d2eca81a2b1ebccb2
  5. cmake -DOVERRIDE_OPENCV=1 -DOPENCV_PREFIX=/usr/local/Cellar/opencv3/<your version here> . (remember the dot at the end!)
  6. make -j4
At this point, you have the executable waifu2x-converter-cpp in the directory; you can make install if you really want to (I prefer to keep custom stuff in my home dir). To test it's working, the following command should return info on your system:

./waifu2x-converter-cpp --list-processor

If you need some images to test, here you can get quite a few stills from the gorgeous 5 Centimeters Per Second. Note: you might have to rename the folder "models_rgb" into "models" before converting.

BONUS: Qt GUI

If you hate the command-line, there is a simple QT wrapper. To compile it you will need Qt-Creator and Qt installed and configured. This used to be very complicated, but both items have now been packaged for Homebrew so it's all awesomely simple (well, compared to what it was, at least). Note that you still have to do the steps above - the wrapper needs the waifu2x executable to be already compiled.

Install and configure Qt and Qt-Creator

  1. brew install qt && brew cask install qt-creator
  2. Launch Qt Creator from Launchpad, then go to Qt Creator -> Preferences (Command + ,)
  3. Select Build & Run, then the Qt Versions tab
  4. Click on Add... and select “Macintosh HD”
  5. Press Command + Shift + . to show hidden directories
  6. select /usr/local/Cellar/qt5/<your version>/bin/qmake then OK and OK again to close the Preferences window
  7. Reopen Preferences -> Build & Run, select the Kits tab and click Add
  8. Set the following options:
    • Name to something like "Qt CLang Desktop" 
    • Both Compiler options to Clang X86 64bit
    • Qt Version to the version you just created
    • Click on Make Default then OK to close Preferences.

Compile waifu2x-converter-qt

  1. git clone https://github.com/toyg/waifu2x-converter-qt.git (the original repo looks abandoned, so I forked it and tweaked it a bit)
  2. cd waifu-converter-qt && open waifu2x-converter-qt.pro (this should open Qt Creator; if it doesn't, launch it manually and File -> Open Project -> select the .pro file).
  3. Select Build -> Run (or Command + R). The resulting .app bundle should now be in a folder called build-waifu2x-converter-qt-<something something>, just beside your main project folder.
When you first launch the GUI, you should probably go to Preferences and set the path to your waifu2x-converter-cpp executable.

2 comments:

Anonymous said...

I finally got it working, thanks for the article.
Somehow the latest code (10/21/2017) can't build smoothly, had to fix some include problems, but still, it can't be build with clang, had to switch to gcc; then linking became a problem, seemed to be binary incompatible with clang built opencv; tried to compile opencv with gcc, but failed; in the end, I reset to 07/31/2017 version, which finally worked out…

Giacomo Lacava said...

Indeed, recent changes seem to be incompatible with clang; there is an open issue omn github, but at the moment we can't find a solution. The last commit that works for me is d69313040b0784662465fb1d2eca81a2b1ebccb2. I'll update the post.