Skip to content

Instantly share code, notes, and snippets.

@satomacoto
Last active April 25, 2019 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satomacoto/452e3df5b0886d6d1295a2e9b78ba054 to your computer and use it in GitHub Desktop.
Save satomacoto/452e3df5b0886d6d1295a2e9b78ba054 to your computer and use it in GitHub Desktop.
import base64
import cv2
from PIL import Image
cap = cv2.VideoCapture(0)
_, img = cap.read()
image_string = cv2.imencode(".png", img)[1].tostring()
output = io.BytesIO()
Image.fromarray(img).save(output, format='PNG')
buf = output.getvalue()
b64 = base64.b64encode(buf)
import requests
from PIL import Image
from io import BytesIO
import numpy as np
res = requests.get(image_url)
image = Image.open(BytesIO(res.content))
image_array = np.array(image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment