Skip to content

Instantly share code, notes, and snippets.

@robobe
Created June 3, 2019 05:17
Show Gist options
  • Save robobe/373c7b9dbcff762d909c01ef90882f29 to your computer and use it in GitHub Desktop.
Save robobe/373c7b9dbcff762d909c01ef90882f29 to your computer and use it in GitHub Desktop.
simple opoencv tcp socket client read camera and send image as jpeg
import socket
import time
import struct
import cv2
capture = cv2.VideoCapture(0)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.0.0.1', 5005))
while True:
ret, frame = capture.read()
data = cv2.imencode('.jpg', frame)[1].tostring()
length = struct.pack("!I", len(data))
sock.send(length)
sock.send(data)
sock.close()
capture.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment