Last active
August 17, 2022 21:15
-
-
Save Nathaniel-Wu/5274fbe808486ab9a83b742112a87294 to your computer and use it in GitHub Desktop.
Build waifu2x on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# before running the script, make sure OpenCV has been installed through Homebrew | |
git clone https://github.com/DeadSix27/waifu2x-converter-cpp.git && cd waifu2x-converter-cpp | |
# caveat: libw2xc.dylib will be referenced by the executable using the build path, so you may want to copy the repo somewhere you eventually want the binaries to be | |
# latest working release is 5.3.4 (27ad20e6a2007d0415a7a1d7fc957e81395ab06b) | |
git checkout 27ad20e6a2007d0415a7a1d7fc957e81395ab06b | |
# create some temporary symbolic links, otherwise cmake and make will not find the files | |
ln -sf "${HOMEBREW_PREFIX}/opt/opencv/include/opencv4/opencv2" "${HOMEBREW_PREFIX}/opt/opencv/include/opencv2" | |
# run the next four lines only if you haven't installed LLVM through Homebrew | |
mkdir -p "${HOMEBREW_PREFIX}/opt/llvm/bin" | |
ln -sf "${HOMEBREW_PREFIX}/lib" "${HOMEBREW_PREFIX}/opt/llvm" | |
ln -sf /usr/bin/clang "${HOMEBREW_PREFIX}/opt/llvm/bin" | |
ln -sf /usr/bin/clang++ "${HOMEBREW_PREFIX}/opt/llvm/bin" | |
# cmake | |
cmake -DOVERRIDE_OPENCV=1 -DOPENCV_PREFIX="${HOMEBREW_PREFIX}/opt/opencv" . | |
# copying the models to ${HOMEBREW_PREFIX}/share | |
cp -r models_rgb "${HOMEBREW_PREFIX}/share/waifu2x-converter-cpp" | |
# namespace difference in Apple clang | |
sed -iE 's/std::filesystem/std::__fs::filesystem/g' src/modelHandler_OpenCL.cpp | |
# make the binary | |
make -j16 | |
# if you don't want to keep the temporary symbolic links created earlier | |
rm -f "${HOMEBREW_PREFIX}/opt/opencv/include/opencv2" | |
# run the next line only if you haven't installed LLVM through Homebrew | |
rm -rf "${HOMEBREW_PREFIX}/opt/llvm" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment