mirror of
https://github.com/NanjingForestryUniversity/supermachine-tobacco.git
synced 2025-11-08 14:23:55 +00:00
Merge remote-tracking branch 'originn/master'
This commit is contained in:
commit
a803b1c905
9
main.py
9
main.py
@ -63,7 +63,6 @@ def main(only_spec=False, only_color=False, if_merge=False, interval_time=None,
|
|||||||
try:
|
try:
|
||||||
img_data = np.frombuffer(data_total, dtype=np.float32).reshape((Config.nRows, Config.nBands, -1)) \
|
img_data = np.frombuffer(data_total, dtype=np.float32).reshape((Config.nRows, Config.nBands, -1)) \
|
||||||
.transpose(0, 2, 1)
|
.transpose(0, 2, 1)
|
||||||
print(f"get image_shape {img_data.shape}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'毁灭性错误!收到的光谱数据长度为{len(data_total)}无法转化成指定的形状 {e}')
|
logging.error(f'毁灭性错误!收到的光谱数据长度为{len(data_total)}无法转化成指定的形状 {e}')
|
||||||
|
|
||||||
@ -85,7 +84,6 @@ def main(only_spec=False, only_color=False, if_merge=False, interval_time=None,
|
|||||||
os.close(fd_rgb)
|
os.close(fd_rgb)
|
||||||
try:
|
try:
|
||||||
rgb_data = np.frombuffer(rgb_data_total, dtype=np.uint8).reshape((Config.nRgbRows, Config.nRgbCols, -1))
|
rgb_data = np.frombuffer(rgb_data_total, dtype=np.uint8).reshape((Config.nRgbRows, Config.nRgbCols, -1))
|
||||||
print(f"get rgb_data shape {rgb_data.shape}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'毁灭性错误!收到的rgb数据长度为{len(rgb_data_total)}无法转化成指定形状 {e}')
|
logging.error(f'毁灭性错误!收到的rgb数据长度为{len(rgb_data_total)}无法转化成指定形状 {e}')
|
||||||
|
|
||||||
@ -93,17 +91,12 @@ def main(only_spec=False, only_color=False, if_merge=False, interval_time=None,
|
|||||||
since = time.time()
|
since = time.time()
|
||||||
# predict
|
# predict
|
||||||
if single_spec or single_color:
|
if single_spec or single_color:
|
||||||
print('start predict')
|
|
||||||
if single_spec:
|
if single_spec:
|
||||||
print('spec predict', img_data.shape)
|
|
||||||
mask_spec = spec_detector.predict(img_data).astype(np.uint8)
|
mask_spec = spec_detector.predict(img_data).astype(np.uint8)
|
||||||
masks = [mask_spec, ]
|
masks = [mask_spec, ]
|
||||||
print('spectral mask shape:', masks[0].shape)
|
|
||||||
else:
|
else:
|
||||||
print('rgb predict', rgb_data.shape)
|
|
||||||
mask_rgb = rgb_detector.predict(rgb_data).astype(np.uint8)
|
mask_rgb = rgb_detector.predict(rgb_data).astype(np.uint8)
|
||||||
masks = [mask_rgb, ]
|
masks = [mask_rgb, ]
|
||||||
print("rgb mask shape: ", masks[0].shape)
|
|
||||||
else:
|
else:
|
||||||
if only_spec:
|
if only_spec:
|
||||||
# 光谱识别
|
# 光谱识别
|
||||||
@ -140,10 +133,8 @@ def main(only_spec=False, only_color=False, if_merge=False, interval_time=None,
|
|||||||
else:
|
else:
|
||||||
output_fifos = [mask_fifo_path, rgb_mask_fifo_path]
|
output_fifos = [mask_fifo_path, rgb_mask_fifo_path]
|
||||||
for fifo, mask in zip(output_fifos, masks):
|
for fifo, mask in zip(output_fifos, masks):
|
||||||
print("open fifo")
|
|
||||||
fd_mask = os.open(fifo, os.O_WRONLY)
|
fd_mask = os.open(fifo, os.O_WRONLY)
|
||||||
os.write(fd_mask, mask.tobytes())
|
os.write(fd_mask, mask.tobytes())
|
||||||
print("close fifo")
|
|
||||||
os.close(fd_mask)
|
os.close(fd_mask)
|
||||||
time_spent = (time.time() - since) * 1000
|
time_spent = (time.time() - since) * 1000
|
||||||
predict_by = 'spec' if single_spec else 'rgb' if single_color else 'spec+rgb'
|
predict_by = 'spec' if single_spec else 'rgb' if single_color else 'spec+rgb'
|
||||||
|
|||||||
@ -9,8 +9,6 @@ from config import Config
|
|||||||
from models import SpecDetector, RgbDetector
|
from models import SpecDetector, RgbDetector
|
||||||
import typing
|
import typing
|
||||||
import logging
|
import logging
|
||||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s',
|
|
||||||
level=logging.WARNING)
|
|
||||||
|
|
||||||
|
|
||||||
class Transmitter(object):
|
class Transmitter(object):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user