Skip to content
Merged
Changes from all commits
Commits
Show all changes
38 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
e5fff2b
Merge branch 'main' into main
jiangyi2302 Dec 24, 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
72 changes: 72 additions & 0 deletions src/Drone_gesture_operation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def __init__(self, target_fps=30):
self.skin_upper = np.array([30, 255, 180], np.uint8)
self.kernel = np.ones((3, 3), np.uint8)

# 新增:手指检测参数
self.defect_depth_threshold = 20 # 凸包缺陷深度阈值
self.min_defect_distance = 10 # 缺陷点最小距离
self.palm_solidity_threshold = 0.6 # 手掌的密实度阈值

# 3. 手势缓存(仅2帧,快速响应+稳定)
self.gesture_buffer = []
self.stable_gesture = "None"
Expand All @@ -26,6 +31,42 @@ def __init__(self, target_fps=30):
self.frame_queue = []
self.queue_lock = threading.Lock()

def count_fingers(self, cnt, frame_small):
"""通过凸包缺陷计算手指数量"""
try:
# 计算凸包和凸包缺陷
hull = cv.convexHull(cnt, returnPoints=False)
defects = cv.convexityDefects(cnt, hull)

if defects is None:
return 0

finger_count = 0
defect_points = []

# 遍历所有凸包缺陷
for i in range(defects.shape[0]):
s, e, f, d = defects[i, 0]
start = tuple(cnt[s][0])
end = tuple(cnt[e][0])
far = tuple(cnt[f][0])

# 计算缺陷深度(转换为实际像素值)
depth = d / 256.0

# 只考虑深度足够的缺陷(手指间的凹陷)
if depth > self.defect_depth_threshold:
# 计算两点间距离,避免重复计数
if all(np.linalg.norm(np.array(far) - np.array(p)) > self.min_defect_distance for p in
defect_points):
defect_points.append(far)
finger_count += 1

# 缺陷数+1 = 手指数量(例如:4个缺陷=5根手指)
return min(finger_count + 1, 5) # 最多5根手指
except:
return 0

def capture_frames(self, cap):
"""独立线程采集帧,避免主线程阻塞"""
while cap.isOpened():
Expand All @@ -48,6 +89,34 @@ def process_frame(self, frame):
mask = cv.morphologyEx(mask, cv.MORPH_OPEN, self.kernel)

# 2. 快速找轮廓
contours, _ = cv.findContours(mask, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
current_gesture = "None"

if contours:
cnt = max(contours, key=cv.contourArea)
area = cv.contourArea(cnt)

if area > 1000:
# 3. 手势分类(新增五指识别)
hull = cv.convexHull(cnt)
solidity = cv.contourArea(cnt) / cv.contourArea(hull)

# 计算手指数量
finger_count = self.count_fingers(cnt, frame_small)

# 手势判断逻辑
if solidity > 0.85:
# 密实度高 = 握拳
current_gesture = "Fist"
elif finger_count == 1:
# 1根手指 = 单指
current_gesture = "Point"
elif finger_count >= 4:
# 4-5根手指 = 手掌张开
current_gesture = "Palm"
elif 2 <= finger_count <= 3:
# 2-3根手指 = 部分张开(归类为Point)
current_gesture = "Point"


# 极简手势识别(仅保留拳头/点手势,极致流畅)
Expand Down Expand Up @@ -177,6 +246,7 @@ def main():
if len(set(self.gesture_buffer)) == 1:
self.stable_gesture = self.gesture_buffer[0]

# 5. 绘制极简UI(仅保留手势和FPS显示,移除手指数量)
# 5. 绘制极简UI(控制绘制耗时)
cv.putText(frame, f"Gesture: {self.stable_gesture}", (10, 40),
cv.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 255), 3)
Expand All @@ -202,6 +272,7 @@ def run(self):
capture_thread.start()

print(f"✅ 帧率锁定 {self.target_fps} 帧 | ESC退出")
print("💡 把手放在画面中间,握拳=Fist,伸食指=Point,五指张开=Palm")
print("💡 把手放在画面中间,握拳=Fist,伸食指=Point")

# 3. 主线程处理+显示(严格控时)
Expand Down Expand Up @@ -239,6 +310,7 @@ def run(self):
if __name__ == '__main__':
# 实例化并运行,锁定30帧(可改20/15帧,更低更稳)
recognizer = StableFPSHandRecognizer(target_fps=30)
recognizer.run()
recognizer.run()
# 7. 稳定输出(连续2帧相同)
if current_gesture == last_gesture:
Expand Down
Loading