Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- import os
- def cv2_imread(filename, mode=-1):
- # 0:gray
- # 1:rgb
- # -1 any, read as the mode of source itself.
- # like cv2.imread
- cv_img = cv2.imdecode(np.fromfile(filename, dtype=np.uint8), mode)
- return cv_img
- def cv2_imwrite(filename, img, suffix=None):
- # like cv2.imwrite
- if suffix is None:
- suffix = os.path.splitext(filename)[-1]
- if suffix == '':
- suffix = '.png'
- cv2.imencode(suffix, img)[1].tofile(filename)
Add Comment
Please, Sign In to add comment