Package: pyanime4k
PyAnime4KPyAnime4K is a simple, fast and powerful Anime4K Python implementation.InstallationPipPyAnime4K can be installed easily throughpip.(recommended for Windows)pipinstallpyanime4kShell scriptFor Ubuntu you can also usesetup_wheel_ubuntu.shto build wheel file and install it (especially recommended for Google Colab):# For Google Colab, you need to add "!" at the beginning
# "setup_wheel_ubuntu.sh" need root permission for installing dependency library by apt
wget https://github.com/TianZerL/pyanime4k/raw/master/setup_wheel_ubuntu.sh && chmod 777 setup_wheel_ubuntu.sh && ./setup_wheel_ubuntu.shManual installationCompile Anime4KCPP for pyanime4kCloneAnime4KCPPFollowthis, and for pyanime4k, only core and c wrapper is needed.  Make sure CMake optionBuild_C_wrapperis turned on, and if you want to build core and c wrapper in one file, turned onBuild_C_wrapper_with_core(recommend)install pyanime4kClone the repoDownload from release or compile the Anime4KCPP core and Anime4KCPP C Wrapper.Copyac.dllandAnime4KCPPCore.dll(if turned off Build_C_wrapper_with_core option of Anime4KCPP in CMake) andopencv_world440.dllto the pyanime4k/wrapper (Windows)Copylibac.soto the pyanime4k/wrapper (Linux)Copylibac.dylibto the pyanime4k/wrapper (macOS)EnjoyUsagesUpscaling Images# pathlib.Path path objects are recommended instead of stringsimportpathlib# import pyanime4k libraryimportpyanime4k# display single image upscaled with Anime4KCPPpyanime4k.show_upscaled_image(pathlib.Path('image1.png'))# upscale a single imagepyanime4k.upscale_images(pathlib.Path('image1.png'))# upscale a list of imagesimages=[pathlib.Path('image1.png'),pathlib.Path('image2.png')]pyanime4k.upscale_images(input_paths=images,output_path=pathlib.Path('./output'))Upscaling Videos# pathlib.Path path objects are recommended instead of stringsimportpathlib# import pyanime4k libraryimportpyanime4k# upscale a single video filepyanime4k.upscale_videos(pathlib.Path('video1.mp4'))# upscale multiple filesvideos=[pathlib.Path('video1.mp4'),pathlib.Path('video2.mp4')]pyanime4k.upscale_videos(input_paths=videos,output_path=pathlib.Path('./output'))Preview a video with OpenCVfrompyanime4kimportacimportcv2video=cv2.VideoCapture(r"F:\Temp\Anime4K\P1-1.m4v")a=ac.AC(managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0,dID=0)]),type=ac.ProcessorType.OpenCL_ACNet)whileTrue:v,f=video.read()ifnotv:break# the default color format of OpenCV is BGRf=a.proccess_image_with_numpy(f)cv2.imshow("video",f)cv2.waitKey(1)Specify GPUYou can specify GPU for processing if you have more than one GPUfrompyanime4kimportac# print GPU list to get pID and dID of each GPUac.AC.list_GPUs()# check GPU supportflag,info=ac.AC.check_GPU_support(GPGPU=ac.GPGPUModel.AC_OpenCL,pID=1,dID=0)# init AC core with pID and dIDifflag:a=ac.AC(managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0,dID=0)]),type=ac.ProcessorType.OpenCL_ACNet)# print GPU informationprint(info)# or to check the current processor informationprint(a.get_processor_info())Manual UpscalingYou may also create a low-level AC object and handle each of the steps manually.frompyanime4kimportacimportpyanime4kparameters=ac.Parameters()# enable HDN for ACNetparameters.HDN=Truea=ac.AC(managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0,dID=0)]),type=ac.ProcessorType.OpenCL_ACNet)# load image from filea.load_image(r"D:\Temp\anime4k\p1.png")# start processinga.process()# preview upscaled imagea.show_image()# save image to filea.save_image('image1_output.png')# from PIL and numpyimportnumpyasnpfromPILimportImageimg=Image.open(r"D:\Temp\anime4k\p1.png").convert("RGB")img=np.array(img)# BGR, RGB and YUV444 is supporteda.load_image_from_numpy(img,input_type=ac.AC_INPUT_RGB)# start processinga.process()# save image to numpy arraynew_img=a.save_image_to_numpy()new_img=Image.fromarray(new_img)new_img.show()# from OpenCVimportcv2img=cv2.imread(r"D:\Temp\anime4k\p1.png")a.load_image_from_numpy(img,input_type=ac.AC_INPUT_BGR)a.process()img=a.save_image_to_numpy()cv2.imshow("opencv",img)cv2.waitKey(0)# save image to filea.save_image('image1_output_1.png')# let's process videoa.set_video_mode(True)# load video filea.load_video(r"D:\Temp\anime4k\P1-1.m4v")# specify output video file name# note that this needs to be done before processing startsa.set_save_video_info("output_tmp.mp4",codec=ac.Codec.MP4V)# start processing with progressa.process_with_progress()# process with callback functiondefprint_progress_time(v,t):print("%.2f%%elapsed:%.2fremaining:%.2f"%(v*100,t,t/v-t),end="\r")'''#ordef print_progress(v):print("%.2f%%" % (v * 100), end="\r")'''# load video filea.load_video(r"D:\Temp\anime4k\P1-1.m4v")# specify output video file name# note that this needs to be done before processing startsa.set_save_video_info("output_tmp_.mp4",codec=ac.Codec.MP4V)# start processing with progress value and time callbacka.process_with_progress_time_callback(print_progress_time)'''#or# start processing with progress value callbacka.process_with_progress_callback(print_progress)'''# save video to filea.save_video()# merge audio and auto delete tmp filepyanime4k.migrate_audio_streams("output_tmp.mp4",r"D:\Temp\anime4k\P1-1.m4v","output.mp4")Process a video with OpenCVfrompyanime4kimportacimportcv2importtimeimportthreadingimportqueue# init VideoCapture and VideoWritervideoReader=cv2.VideoCapture(r"D:\Temp\anime4k\P1-1.m4v")fps=videoReader.get(cv2.CAP_PROP_FPS)h=videoReader.get(cv2.CAP_PROP_FRAME_HEIGHT)w=videoReader.get(cv2.CAP_PROP_FRAME_WIDTH)videoWriter=cv2.VideoWriter("output.mp4",cv2.VideoWriter_fourcc("m","p","4","v"),fps,(int(w*2),int(h*2)),)# init Anime4KCPPa=ac.AC(managerList=ac.ManagerList([ac.OpenCLACNetManager(pID=0,dID=0)]),type=ac.ProcessorType.OpenCL_ACNet)# frame queueq=queue.Queue(12)# write frames to diskdefwriteFrames():whileTrue:f=q.get()videoWriter.write(f)q.task_done()# write frames in new threadt=threading.Thread(target=writeFrames,daemon=True)t.start()s=time.time()whileTrue:v,f=videoReader.read()ifnotv:breakf=a.proccess_image_with_numpy(f)q.put(f)e=time.time()print("time:",e-s,"s")# wait for finishedq.join()videoWriter.release()Other Anime4K ImplementationsGoTianZerL/Anime4KGoC++TianZerL/Anime4KCPPC#shadow578/Anime4kSharpnet2cn/Anime4KSharpGLSLbloc97/Anime4KRustandraantariksa/Anime4K-rs