Former-commit-id: 251b57f490efdc292b0c4c019431219b75ee890c
This commit is contained in:
2025-07-03 22:29:31 +08:00
parent 42460ad72f
commit 27c1b08365
3 changed files with 20 additions and 10 deletions

26
main.py
View File

@ -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
)

View File

@ -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

View File

@ -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"