Skip to content
Merged
Changes from all commits
Commits
Show all changes
35 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
36274f1
Merge branch 'main' into main
jiangyi2302 Dec 22, 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
113 changes: 113 additions & 0 deletions src/Drone_gesture_operation/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,118 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2 as cv
import numpy as np
import time
from collections import deque


# ========== 稳定版手势识别(固定ROI+帧验证) ==========
class StableHandRecognizer:
def __init__(self):
# 1. 固定检测区域(画面右侧1/3)
self.roi_x1, self.roi_y1 = 600, 100
self.roi_x2, self.roi_y2 = 900, 500
# 2. 肤色范围(扩大兼容)
self.lower_skin = np.array([0, 20, 30], dtype=np.uint8)
self.upper_skin = np.array([30, 255, 255], dtype=np.uint8)
# 3. 手势缓存(连续3帧相同才确认)
self.gesture_buffer = deque(maxlen=3)
self.last_gesture = "None"

def get_roi(self, image):
"""截取固定检测区域"""
return image[self.roi_y1:self.roi_y2, self.roi_x1:self.roi_x2]

def process(self, image):
# 1. 截取ROI
roi = self.get_roi(image)
if roi.size == 0:
return "None", []

# 2. 预处理(降噪+肤色检测)
blur = cv.GaussianBlur(roi, (7, 7), 0)
hsv = cv.cvtColor(blur, cv.COLOR_BGR2HSV)
mask = cv.inRange(hsv, self.lower_skin, self.upper_skin)
mask = cv.morphologyEx(mask, cv.MORPH_CLOSE, np.ones((7, 7), np.uint8))

# 3. 找手部轮廓
contours, _ = cv.findContours(mask, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
if not contours:
self.gesture_buffer.append("None")
return self._get_stable_gesture(), []

max_contour = max(contours, key=cv.contourArea)
if cv.contourArea(max_contour) < 5000:
self.gesture_buffer.append("None")
return self._get_stable_gesture(), []

# 4. 手势判断(仅保留拳头/点手势,最稳定)
hull = cv.convexHull(max_contour)
solidity = cv.contourArea(max_contour) / cv.contourArea(hull)
current_gesture = "Fist" if solidity > 0.85 else "Point"
self.gesture_buffer.append(current_gesture)

# 5. 稳定输出(连续3帧相同)
return self._get_stable_gesture(), max_contour

def _get_stable_gesture(self):
"""只有连续3帧相同才输出"""
if len(self.gesture_buffer) < 3:
return self.last_gesture
if len(set(self.gesture_buffer)) == 1:
self.last_gesture = self.gesture_buffer[0]
return self.last_gesture


# ========== 主函数(带ROI框+稳定显示) ==========
def main():
cap = cv.VideoCapture(0)
cap.set(cv.CAP_PROP_FRAME_WIDTH, 960)
cap.set(cv.CAP_PROP_FRAME_HEIGHT, 540)
cap.set(cv.CAP_PROP_EXPOSURE, -6) # 固定曝光,避免过曝
recognizer = StableHandRecognizer()
fps_calc = deque(maxlen=10)

while True:
# 计时算FPS
start = time.time()
ret, frame = cap.read()
if not ret:
break
frame = cv.flip(frame, 1)
debug_frame = frame.copy()

# 1. 绘制ROI框(提示用户把手放在这里)
cv.rectangle(debug_frame, (recognizer.roi_x1, recognizer.roi_y1),
(recognizer.roi_x2, recognizer.roi_y2), (0, 255, 255), 2)
cv.putText(debug_frame, "Put hand here", (recognizer.roi_x1 + 10, recognizer.roi_y1 - 10),
cv.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 255), 2)

# 2. 识别手势
gesture, contour = recognizer.process(frame)

# 3. 绘制结果(固定位置,不闪烁)
cv.putText(debug_frame, f"Stable Gesture: {gesture}", (50, 50),
cv.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 255), 4)

# 4. 绘制手部轮廓(ROI内)
if contour is not None and len(contour) > 0:
# 转换轮廓坐标到全局画面
contour[:, :, 0] += recognizer.roi_x1
contour[:, :, 1] += recognizer.roi_y1
cv.drawContours(debug_frame, [contour], -1, (0, 255, 0), 2)

# 计算FPS
fps = 1 / (time.time() - start)
fps_calc.append(fps)
cv.putText(debug_frame, f"FPS: {int(np.mean(fps_calc))}", (50, 100),
cv.FONT_HERSHEY_SIMPLEX, 1.0, (255, 0, 0), 3)

# 显示
cv.imshow("Stable Hand Gesture", debug_frame)
if cv.waitKey(1) & 0xFF == 27:
break

# 导入必要的库
import copy # 深拷贝库,用于数据副本创建
import argparse # 命令行参数解析库
Expand Down
Loading