a guest Jun 25th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def img_encode(img, format=".jpg"):
  2.     new_img = img.convert('RGB')
  3.     cv2_img = cv2.cvtColor(numpy.array(new_img), cv2.COLOR_RGB2BGR)
  4.     r, b = cv2.imencode(format, cv2_img)
  5.     if not r:
  6.         raise Exception("unable to encode image")
  7.     return b.tobytes()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand