feat: close image save
This commit is contained in:
parent
e85d8dfbaa
commit
84cca7b2b6
7
main.py
7
main.py
@ -80,7 +80,6 @@ def main():
|
|||||||
Ctrl.base_msg.stand_up()
|
Ctrl.base_msg.stand_up()
|
||||||
Ctrl.base_msg.stop() # BUG 垃圾指令 for eat # INFO 但是正式比赛或许也有用
|
Ctrl.base_msg.stop() # BUG 垃圾指令 for eat # INFO 但是正式比赛或许也有用
|
||||||
|
|
||||||
|
|
||||||
# image = Ctrl.image_processor.get_current_image('ai')
|
# image = Ctrl.image_processor.get_current_image('ai')
|
||||||
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
|
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
|
||||||
# filename = f"saved_images/rgb_{timestamp}.jpg"
|
# filename = f"saved_images/rgb_{timestamp}.jpg"
|
||||||
@ -136,7 +135,7 @@ def main():
|
|||||||
# run_task_2_5(Ctrl, msg, direction=arrow_direction)
|
# run_task_2_5(Ctrl, msg, direction=arrow_direction)
|
||||||
|
|
||||||
|
|
||||||
# #TAG task - 3 / 4 - part I
|
#TAG task - 3 / 4 - part I
|
||||||
# if arrow_direction == 'left':
|
# if arrow_direction == 'left':
|
||||||
# run_task_4(Ctrl, msg)
|
# run_task_4(Ctrl, msg)
|
||||||
# else:
|
# else:
|
||||||
@ -145,7 +144,7 @@ def main():
|
|||||||
|
|
||||||
# TAG task - 5
|
# TAG task - 5
|
||||||
# turn_degree_v2(Ctrl, msg, degree=90, absolute=True)
|
# turn_degree_v2(Ctrl, msg, degree=90, absolute=True)
|
||||||
success, qr=run_task_5(Ctrl, msg, direction=arrow_direction, observe=True, time_sleep=TIME_SLEEP) # B区任务
|
# success, qr=run_task_5(Ctrl, msg, direction=arrow_direction, observe=True, time_sleep=TIME_SLEEP) # B区任务
|
||||||
# print(success)
|
# print(success)
|
||||||
# print(qr)
|
# print(qr)
|
||||||
|
|
||||||
@ -208,7 +207,7 @@ class Robot_Ctrl(object):
|
|||||||
self.cmd_msg = robot_control_cmd_lcmt()
|
self.cmd_msg = robot_control_cmd_lcmt()
|
||||||
self.rec_msg = robot_control_response_lcmt()
|
self.rec_msg = robot_control_response_lcmt()
|
||||||
self.odo_msg = localization_lcmt()
|
self.odo_msg = localization_lcmt()
|
||||||
self.image_processor = ImageProcessor()
|
self.image_processor = ImageProcessor(save_flag=False) # INFO 这里控制是否开始保存图片
|
||||||
# DEBUG
|
# DEBUG
|
||||||
# self.marker_runner = MarkerRunner(pass_flag=pass_marker)
|
# self.marker_runner = MarkerRunner(pass_flag=pass_marker)
|
||||||
self.send_lock = Lock()
|
self.send_lock = Lock()
|
||||||
|
|||||||
@ -20,7 +20,7 @@ from utils.speech_demo import speak
|
|||||||
# 创建本模块特定的日志记录器
|
# 创建本模块特定的日志记录器
|
||||||
logger = get_logger("任务1")
|
logger = get_logger("任务1")
|
||||||
|
|
||||||
observe = True
|
observe = False # 控制是否输出更多调试信息
|
||||||
direction = True
|
direction = True
|
||||||
|
|
||||||
def run_task_1(ctrl, msg, time_sleep=5000):
|
def run_task_1(ctrl, msg, time_sleep=5000):
|
||||||
|
|||||||
@ -17,7 +17,7 @@ from file_send_lcmt import file_send_lcmt
|
|||||||
# 创建本模块特定的日志记录器
|
# 创建本模块特定的日志记录器
|
||||||
logger = get_logger("低头匍匐步态")
|
logger = get_logger("低头匍匐步态")
|
||||||
|
|
||||||
observe = True
|
observe = False
|
||||||
|
|
||||||
robot_cmd = {
|
robot_cmd = {
|
||||||
'mode':0, 'gait_id':0, 'contact':0, 'life_count':0,
|
'mode':0, 'gait_id':0, 'contact':0, 'life_count':0,
|
||||||
|
|||||||
@ -33,7 +33,7 @@ from task_2.crawl_gait import (
|
|||||||
# 创建本模块特定的日志记录器
|
# 创建本模块特定的日志记录器
|
||||||
logger = get_logger("任务2-5")
|
logger = get_logger("任务2-5")
|
||||||
|
|
||||||
observe = True
|
observe = False
|
||||||
|
|
||||||
# 异步箭头检测器类
|
# 异步箭头检测器类
|
||||||
class AsyncArrowDetector:
|
class AsyncArrowDetector:
|
||||||
@ -148,7 +148,6 @@ class AsyncArrowDetector:
|
|||||||
return self.left_count, self.right_count
|
return self.left_count, self.right_count
|
||||||
|
|
||||||
def run_task_2(ctrl, msg, xy_flag=False):
|
def run_task_2(ctrl, msg, xy_flag=False):
|
||||||
|
|
||||||
# 微调 xy 和角度
|
# 微调 xy 和角度
|
||||||
# go_to_xy_v2(ctrl, msg, 0.9, 0.25, speed=0.5, observe=True)
|
# go_to_xy_v2(ctrl, msg, 0.9, 0.25, speed=0.5, observe=True)
|
||||||
# turn_degree_v2(ctrl, msg, 0.8, absolute=True)
|
# turn_degree_v2(ctrl, msg, 0.8, absolute=True)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from base_move.go_to_xy import go_straight, go_to_x_v2, go_to_y_v2
|
|||||||
from base_move.move_base_hori_line import arc_turn_around_hori_line, align_to_horizontal_line
|
from base_move.move_base_hori_line import arc_turn_around_hori_line, align_to_horizontal_line
|
||||||
from utils.log_helper import LogHelper, get_logger, section, info, debug, warning, error, success, timing
|
from utils.log_helper import LogHelper, get_logger, section, info, debug, warning, error, success, timing
|
||||||
|
|
||||||
observe = True
|
observe = False
|
||||||
|
|
||||||
def run_task_2_5(Ctrl, msg, direction='left'):
|
def run_task_2_5(Ctrl, msg, direction='left'):
|
||||||
section('任务2.5:预备进入任务3', "启动")
|
section('任务2.5:预备进入任务3', "启动")
|
||||||
|
|||||||
@ -26,7 +26,7 @@ from utils.speech_demo import speak
|
|||||||
# 创建本模块特定的日志记录器
|
# 创建本模块特定的日志记录器
|
||||||
logger = get_logger("任务3")
|
logger = get_logger("任务3")
|
||||||
|
|
||||||
observe = True
|
observe = False
|
||||||
YELLOW_RATIO_THRESHOLD = 0.03 # TODO 黄色区域比例阈值
|
YELLOW_RATIO_THRESHOLD = 0.03 # TODO 黄色区域比例阈值
|
||||||
|
|
||||||
def run_task_3(ctrl, msg, time_sleep=5000):
|
def run_task_3(ctrl, msg, time_sleep=5000):
|
||||||
|
|||||||
@ -19,7 +19,7 @@ from file_send_lcmt import file_send_lcmt
|
|||||||
# 创建本模块特定的日志记录器
|
# 创建本模块特定的日志记录器
|
||||||
logger = get_logger("任务3")
|
logger = get_logger("任务3")
|
||||||
|
|
||||||
observe = True
|
observe = False
|
||||||
|
|
||||||
robot_cmd = {
|
robot_cmd = {
|
||||||
'mode':0, 'gait_id':0, 'contact':0, 'life_count':0,
|
'mode':0, 'gait_id':0, 'contact':0, 'life_count':0,
|
||||||
|
|||||||
@ -22,7 +22,7 @@ from task_3.task_3 import pass_stone
|
|||||||
# 创建本模块特定的日志记录器
|
# 创建本模块特定的日志记录器
|
||||||
logger = get_logger("任务4")
|
logger = get_logger("任务4")
|
||||||
|
|
||||||
observe = True
|
observe = False
|
||||||
|
|
||||||
STONE_DISTANCE = 4.5 # TODO 距离参数需要微调
|
STONE_DISTANCE = 4.5 # TODO 距离参数需要微调
|
||||||
RED_RATIO_THRESHOLD = 0.18 # TODO 红色区域比例阈值需要微调
|
RED_RATIO_THRESHOLD = 0.18 # TODO 红色区域比例阈值需要微调
|
||||||
|
|||||||
@ -105,7 +105,7 @@ def test_track_detection(image_path, observe=True, save_log=True):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 设置观察模式和保存日志
|
# 设置观察模式和保存日志
|
||||||
observe = True
|
observe = False
|
||||||
save_log = True
|
save_log = True
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
|||||||
@ -73,7 +73,7 @@ from pyzbar import pyzbar
|
|||||||
|
|
||||||
|
|
||||||
class ImageSubscriber(Node):
|
class ImageSubscriber(Node):
|
||||||
def __init__(self):
|
def __init__(self, save_flag=False):
|
||||||
super().__init__('ai_camera_demo')
|
super().__init__('ai_camera_demo')
|
||||||
|
|
||||||
# 初始化安全控制标志
|
# 初始化安全控制标志
|
||||||
@ -118,6 +118,7 @@ class ImageSubscriber(Node):
|
|||||||
'ai': time.time()
|
'ai': time.time()
|
||||||
}
|
}
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
|
self.save_flag = save_flag
|
||||||
self.save_interval = 0.5
|
self.save_interval = 0.5
|
||||||
self.total_duration = 1.0
|
self.total_duration = 1.0
|
||||||
self.save_dir = "saved_images"
|
self.save_dir = "saved_images"
|
||||||
@ -198,7 +199,7 @@ class ImageSubscriber(Node):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.cv_image_rgb = self.bridge.imgmsg_to_cv2(msg, 'bgr8')
|
self.cv_image_rgb = self.bridge.imgmsg_to_cv2(msg, 'bgr8')
|
||||||
if time.time() - self.last_save_time['rgb'] >= self.save_interval:
|
if self.save_flag and time.time() - self.last_save_time['rgb'] >= self.save_interval:
|
||||||
self.save_image(self.cv_image_rgb, 'rgb')
|
self.save_image(self.cv_image_rgb, 'rgb')
|
||||||
self.last_save_time['rgb'] = time.time()
|
self.last_save_time['rgb'] = time.time()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -225,7 +226,7 @@ class ImageSubscriber(Node):
|
|||||||
def image_callback_ai(self, msg):
|
def image_callback_ai(self, msg):
|
||||||
try:
|
try:
|
||||||
self.cv_image_ai = self.bridge.imgmsg_to_cv2(msg, 'bgr8')
|
self.cv_image_ai = self.bridge.imgmsg_to_cv2(msg, 'bgr8')
|
||||||
if time.time() - self.last_save_time['ai'] >= self.save_interval:
|
if self.save_flag and time.time() - self.last_save_time['ai'] >= self.save_interval:
|
||||||
self.save_image(self.cv_image_ai, 'ai')
|
self.save_image(self.cv_image_ai, 'ai')
|
||||||
self.last_save_time['ai'] = time.time()
|
self.last_save_time['ai'] = time.time()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -275,8 +276,8 @@ class ImageSubscriber(Node):
|
|||||||
|
|
||||||
|
|
||||||
class ImageProcessor:
|
class ImageProcessor:
|
||||||
def __init__(self):
|
def __init__(self, save_flag=False):
|
||||||
self.image_subscriber = ImageSubscriber()
|
self.image_subscriber = ImageSubscriber(save_flag=save_flag)
|
||||||
self.spin_thread = None
|
self.spin_thread = None
|
||||||
self.running = True
|
self.running = True
|
||||||
self.log = get_logger("图像处理器")
|
self.log = get_logger("图像处理器")
|
||||||
@ -389,7 +390,7 @@ class ImageProcessor:
|
|||||||
"""
|
"""
|
||||||
if self.scan_thread is not None and self.scan_thread.is_alive():
|
if self.scan_thread is not None and self.scan_thread.is_alive():
|
||||||
self.log.warning("异步扫描已经在运行中", "警告")
|
self.log.warning("异步扫描已经在运行中", "警告")
|
||||||
print('scan,warn')
|
print('scan, warn')
|
||||||
return
|
return
|
||||||
|
|
||||||
self.enable_async_scan = True
|
self.enable_async_scan = True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user