# import cv2 # import socket # import io # import struct # # Define connection details (replace with your actual values) # HOST = '144.126.254.143' # IP address of the receiving device # PORT = 5555 # Port number for communication # # Create a socket connection # connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # connection.connect((HOST, PORT)) # print("Starting camera using OpenCV...") # # Initialize video capture using OpenCV # cap = cv2.VideoCapture(0) # Change 0 to the video source index if needed # while True: # # Capture frame-by-frame # ret, frame = cap.read() # # Check if frame capture is successful # if not ret: # print("Error: Frame not captured") # break # # Encode frame as JPEG # _, jpeg_buffer = cv2.imencode('.jpg', frame) # # Create a stream-like object from the JPEG buffer # stream = io.BytesIO(jpeg_buffer.tobytes()) # # Get the stream's current position (similar to stream.tell()) # stream_length = stream.tell() # # Send frame size (4 bytes) in little-endian format # connection.sendall(struct.pack('