Created
June 3, 2019 05:17
-
-
Save robobe/373c7b9dbcff762d909c01ef90882f29 to your computer and use it in GitHub Desktop.
simple opoencv tcp socket client read camera and send image as jpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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