Skip to content

Instantly share code, notes, and snippets.

@Kinetic27
Created November 11, 2025 04:02
Show Gist options
  • Select an option

  • Save Kinetic27/7ff5bc8f06ac5ce855e70f05ebefb74b to your computer and use it in GitHub Desktop.

Select an option

Save Kinetic27/7ff5bc8f06ac5ce855e70f05ebefb74b to your computer and use it in GitHub Desktop.
import cv2
import zmq
# from djitellopy import Tello
# tello gogo
import time
SERVER_IP = "cam.uhmcv.kro.kr"
PORT = 5000
print("create ZMQ")
context = zmq.Context()
socket = context.socket(zmq.PUSH)
socket.connect(f"tcp://{SERVER_IP}:{PORT}")
print(f"try to connect {SERVER_IP}:{PORT}")
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("error: cannot open webcam")
exit()
# cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
# cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
try:
while True:
ret, frame = cap.read()
if not ret or frame is None:
print("error reading frame from webcam")
continue
ret_encode, buffer = cv2.imencode(".jpg", frame, [cv2.IMWRITE_JPEG_QUALITY, 80])
if not ret_encode:
print("encode error")
continue
socket.send(buffer)
# cv2.imshow("Webcam Stream - Laptop", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
time.sleep(0.01)
except KeyboardInterrupt:
print("stop service")
finally:
cap.release()
socket.close()
context.term()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment