mirror of
https://github.com/NanjingForestryUniversity/supermachine-tobacco.git
synced 2025-11-08 14:23:55 +00:00
Two masks split version.
This commit is contained in:
parent
081b4e050f
commit
d29d465c7c
@ -29,3 +29,6 @@ class Config:
|
|||||||
threshold_low, threshold_high = 10, 230
|
threshold_low, threshold_high = 10, 230
|
||||||
threshold_s = 175
|
threshold_s = 175
|
||||||
rgb_size_threshold = 4
|
rgb_size_threshold = 4
|
||||||
|
|
||||||
|
# Mask parameter
|
||||||
|
target_size = (1024, 1024) # (Width, Height) of mask
|
||||||
|
|||||||
@ -23,7 +23,8 @@ class EfficientUI(object):
|
|||||||
spec_receiver = transmit.FifoReceiver(fifo_path=img_fifo_path, output=spec_img_queue, read_max_num=spec_len)
|
spec_receiver = transmit.FifoReceiver(fifo_path=img_fifo_path, output=spec_img_queue, read_max_num=spec_len)
|
||||||
rgb_receiver = transmit.FifoReceiver(fifo_path=rgb_fifo_path, output=rgb_img_queue, read_max_num=rgb_len)
|
rgb_receiver = transmit.FifoReceiver(fifo_path=rgb_fifo_path, output=rgb_img_queue, read_max_num=rgb_len)
|
||||||
# 指令执行与图像流向控制
|
# 指令执行与图像流向控制
|
||||||
subscribers = {'detector': detector_queue, 'visualize': self.visual_queue, 'save': save_queue}
|
# subscribers = {'detector': detector_queue, 'visualize': self.visual_queue, 'save': save_queue}
|
||||||
|
subscribers = {"detector": detector_queue}
|
||||||
cmd_img_controller = transmit.CmdImgSplitMidware(rgb_queue=rgb_img_queue, spec_queue=spec_img_queue,
|
cmd_img_controller = transmit.CmdImgSplitMidware(rgb_queue=rgb_img_queue, spec_queue=spec_img_queue,
|
||||||
subscribers=subscribers)
|
subscribers=subscribers)
|
||||||
# 探测器
|
# 探测器
|
||||||
|
|||||||
29
main.py
29
main.py
@ -21,10 +21,12 @@ def main():
|
|||||||
total_rgb = Config.nRgbRows * Config.nRgbCols * Config.nRgbBands * 1 # int型变量
|
total_rgb = Config.nRgbRows * Config.nRgbCols * Config.nRgbBands * 1 # int型变量
|
||||||
if not os.access(img_fifo_path, os.F_OK):
|
if not os.access(img_fifo_path, os.F_OK):
|
||||||
os.mkfifo(img_fifo_path, 0o777)
|
os.mkfifo(img_fifo_path, 0o777)
|
||||||
if not os.access(mask_fifo_path, os.F_OK):
|
|
||||||
os.mkfifo(mask_fifo_path, 0o777)
|
|
||||||
if not os.access(rgb_fifo_path, os.F_OK):
|
if not os.access(rgb_fifo_path, os.F_OK):
|
||||||
os.mkfifo(rgb_fifo_path, 0o777)
|
os.mkfifo(rgb_fifo_path, 0o777)
|
||||||
|
if not os.access(mask_fifo_path, os.F_OK):
|
||||||
|
os.mkfifo(mask_fifo_path, 0o777)
|
||||||
|
if not os.access(rgb_mask_fifo_path, os.F_OK):
|
||||||
|
os.mkfifo(rgb_mask_fifo_path, 0o777)
|
||||||
while True:
|
while True:
|
||||||
fd_img = os.open(img_fifo_path, os.O_RDONLY)
|
fd_img = os.open(img_fifo_path, os.O_RDONLY)
|
||||||
fd_rgb = os.open(rgb_fifo_path, os.O_RDONLY)
|
fd_rgb = os.open(rgb_fifo_path, os.O_RDONLY)
|
||||||
@ -38,7 +40,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
data_total = data
|
data_total = data
|
||||||
os.close(fd_img)
|
os.close(fd_img)
|
||||||
|
|
||||||
# rgb data read
|
# rgb data read
|
||||||
rgb_data = os.read(fd_rgb, total_rgb)
|
rgb_data = os.read(fd_rgb, total_rgb)
|
||||||
if len(rgb_data) < 3:
|
if len(rgb_data) < 3:
|
||||||
@ -56,20 +58,20 @@ def main():
|
|||||||
.transpose(0, 2, 1)
|
.transpose(0, 2, 1)
|
||||||
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))
|
||||||
# 光谱识别
|
# 光谱识别
|
||||||
mask = spec_detector.predict(img_data)
|
mask_spec = spec_detector.predict(img_data)
|
||||||
# rgb识别
|
# rgb识别
|
||||||
mask_rgb = rgb_detector.predict(rgb_data)
|
mask_rgb = rgb_detector.predict(rgb_data)
|
||||||
# 结果合并
|
# 结果合并
|
||||||
mask_result = (mask | mask_rgb).astype(np.uint8)
|
# mask_result = (mask_spec | mask_rgb).astype(np.uint8)
|
||||||
# mask_result = mask_rgb.astype(np.uint8)
|
|
||||||
mask_result = mask_result.repeat(Config.blk_size, axis=0).repeat(Config.blk_size, axis=1).astype(np.uint8)
|
|
||||||
t2 = time.time()
|
|
||||||
print(f'rgb len = {len(rgb_data)}')
|
|
||||||
|
|
||||||
|
# control the size of the output masks
|
||||||
|
masks = [cv2.resize(mask.astype(np.uint8), Config.target_size) for mask in [mask_spec, mask_rgb]]
|
||||||
# 写出
|
# 写出
|
||||||
fd_mask = os.open(mask_fifo_path, os.O_WRONLY)
|
output_fifos = [mask_fifo_path, rgb_mask_fifo_path]
|
||||||
os.write(fd_mask, mask_result.tobytes())
|
for fifo, mask in zip(output_fifos, masks):
|
||||||
os.close(fd_mask)
|
fd_mask = os.open(fifo, os.O_WRONLY)
|
||||||
|
os.write(fd_mask, mask.tobytes())
|
||||||
|
os.close(fd_mask)
|
||||||
t3 = time.time()
|
t3 = time.time()
|
||||||
print(f'total time is:{t3 - t1}')
|
print(f'total time is:{t3 - t1}')
|
||||||
|
|
||||||
@ -77,9 +79,10 @@ def main():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# 相关参数
|
# 相关参数
|
||||||
img_fifo_path = "/tmp/dkimg.fifo"
|
img_fifo_path = "/tmp/dkimg.fifo"
|
||||||
mask_fifo_path = "/tmp/dkmask.fifo"
|
|
||||||
rgb_fifo_path = "/tmp/dkrgb.fifo"
|
rgb_fifo_path = "/tmp/dkrgb.fifo"
|
||||||
|
|
||||||
|
mask_fifo_path = "/tmp/dkmask.fifo"
|
||||||
|
rgb_mask_fifo_path = "/tmp/dkmask_rgb.fifo"
|
||||||
# 主函数
|
# 主函数
|
||||||
main()
|
main()
|
||||||
# read_c_captures('/home/lzy/2022.7.15/tobacco_v1_0/', no_mask=True, nrows=256, ncols=1024,
|
# read_c_captures('/home/lzy/2022.7.15/tobacco_v1_0/', no_mask=True, nrows=256, ncols=1024,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user