Skip to content

Instantly share code, notes, and snippets.

@jangsoopark
Created November 13, 2019 06:50
Show Gist options
  • Save jangsoopark/56a56c030a86ea2266da1dda08853429 to your computer and use it in GitHub Desktop.
Save jangsoopark/56a56c030a86ea2266da1dda08853429 to your computer and use it in GitHub Desktop.
from io import BytesIO
import cv2
cap = cv2.VideoCapture('rtsp://admin:1234@192.168.21.152:554/video1')
ret, frame = cap.read()
success, encoded_frame = cv2.imencode('.jpg', frame)
cv2_bytes_frame = BytesIO(encoded_frame)
from PIL import Image
pil_bytes_frame = BytesIO()
Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).save(pil_bytes_frame, 'jpeg')
Image.open(cv2_bytes_frame).show()
Image.open(pil_bytes_frame).show()
cap.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment