Skip to content
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
852109a
完成选题并提交
jiangyi2302 Dec 18, 2025
6fe47f5
完成选题并提交
jiangyi2302 Dec 18, 2025
af14f99
完成选题并提交
jiangyi2302 Dec 18, 2025
c1ae4ac
完成选题并提交
jiangyi2302 Dec 18, 2025
ddaa9d5
完成选题并提交
jiangyi2302 Dec 18, 2025
d66962d
完成选题并提交
jiangyi2302 Dec 18, 2025
9293e17
完成选题并提交
jiangyi2302 Dec 18, 2025
e8fef31
完成选题并提交
jiangyi2302 Dec 18, 2025
7a9fab5
完成选题并提交
jiangyi2302 Dec 18, 2025
79cc531
完成选题并提交
jiangyi2302 Dec 18, 2025
29f7770
完成选题并提交
jiangyi2302 Dec 18, 2025
4b1aca1
完成选题并提交
jiangyi2302 Dec 18, 2025
edcd60e
完成选题并提交
jiangyi2302 Dec 18, 2025
e43731a
完成选题并提交
jiangyi2302 Dec 18, 2025
0f8575a
完成选题并提交
jiangyi2302 Dec 18, 2025
60db4b4
完成选题并提交
jiangyi2302 Dec 18, 2025
d9535ba
完成选题并提交
jiangyi2302 Dec 18, 2025
7886980
完成选题:更新Unmanned_Aircraft_System的README.md
jiangyi2302 Dec 18, 2025
b498537
提交选题
jiangyi2302 Dec 19, 2025
bc14972
修改选题
jiangyi2302 Dec 19, 2025
c0679cb
完成选题并提交
jiangyi2302 Dec 19, 2025
2d1e296
重命名文件夹:Unmanned_Aircraft_System → UAV_Small_Target_Recognition
jiangyi2302 Dec 19, 2025
d49e121
完成选题并提交
jiangyi2302 Dec 19, 2025
2c57293
重命名文件夹为Gesture_Control_for_Airsim_UAV,并更新README.md补充无人机手势控制内容
jiangyi2302 Dec 19, 2025
d5f2c9d
重命名文件夹:Gesture_Control_for_Airsim_UAV → Drone_gesture_operation
jiangyi2302 Dec 19, 2025
f1d3167
更新Drone_gesture_operation/README.md:基于轻量级 CNN 的无人机手势操控指令识别
jiangyi2302 Dec 19, 2025
5a5639c
无人机手势识别
jiangyi2302 Dec 20, 2025
0ecd007
更新Drone_gesture_operation:同步main.py代码
jiangyi2302 Dec 20, 2025
786c598
无人机手势识别
jiangyi2302 Dec 20, 2025
2bd5954
优化Drone_gesture_operation/main.py:给代码添加注释,增加可读性
jiangyi2302 Dec 20, 2025
c6eea87
新增Drone_gesture_operation/keypoint_classifier.py:无人机手势关键点分类器
jiangyi2302 Dec 21, 2025
f2dc1af
优化Drone_gesture_operation/main.py:可切换三种模式
jiangyi2302 Dec 21, 2025
0b9f52d
给代码添加注释
jiangyi2302 Dec 22, 2025
049d707
能够识别手势:拳头
jiangyi2302 Dec 22, 2025
d5a28cd
优化手势切换的流畅度
jiangyi2302 Dec 22, 2025
d15abc4
使画面帧率更稳定
jiangyi2302 Dec 23, 2025
f507f0e
添加了对五指张开的手势识别
jiangyi2302 Dec 24, 2025
032575a
修改了对手指的识别
jiangyi2302 Dec 24, 2025
89e210e
修改了手势识别后的输出
jiangyi2302 Dec 24, 2025
b40eaa4
添加了识别区域
jiangyi2302 Dec 25, 2025
5016971
添加识区别
jiangyi2302 Dec 25, 2025
dcb1122
优化手势识别的准确度
jiangyi2302 Dec 26, 2025
856383b
备注:你改了什么
jiangyi2302 Dec 27, 2025
2347d15
在光线暗时也能识别
jiangyi2302 Dec 27, 2025
c68229a
解决部分手势识别不出
jiangyi2302 Dec 28, 2025
9e4b8ba
Merge branch 'main' into main
jiangyi2302 Dec 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions src/Drone_gesture_operation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def __init__(self, target_fps=30):
self.frame_interval = 1.0 / target_fps
self.last_frame_time = time.time()

# 2. 肤色检测(适配明亮+暗光环境)
self.skin_lower_bright = np.array([0, 10, 50], np.uint8)
self.skin_upper_bright = np.array([30, 255, 255], np.uint8)
self.skin_lower_dark = np.array([0, 5, 15], np.uint8)
self.skin_upper_dark = np.array([40, 180, 200], np.uint8)
# 2. 肤色检测(适配明亮+暗光环境,核心优化:新增暗光阈值)
# 明亮环境阈值(保留原有,适配强光场景)
self.skin_lower_bright = np.array([0, 10, 50], np.uint8)
Expand All @@ -25,6 +30,21 @@ def __init__(self, target_fps=30):
self.skin_upper = self.skin_upper_dark
self.kernel = np.ones((5, 5), np.uint8)

# 3. 核心参数(细化两者特征差异,解决重叠问题)
# 握拳参数(收紧阈值,增加横向/方正特征约束)
self.fist_solidity = 0.85 # 从0.82升至0.85,收紧密实度,拉大与大拇指差距
self.fist_area_ratio = 0.75
# 手指计数参数
self.defect_depth_threshold = 4
self.min_contour_area = 300
# 大拇指识别参数(强化纵向特征,与握拳形成明显差异)
self.thumb_aspect_ratio = 0.6
self.thumb_solidity_range = (0.4, 0.82) # 上限设为0.82,与握拳阈值0.85无重叠
self.thumb_defect_max = 3

# 4. 缓存参数
self.gesture_buffer = []
self.buffer_size = 3
# 3. 核心参数(精准适配手势特征,优化暗光下轮廓识别)
# 2. 肤色检测(适配更多光线)
self.skin_lower = np.array([0, 10, 50], np.uint8)
Expand Down Expand Up @@ -161,6 +181,7 @@ def analyze_contour(self, cnt):
c = np.linalg.norm(np.array(end) - np.array(far))
angle = np.arccos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c)) * 180 / np.pi if (b * c) > 0 else 0

if depth > self.defect_depth_threshold and angle < 100:
if depth > self.defect_depth_threshold and angle < 90:
valid_defects.append((depth, angle, far))
defect_count += 1
Expand All @@ -185,6 +206,28 @@ def analyze_contour(self, cnt):
return None

def is_fist(self, features):
"""优化握拳(stop)判定:增加方正/横向轮廓排除,避免误判大拇指"""
if not features:
return False
# 握拳核心特征:高密实度 + 低缺陷数 + 方正/横向轮廓(h <= w,排除纵向大拇指)
return (features["solidity"] > self.fist_solidity and
features["defect_count"] <= 1 and
abs(features["aspect_ratio"] - 1) < 0.3 and
features["h"] <= features["w"]) # 新增:握拳高度不大于宽度,排除纵向大拇指

def is_thumb_up(self, features):
"""强化竖大拇指(up)纵向特征,与握拳形成明显差异"""
if not features:
return False
# 大拇指核心特征:窄高轮廓 + 适中密实度 + 少量缺陷 + 强纵向延伸
return (features["aspect_ratio"] < self.thumb_aspect_ratio and
self.thumb_solidity_range[0] < features["solidity"] < self.thumb_solidity_range[1] and
features["defect_count"] <= self.thumb_defect_max and
features["hull_aspect"] < 0.7 and
features["h"] > features["w"] * 1.2) # 强化纵向:高度大于宽度1.2倍,与握拳形成差距

def capture_frames(self, cap):
"""帧采集线程"""
"""稳定识别握拳(stop)"""
if not features:
return False
Expand Down Expand Up @@ -311,6 +354,7 @@ def capture_frames(self, cap):
time.sleep(self.frame_interval * 0.5)

def process_frame(self, frame):
"""核心处理逻辑:调整手势判断优先级,先up后stop"""
"""核心处理逻辑(暗光增强优化)"""
"""核心处理逻辑"""
frame = cv.flip(frame, 1)
Expand All @@ -319,6 +363,28 @@ def process_frame(self, frame):
current_gesture = "None"

if roi.size > 0:
# 预处理(暗光增强+去噪)
roi_small = cv.resize(roi, (400, 300))
alpha = 1.8
beta = 40
roi_enhanced = cv.convertScaleAbs(roi_small, alpha=alpha, beta=beta)
roi_denoised = cv.GaussianBlur(roi_enhanced, (5, 5), 0)

# 自适应亮度判断
gray_roi = cv.cvtColor(roi_small, cv.COLOR_BGR2GRAY)
avg_brightness = np.mean(gray_roi)
if avg_brightness < 50:
self.skin_lower = self.skin_lower_dark
self.skin_upper = self.skin_upper_dark
else:
self.skin_lower = self.skin_lower_bright
self.skin_upper = self.skin_upper_bright

