Guest User

Untitled

a guest
Jan 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3. import os
  4.  
  5. def cv2_imread(filename, mode=-1):
  6. # 0:gray
  7. # 1:rgb
  8. # -1 any, read as the mode of source itself.
  9. # like cv2.imread
  10. cv_img = cv2.imdecode(np.fromfile(filename, dtype=np.uint8), mode)
  11. return cv_img
  12.  
  13. def cv2_imwrite(filename, img, suffix=None):
  14. # like cv2.imwrite
  15. if suffix is None:
  16. suffix = os.path.splitext(filename)[-1]
  17. if suffix == '':
  18. suffix = '.png'
  19. cv2.imencode(suffix, img)[1].tofile(filename)
Add Comment
Please, Sign In to add comment