mirror of
https://github.com/NanjingForestryUniversity/supermachine-wood.git
synced 2025-11-08 10:13:53 +00:00
修改了接收图片类型为float32,测试通过
This commit is contained in:
parent
39dc58891e
commit
a0a06d8b8d
@ -93,15 +93,17 @@ def main():
|
|||||||
if cmd == 'IM':
|
if cmd == 'IM':
|
||||||
img = cv2.imread(r"C:\Users\FEIJINTI\PycharmProjects\wood_color\data\data20220919\dark\rgb60.png")
|
img = cv2.imread(r"C:\Users\FEIJINTI\PycharmProjects\wood_color\data\data20220919\dark\rgb60.png")
|
||||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||||
|
img = np.asarray(img, dtype=np.float32)
|
||||||
width = img.shape[0]
|
width = img.shape[0]
|
||||||
height = img.shape[1]
|
height = img.shape[1]
|
||||||
length = width * height * 3 + 4 + 4
|
img_bytes = img.tobytes()
|
||||||
|
length = len(img_bytes) + 8
|
||||||
length = length.to_bytes(4, byteorder='big')
|
length = length.to_bytes(4, byteorder='big')
|
||||||
width = width.to_bytes(2, byteorder='big')
|
width = width.to_bytes(2, byteorder='big')
|
||||||
height = height.to_bytes(2, byteorder='big')
|
height = height.to_bytes(2, byteorder='big')
|
||||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + width + height
|
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + width + height
|
||||||
socket_send_1.send(send_message)
|
socket_send_1.send(send_message)
|
||||||
socket_send_1.send(img)
|
socket_send_1.send(img_bytes)
|
||||||
socket_send_1.send(b'\xff\xff\xbb')
|
socket_send_1.send(b'\xff\xff\xbb')
|
||||||
print('发送成功')
|
print('发送成功')
|
||||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||||
|
|||||||
@ -79,7 +79,7 @@ def main(is_debug=False):
|
|||||||
# socket_send.connect(('127.0.0.1', 21123))
|
# socket_send.connect(('127.0.0.1', 21123))
|
||||||
# a = b'\xaa\x00\x00\x00\x05\x20\x44\x54\x52\xff\xff\xff\xbb'
|
# a = b'\xaa\x00\x00\x00\x05\x20\x44\x54\x52\xff\xff\xff\xbb'
|
||||||
# connected_sock.send(a)
|
# connected_sock.send(a)
|
||||||
model_path = os.path.join(ROOT_DIR, "models/model_2022-09-06_13-08.p")
|
model_path = os.path.join(ROOT_DIR, r"C:\Users\FEIJINTI\PycharmProjects\wood_color\models\model_2022-09-28_13-15.p")
|
||||||
detector = WoodClass(w=4096, h=1200, n=3000, debug_mode=False)
|
detector = WoodClass(w=4096, h=1200, n=3000, debug_mode=False)
|
||||||
detector.load(path=model_path)
|
detector.load(path=model_path)
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
7
utils.py
7
utils.py
@ -138,7 +138,7 @@ def receive_sock(recv_sock: PreSocket, pre_pack: bytes = b'', time_out: float =
|
|||||||
try:
|
try:
|
||||||
data_len = int.from_bytes(temp, byteorder='big')
|
data_len = int.from_bytes(temp, byteorder='big')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'转换失败,错误代码 \n{e}, \n报文内容\n{temp}')
|
logging.error(f'转换失败,错误代码 \n{e}')
|
||||||
return b'', b''
|
return b'', b''
|
||||||
|
|
||||||
# 读取报文内容
|
# 读取报文内容
|
||||||
@ -170,7 +170,7 @@ def receive_sock(recv_sock: PreSocket, pre_pack: bytes = b'', time_out: float =
|
|||||||
if temp == b'\xff\xff\xbb':
|
if temp == b'\xff\xff\xbb':
|
||||||
return data, next_pack
|
return data, next_pack
|
||||||
else:
|
else:
|
||||||
logging.error(f"接收了一个完美的只错了校验位的报文,\n data: {data} \n next_pack:{next_pack}")
|
logging.error(f"接收了一个完美的只错了校验位的报文")
|
||||||
return b'', b''
|
return b'', b''
|
||||||
|
|
||||||
|
|
||||||
@ -196,7 +196,8 @@ def parse_protocol(data: bytes) -> (str, any):
|
|||||||
logging.error(f'长宽转换失败, 错误代码{e}, 报文内容: n_rows:{n_rows}, n_cols: {n_cols}')
|
logging.error(f'长宽转换失败, 错误代码{e}, 报文内容: n_rows:{n_rows}, n_cols: {n_cols}')
|
||||||
return '', None
|
return '', None
|
||||||
try:
|
try:
|
||||||
assert n_rows * n_cols * 3 == len(img)
|
assert n_rows * n_cols * 12 == len(img)
|
||||||
|
# 因为是float32类型 所以长度要乘12 ,如果是uint8则乘3
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
logging.error('图像指令IM转换失败,数据长度错误')
|
logging.error('图像指令IM转换失败,数据长度错误')
|
||||||
return '', None
|
return '', None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user