From 27c1b08365109621aec671bc41ac94aa5fa11062 Mon Sep 17 00:00:00 2001 From: flt6 <1404262047@qq.com> Date: Thu, 3 Jul 2025 22:29:31 +0800 Subject: [PATCH] final Former-commit-id: 251b57f490efdc292b0c4c019431219b75ee890c --- main.py | 26 ++++++++++++++++++-------- utils.py | 2 +- vid_chk.py | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 071f519..94b6293 100644 --- a/main.py +++ b/main.py @@ -57,7 +57,9 @@ class MAT: st = self.ch340.start if not value_only: self.ch340.stop() - assert abs(self.ch340._get_time()-1) < 1e-3 + if not abs(self.ch340._get_time()-1) < 1e-3: + self.control_logger.warning(f"CH340 timing issue detected: {self.ch340._get_time()}") + return self.total_volume r = now - st ret = self.total_volume - (1-r) * self.speeds[self.state.mode.value] if value_only: @@ -177,10 +179,17 @@ class MAT: return "colored" if dep == 1: suc,im = self.cap.read() + hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV) + + # 降低饱和度通道 (S通道是索引1) + hsv[:, :, 1] = hsv[:, :, 1] * 0.8 + + # 转换回BGR颜色空间 + result = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) name = f"colored_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg" - cv2.imwrite(name,im) + cv2.imwrite(name,result) self.colored_im = name - if dep > 5: + if dep > 3: # self.endpoint_logger.info(f"colored比例{.2%}>=70%,确认滴定终点") self.colored_volume = self.total_volume self.endpoint_logger.info(f"最终体积: {self.colored_volume:.2f} ml") @@ -248,7 +257,7 @@ class MAT: rate = val/tot if self.history.base is not None: base = self.history.base - thr = (min(0.05,base*5), min(0.4,base*13), 0.5) + thr = (min(0.05,base*5), min(0.2,base*13), 0.5) # thr = (base*5, base*13, 0.5) if rate < thr[0]: return "transport",rate @@ -386,7 +395,8 @@ class MAT: "总体积 ": f"{self.total_volume:.2f} ml", "终点体积": f"{self.colored_volume:.2f} ml", "理论体积": f"{self.colored_volume:.2f} ml", - "实验时长": f"{time.time() - self.start_time:.2f} 秒" + "实验时长": f"{time.time() - self.start_time:.2f} 秒", + "滴定速率": f"{self.total_volume / (time.time() - self.start_time):.2f} mL/s", } upload_data = { "start_time":self.format_date_time(self.start_time), @@ -408,16 +418,16 @@ if __name__ == "__main__": # 创建MAT类的实例并运行 mat = MAT( videoSourceIndex = 1, - bounce_time=4, + bounce_time=2, end_bounce_time=0.01, - k = 27 + k = 32 ) mat.state.mode = State.Mode.FAST final_data, finish_picture = mat.run( slow_speed = 0.05, - quick_speed = 0.8, + quick_speed = 1.0, about_time=3, # cap_dir=None ) diff --git a/utils.py b/utils.py index 8f2e0c8..f2af3be 100644 --- a/utils.py +++ b/utils.py @@ -420,7 +420,7 @@ def send_data_to_platform(token, data, picture): picture_data = picture_file.read() base64_encoded_picture = base64.b64encode(picture_data).decode("utf-8") - print(base64_encoded_picture) + # print(base64_encoded_picture) # 更新数据字典,添加 Base64 编码的图片 data["final_image"] = base64_encoded_picture diff --git a/vid_chk.py b/vid_chk.py index 0ddf379..d9f1cd5 100644 --- a/vid_chk.py +++ b/vid_chk.py @@ -30,7 +30,7 @@ while True: tot = mask.shape[0]*mask.shape[1] val = np.sum(mask) rate = val/tot - thr = (0.05,0.3, 0.5) + thr = (0.05,0.2, 0.5) ret = "" if rate < thr[0]: ret = "transport"