mirror of
https://github.com/NanjingForestryUniversity/supermachine-wood.git
synced 2025-11-08 10:13:53 +00:00
修改了float32类型的图片乱识别的bug
This commit is contained in:
parent
e8af097ec7
commit
f1cf707f6e
@ -13,6 +13,7 @@ from sklearn.cluster import KMeans
|
||||
from sklearn.linear_model import LogisticRegression
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.metrics import accuracy_score
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
from scipy.stats import binom
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
@ -22,7 +23,7 @@ sys.path.append(os.getcwd())
|
||||
from root_dir import ROOT_DIR
|
||||
import utils
|
||||
|
||||
FEATURE_INDEX = [0, 1, 2, 3, 4, 5]
|
||||
FEATURE_INDEX = [1, 2]
|
||||
|
||||
|
||||
class WoodClass(object):
|
||||
|
||||
@ -48,7 +48,7 @@ def main(is_debug=False):
|
||||
console_handler.setLevel(logging.DEBUG if is_debug else logging.WARNING)
|
||||
logging.basicConfig(format='%(asctime)s %(filename)s[line:%(lineno)d] - %(levelname)s - %(message)s',
|
||||
handlers=[file_handler, console_handler], level=logging.DEBUG)
|
||||
dual_sock = DualSock(connect_ip='192.168.2.221')
|
||||
dual_sock = DualSock(connect_ip='127.0.0.1')
|
||||
|
||||
while not dual_sock.status:
|
||||
dual_sock.reconnect()
|
||||
@ -56,6 +56,7 @@ def main(is_debug=False):
|
||||
# model_path = os.path.join(ROOT_DIR, r"models\model_2022-09-28_13-15.p")
|
||||
detector = WoodClass(w=4096, h=1200, n=3000, debug_mode=False)
|
||||
detector.load(path=model_path)
|
||||
_ = detector.predict(np.random.randint(1, 254, (1200, 4096, 3), dtype=np.uint8))
|
||||
while True:
|
||||
pack, next_pack = receive_sock(dual_sock)
|
||||
if pack == b"":
|
||||
|
||||
14
utils.py
14
utils.py
@ -201,7 +201,7 @@ bytes, bytes):
|
||||
try:
|
||||
temp += recv_sock.receive(data_len)
|
||||
except Exception as e:
|
||||
logging.error(f'接收报文内容失败, 错误代码: \n{e},\n报文内容\n{temp}')
|
||||
logging.error(f'接收报文内容失败, 错误代码: \n{e}')
|
||||
return b'', b''
|
||||
data, next_pack = temp[:data_len], temp[data_len:]
|
||||
recv_sock.set_prepack(next_pack)
|
||||
@ -216,7 +216,7 @@ bytes, bytes):
|
||||
try:
|
||||
temp += recv_sock.receive(1)
|
||||
except Exception as e:
|
||||
logging.error(f'接收报文校验失败, 错误代码: \n{e}, 报文如下: \n{temp}')
|
||||
logging.error(f'接收报文校验失败, 错误代码: \n{e}')
|
||||
return b'', b''
|
||||
if temp == b'\xff\xff\xbb':
|
||||
return data, next_pack
|
||||
@ -244,15 +244,15 @@ def parse_protocol(data: bytes) -> (str, any):
|
||||
try:
|
||||
n_rows, n_cols = [int.from_bytes(x, byteorder='big') for x in [n_rows, n_cols]]
|
||||
except Exception as e:
|
||||
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
|
||||
try:
|
||||
assert n_rows * n_cols * 12 == len(img)
|
||||
assert n_rows * n_cols * 3 == len(img)
|
||||
# 因为是float32类型 所以长度要乘12 ,如果是uint8则乘3
|
||||
except AssertionError:
|
||||
logging.error('图像指令IM转换失败,数据长度错误')
|
||||
return '', None
|
||||
img = np.frombuffer(img, dtype=np.float32).reshape((n_rows, n_cols, -1))
|
||||
img = np.frombuffer(img, dtype=np.uint8).reshape((n_rows, n_cols, -1))
|
||||
return cmd, img
|
||||
elif cmd == 'TR':
|
||||
data = data.decode('ascii')
|
||||
@ -313,11 +313,11 @@ def simple_sock(send_sock: socket.socket, cmd_type: str, result: int = '') -> bo
|
||||
cmd_type = cmd_type.strip().upper()
|
||||
if cmd_type == 'IM':
|
||||
if result == 0:
|
||||
msg = b'Q'
|
||||
msg = b'S'
|
||||
elif result == 1:
|
||||
msg = b'Z'
|
||||
elif result == 2:
|
||||
msg = b'S'
|
||||
msg = b'Q'
|
||||
elif cmd_type == 'TR':
|
||||
msg = b'A'
|
||||
elif cmd_type == 'MD':
|
||||
|
||||
Loading…
Reference in New Issue
Block a user