-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageFromFiles.py
More file actions
59 lines (49 loc) · 1.62 KB
/
Copy pathImageFromFiles.py
File metadata and controls
59 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import socket
import threading
import time
from dataclasses import dataclass
from queue import Queue
import cv2
import numpy as np
@dataclass
class ImageInfo:
size: int
width: int
height: int
channels: int
@dataclass
class Image:
width: int
height: int
channels: int
data_type: np.dtype
data: bytearray
class ImageFromFiles:
def __init__(self, path: str, queue):
self.queue = queue
def start(self):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((self.host, self.port))
print("Connected to server")
# keep the tcp listener up if the client diesconnects
size = 128
# all_data = []
received_data = 0
while True:
data = s.recv(size)
received_data += len(data)
print(received_data)
# all_data.append(data)
# if received_data == 244 * 324 * 2:
# print("received image")
# image = np.frombuffer(b"".join(all_data), dtype=np.uint8)
# image = np.reshape(image, (244, 324, 2))
# image = np.hstack((image[:, :, 0], image[:, :, 1]))
# self.queue.put(image)
# all_data = []
# received_data = 0
# if data:
# image = np.frombuffer(data, dtype=np.uint8)
# image = np.reshape(image, (244, 324, 2))
# image = np.hstack((image[:, :, 0], image[:, :, 1]))
# self.queue.put(image)