ImshowOverSocket/imshow/client.py
2019-12-28 16:26:19 +08:00

42 lines
1.0 KiB
Python

import cv2
import socket
from imshow import wrap
from imshow import network
from imshow import parallel
from imshow import config
token = config.token
host = '192.168.123.222'
port = 12345
class ImageClient():
def __init__(self, host, port, token):
self.host = host
self.port = port
self.token = token
self.sock = network.SocketConnection(parallel.daemon)
self.sock.connect(self.host, self.port)
self.sock.auth(self.token)
self.log = self.sock.log
def imshow(self, name, img, waitKey=0):
self.log('Sending Image {0} to host {1}:{2}'.format(name, host, port))
img = wrap.ImageMessage(img=img, name=name, wait=waitKey)
self.sock.send(img.tobytes())
exit = False
self.log('Waiting for host message to exit.')
while not exit:
msg = self.sock.recv()
if msg.decode('utf-8') == 'continue':
exit = True
client = ImageClient(host, port, token)
if __name__ == '__main__':
img1 = cv2.imread('./img/1.jpg')
img2 = cv2.imread('./img/2.jpg')
while True:
client.imshow('Name', img1, waitKey=1)
client.imshow('Name', img2, waitKey=1)