# 肤色掩码提取+形态学优化
hsv = cv.cvtColor(roi_denoised, cv.COLOR_BGR2HSV)
mask = cv.inRange(hsv, self.skin_lower, self.skin_upper)
mask = cv.morphologyEx(mask, cv.MORPH_OPEN, self.kernel, iterations=1)
mask = cv.morphologyEx(mask, cv.MORPH_DILATE, self.kernel, iterations=2)
# 预处理(暗光增强:亮度+对比度+去噪+形态学,核心优化)
roi_small = cv.resize(roi, (400, 300))

Expand Down Expand Up @@ -363,6 +429,39 @@ def process_frame(self, frame):
features = self.analyze_contour(cnt)

if features and features["area"] > self.min_contour_area:
# 手动轮廓坐标缩放+偏移
scale_x = roi.shape[1] / float(roi_small.shape[1])
scale_y = roi.shape[0] / float(roi_small.shape[0])
cnt_scaled = cnt.astype(np.float64)
cnt_scaled[:, :, 0] *= scale_x
cnt_scaled[:, :, 1] *= scale_y
cnt_scaled[:, :, 0] += roi_x
cnt_scaled[:, :, 1] += roi_y
cnt_scaled = cnt_scaled.astype(np.int32)
cnt_scaled[:, :, 0] = np.clip(cnt_scaled[:, :, 0], 0, frame.shape[1]-1)
cnt_scaled[:, :, 1] = np.clip(cnt_scaled[:, :, 1], 0, frame.shape[0]-1)

cv.drawContours(frame, [cnt_scaled], -1, (255, 0, 0), 2)

# ========== 核心优化:调整手势判断优先级(先up后stop) ==========
# 1. 优先判断竖大拇指(up)- 避免被stop提前拦截
if self.is_thumb_up(features):
current_gesture = "up"
# 2. 再判断握拳(stop)- 此时已排除大拇指,无误判
elif self.is_fist(features):
current_gesture = "stop"
# 3. 其他手势判断
elif features["defect_count"] == 1:
current_gesture = "front"
elif features["defect_count"] >= 3:
current_gesture = "back"
else:
current_gesture = "None"

# 缓存稳定性增强
self.gesture_buffer.append(current_gesture)
if len(self.gesture_buffer) > self.buffer_size:
self.gesture_buffer.pop(0)
# 绘制轮廓(调试用,可直观看到手部提取效果)
# 绘制轮廓(调试用)
self.frame_queue = [frame] # 只保留最新帧
Expand Down Expand Up @@ -662,6 +761,10 @@ def main():
return frame_show

def run(self):
"""主运行逻辑"""
# 摄像头初始化
cap = cv.VideoCapture(0)
cap.set(cv.CAP_PROP_FRAME_WIDTH, 640)
"""主运行逻辑(修复时间计算错误)"""
# 摄像头初始化
cap = cv.VideoCapture(0)
Expand All @@ -682,6 +785,16 @@ def run(self):
# 提示信息
print("=" * 60)
print(f"✅ 帧率锁定 {self.target_fps} 帧 | ESC退出")
print("💡 修复up误判为stop(优先级+特征优化):")
print(" 👍 竖大拇指 → up(优先判断,精准识别)")
print(" ✊ 握拳 → stop(排除大拇指,无重叠)")
print(" 🤘 食指+中指 → front")
print(" 🖐️ 手掌张开 → back")
print("📌 已解决up与stop的特征重叠问题")
print("=" * 60)

# 主循环
while cap.isOpened():
print("💡 暗光优化版手势识别(高稳定性):")
print("💡 优化版手势识别(高稳定性):")
print(" ✊ 握拳 → stop(高稳定)")
Expand Down Expand Up @@ -762,6 +875,9 @@ def run(self):

# 处理并显示
frame_show = self.process_frame(frame)
cv.imshow("Hand Gesture Recognition (Fix UP→Stop Misjudgment)", frame_show)

# 更新时间戳
cv.imshow("Hand Gesture Recognition (Dark Mode Optimized)", frame_show)

# 更新时间戳
Expand All @@ -788,6 +904,7 @@ def run(self):
if __name__ == '__main__':
recognizer = StableFPSHandRecognizer(target_fps=20)
recognizer.run()
recognizer.run()
# 20帧兼顾流畅度和识别稳定性
recognizer = StableFPSHandRecognizer(target_fps=20)
recognizer.run()
Expand Down
Loading