RockmanYang/vocal_remover
3
1import os2 3import cv24import numpy as np5 6 7def imread(filename, flags=cv2.IMREAD_COLOR, dtype=np.uint8):8 try:9 n = np.fromfile(filename, dtype)10 img = cv2.imdecode(n, flags)11 return img12 except Exception as e:13 print(e)14 return None15 16 17def imwrite(filename, img, params=None):18 try:19 ext = os.path.splitext(filename)[1]20 result, n = cv2.imencode(ext, img, params)21 22 if result:23 with open(filename, mode='w+b') as f:24 n.tofile(f)25 return True26 else:27 return False28 except Exception as e:29 print(e)30 return False31 