新增agent功能
This commit is contained in:
parent
dae78fffc3
commit
d9ec92220e
@ -99,7 +99,7 @@ while True:
|
|||||||
if area < 75: # 过滤噪声,增大阈值
|
if area < 75: # 过滤噪声,增大阈值
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if area > 8000: # 过滤大面积假目标(如整个画面),减小阈值
|
if area > 5000: # 过滤大面积假目标(如整个画面),减小阈值
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 计算轮廓的宽高比,过滤不符合垃圾特征的目标
|
# 计算轮廓的宽高比,过滤不符合垃圾特征的目标
|
||||||
@ -117,7 +117,7 @@ while True:
|
|||||||
best_match = None
|
best_match = None
|
||||||
min_distance = float('inf')
|
min_distance = float('inf')
|
||||||
|
|
||||||
search_radius = 100 # 目标锁定区域半径
|
search_radius = 80 # 目标锁定区域半径
|
||||||
|
|
||||||
for area, cnt, x, y, w, h in valid_contours:
|
for area, cnt, x, y, w, h in valid_contours:
|
||||||
cx = x + w // 2
|
cx = x + w // 2
|
||||||
@ -170,7 +170,7 @@ while True:
|
|||||||
cy = int(alpha * prev_cy + (1 - alpha) * cy)
|
cy = int(alpha * prev_cy + (1 - alpha) * cy)
|
||||||
|
|
||||||
# 绘制画面中心
|
# 绘制画面中心
|
||||||
center_x = 50 # 画面中心x坐标
|
center_x = 90 # 画面中心x坐标
|
||||||
center_y = 120 # 画面中心y坐标
|
center_y = 120 # 画面中心y坐标
|
||||||
cv2.circle(frame, (center_x, center_y), 5, (255, 0, 0), -1)
|
cv2.circle(frame, (center_x, center_y), 5, (255, 0, 0), -1)
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ while True:
|
|||||||
tracking_target = None
|
tracking_target = None
|
||||||
|
|
||||||
# 控制逻辑:根据x轴和y轴坐标控制垃圾桶移动
|
# 控制逻辑:根据x轴和y轴坐标控制垃圾桶移动
|
||||||
center_x = 160 # 画面中心x坐标
|
center_x = 90 # 画面中心x坐标
|
||||||
center_y = 120 # 画面中心y坐标
|
center_y = 120 # 画面中心y坐标
|
||||||
threshold = 15 # 阈值范围
|
threshold = 15 # 阈值范围
|
||||||
|
|
||||||
|
|||||||
@ -72,25 +72,25 @@ def motor_drive(name, speed):
|
|||||||
# ======================
|
# ======================
|
||||||
# 基础移动
|
# 基础移动
|
||||||
# ======================
|
# ======================
|
||||||
def forward(speed=0.8):
|
def forward(speed=0.6):
|
||||||
motor_drive("M1", -speed)
|
motor_drive("M1", -speed)
|
||||||
motor_drive("M2", -speed)
|
motor_drive("M2", -speed)
|
||||||
motor_drive("M3", speed)
|
motor_drive("M3", speed)
|
||||||
motor_drive("M4", speed)
|
motor_drive("M4", speed)
|
||||||
|
|
||||||
def backward(speed=0.8):
|
def backward(speed=0.6):
|
||||||
motor_drive("M1", speed)
|
motor_drive("M1", speed)
|
||||||
motor_drive("M2", speed)
|
motor_drive("M2", speed)
|
||||||
motor_drive("M3", -speed)
|
motor_drive("M3", -speed)
|
||||||
motor_drive("M4", -speed)
|
motor_drive("M4", -speed)
|
||||||
|
|
||||||
def move_left(speed=0.8):
|
def move_left(speed=0.6):
|
||||||
motor_drive("M1", -speed)
|
motor_drive("M1", -speed)
|
||||||
motor_drive("M2", speed)
|
motor_drive("M2", speed)
|
||||||
motor_drive("M3", speed)
|
motor_drive("M3", speed)
|
||||||
motor_drive("M4", -speed)
|
motor_drive("M4", -speed)
|
||||||
|
|
||||||
def move_right(speed=0.8):
|
def move_right(speed=0.6):
|
||||||
motor_drive("M1", speed)
|
motor_drive("M1", speed)
|
||||||
motor_drive("M2", -speed)
|
motor_drive("M2", -speed)
|
||||||
motor_drive("M3", -speed)
|
motor_drive("M3", -speed)
|
||||||
@ -99,13 +99,13 @@ def move_right(speed=0.8):
|
|||||||
# ======================
|
# ======================
|
||||||
# 旋转
|
# 旋转
|
||||||
# ======================
|
# ======================
|
||||||
def rotate_left(speed=0.8):
|
def rotate_left(speed=0.6):
|
||||||
motor_drive("M1", -speed)
|
motor_drive("M1", -speed)
|
||||||
motor_drive("M2", -speed)
|
motor_drive("M2", -speed)
|
||||||
motor_drive("M3", -speed)
|
motor_drive("M3", -speed)
|
||||||
motor_drive("M4", -speed)
|
motor_drive("M4", -speed)
|
||||||
|
|
||||||
def rotate_right(speed=0.8):
|
def rotate_right(speed=0.6):
|
||||||
motor_drive("M1", speed)
|
motor_drive("M1", speed)
|
||||||
motor_drive("M2", speed)
|
motor_drive("M2", speed)
|
||||||
motor_drive("M3", speed)
|
motor_drive("M3", speed)
|
||||||
@ -114,25 +114,25 @@ def rotate_right(speed=0.8):
|
|||||||
# ======================
|
# ======================
|
||||||
# 斜向移动
|
# 斜向移动
|
||||||
# ======================
|
# ======================
|
||||||
def move_left_forward(speed=0.8):
|
def move_left_forward(speed=0.6):
|
||||||
motor_drive("M1", 0)
|
motor_drive("M1", 0)
|
||||||
motor_drive("M2", speed)
|
motor_drive("M2", speed)
|
||||||
motor_drive("M3", 0)
|
motor_drive("M3", 0)
|
||||||
motor_drive("M4", -speed)
|
motor_drive("M4", -speed)
|
||||||
|
|
||||||
def move_right_forward(speed=0.8):
|
def move_right_forward(speed=0.6):
|
||||||
motor_drive("M1", speed)
|
motor_drive("M1", speed)
|
||||||
motor_drive("M2", 0)
|
motor_drive("M2", 0)
|
||||||
motor_drive("M3", -speed)
|
motor_drive("M3", -speed)
|
||||||
motor_drive("M4", 0)
|
motor_drive("M4", 0)
|
||||||
|
|
||||||
def move_left_backward(speed=0.8):
|
def move_left_backward(speed=0.6):
|
||||||
motor_drive("M1", -speed)
|
motor_drive("M1", -speed)
|
||||||
motor_drive("M2", 0)
|
motor_drive("M2", 0)
|
||||||
motor_drive("M3", speed)
|
motor_drive("M3", speed)
|
||||||
motor_drive("M4", 0)
|
motor_drive("M4", 0)
|
||||||
|
|
||||||
def move_right_backward(speed=0.8):
|
def move_right_backward(speed=0.6):
|
||||||
motor_drive("M1", 0)
|
motor_drive("M1", 0)
|
||||||
motor_drive("M2", -speed)
|
motor_drive("M2", -speed)
|
||||||
motor_drive("M3", 0)
|
motor_drive("M3", 0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user