diff --git a/python/opencv_client.py b/python/opencv_client.py new file mode 100644 index 0000000000000000000000000000000000000000..18026844db75fb47de789e4a0242a1617b071c06 --- /dev/null +++ b/python/opencv_client.py @@ -0,0 +1,24 @@ +import cv2 +import numpy + +from blc_network import BlcArrayTCP4Client +client=BlcArrayTCP4Client("localhost", "31440") + +#these informations has been sent by the server +height = client.dims[0] +width = client.dims[1] +deep = client.dims[2] + +print(height,"x",width,"x",deep, cleint.type, client.format) + +#We create an numpy array (equivalent to cv:Mat in C++ ) associated with the data of the client +client_array = numpy.ndarray([height, width, deep], dtype=numpy.uint8, buffer=client.data, offset=0, strides=None, order='C') + +while(True): + client.recv_data() + #We even do not need a copy as the numpy array directly links to the data + cv2.imshow('client', client_array) + cv2.waitKey(1) + + + diff --git a/python/opencv_server.py b/python/opencv_server.py new file mode 100644 index 0000000000000000000000000000000000000000..3734f52ad70f8b74de3d9acbff8f5e2814687842 --- /dev/null +++ b/python/opencv_server.py @@ -0,0 +1,25 @@ +import cv2 +import numpy +from blc_network import BlcArrayTCP4Server + +vid = cv2.VideoCapture(0) +height = int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)) +width = int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)) +deep=3 # 1 if it is in gray + +print(height,"x", width) + +server=BlcArrayTCP4Server("31440", 'UIN8', 'RGB3', [height, width, 3]) +print("Wait client") +server.wait_connection() + +#We create an numpy array (equivalent to cv:Mat in C++ ) associated with the data of server +server_array = numpy.ndarray([height, width, 3], dtype=numpy.uint8, buffer=server.data, offset=0, strides=None, order='C') + +while(True): + ret, img = vid.read() + #we copy the pixels of the image to the array of the server (i.e. the buffer: server.data) + numpy.copyto(server_array, img) + server.send_data() + cv2.imshow('server', server_array) + cv2.waitKey(1)