From 32010f35f00fec1e75d8f420979426dcc8792371 Mon Sep 17 00:00:00 2001 From: "li.zhenye" <李> Date: Wed, 27 Jul 2022 17:44:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=AF=BB=E5=8F=96c?= =?UTF-8?q?=E8=AF=AD=E8=A8=80buff=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- main.py | 23 +++++++++++++++++++++++ models.py | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 483c629..2e5266c 100755 --- a/config.py +++ b/config.py @@ -20,7 +20,7 @@ class Config: # 光谱模型参数 blk_size = 4 pixel_model_path = r"./models/dt.p" - blk_model_path = r"./models/rf_4x4_c22_20_sen8_8.model" + blk_model_path = r"./models/rf_4x4_c22_20_sen8_9.model" spec_size_threshold = 3 # rgb模型参数 diff --git a/main.py b/main.py index 7ac3b21..e368ea7 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,7 @@ import os import time + +import matplotlib.pyplot as plt import numpy as np import scipy.io @@ -70,6 +72,26 @@ def main(): print(f'total time is:{t3 - t1}\n') +def read_c_captures(buffer_path): + buffer_names = [buffer_name for buffer_name in os.listdir(buffer_path) if buffer_name.endswith('.raw')] + for buffer_name in buffer_names: + with open(os.path.join(buffer_path, buffer_name), 'rb') as f: + data = f.read() + img = np.frombuffer(data, dtype=np.float32).reshape((Config.nRows, Config.nBands, -1)) \ + .transpose(0, 2, 1) + mask_name = buffer_name.replace('buf', 'mask').replace('.raw', '') + with open(os.path.join(buffer_path, mask_name), 'rb') as f: + data = f.read() + mask = np.frombuffer(data, dtype=np.uint8).reshape((256, 1024, -1)) + # mask = cv2.resize(mask, (1024, 256)) + fig, axs = plt.subplots(2, 1) + axs[0].imshow(img[..., [21, 3, 0]]) + axs[0].set_title(buffer_name) + axs[1].imshow(mask) + axs[1].set_title(mask_name) + plt.show() + + if __name__ == '__main__': # 相关参数 img_fifo_path = "/tmp/dkimg.fifo" @@ -78,3 +100,4 @@ if __name__ == '__main__': # 主函数 main() + # read_c_captures('/home/lzy/2022.7.20/tobacco_v1_0/') diff --git a/models.py b/models.py index 95d7f4a..181651d 100755 --- a/models.py +++ b/models.py @@ -415,7 +415,7 @@ class SpecDetector(Detector): # 烟梗mask中将背景赋值为0,将烟梗赋值为2 yellow_things[yellow_things] = tobacco yellow_things = yellow_things + 0 - # yellow_things = binary_dilation(yellow_things, iterations=iteration) + yellow_things = binary_dilation(yellow_things, iterations=iteration) yellow_things = yellow_things + 0 yellow_things[yellow_things == 1] = 2