Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
20e276a
更新代码
183899 Dec 1, 2025
91bf847
Merge branch 'OpenHUTB:main' into main
183899 Dec 1, 2025
08bccf0
Merge branch 'OpenHUTB:main' into main
183899 Dec 8, 2025
4a2ccc8
将原模块名更改为更加详细的名字
183899 Dec 8, 2025
da1e375
Merge branch 'OpenHUTB:main' into main
183899 Dec 15, 2025
1678aeb
Merge branch 'OpenHUTB:main' into main
183899 Dec 15, 2025
2b3e4b2
更新了控制器功能,增添了速度显示效果
183899 Dec 15, 2025
10f7798
Merge branch 'OpenHUTB:main' into main
183899 Dec 15, 2025
1f64807
补充并在原有的 drawer.py 中添加了 draw_point 方法
183899 Dec 16, 2025
b21c1f2
Merge branch 'OpenHUTB:main' into main
183899 Dec 16, 2025
c9d3f89
添加传感器数据采集模块
Dec 18, 2025
0d5b42a
模块化PID控制优化
0023csw Dec 18, 2025
9f0723c
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 18, 2025
09ac131
新添手势增强识别程序,并修改主程序
Arrebol01 Dec 18, 2025
737c4bd
增加传感器数据采集模型及运行效果
Dec 18, 2025
a1f34b4
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 18, 2025
cebf093
Merge branch 'OpenHUTB:main' into main
183899 Dec 18, 2025
417561d
添加新的转弯感知模块,修改main函数实现转弯时自主检测刹车
183899 Dec 18, 2025
8728dc7
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 18, 2025
c15f438
修改readme文件
Dec 18, 2025
8114475
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
29141dd
完整README文件
Arrebol01 Dec 19, 2025
34dd8d3
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 19, 2025
10fb819
添加LiDAR-IMU紧耦合里程计模块
Dec 19, 2025
f61c544
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
7736d31
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
5a11a5f
完全中文显示
Arrebol01 Dec 19, 2025
837902a
简洁化与环境管理优化
0023csw Dec 19, 2025
a091bb1
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 19, 2025
170d62e
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 19, 2025
f46671c
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
9027bb5
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 19, 2025
a92adb9
更新readme文件
Dec 19, 2025
d1493ae
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
f756b9f
提交选题
ou-yang220 Dec 19, 2025
4ced0d4
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 19, 2025
3b3f9b8
添加因子图优化后端模块代码
Dec 19, 2025
c24646f
docs: 新增README.md,记录车路协同与边缘智能研究方向
ou-yang220 Dec 19, 2025
0a46f15
docs: 修改文件名
ou-yang220 Dec 19, 2025
dcd6cb6
feat: 车路协同与边缘智能 路侧YOLOv7轻量化模型
ou-yang220 Dec 19, 2025
2d62df4
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
033223e
feat: 车路协同与边缘智能 路侧YOLOv7轻量化模型
ou-yang220 Dec 19, 2025
7dfbfea
PID控制器再度提升清晰度优化
0023csw Dec 19, 2025
90502cf
Merge branch 'main' into main
0023csw Dec 19, 2025
b989886
config: 新增.idea/忽略规则,解决中文配置文件追踪问题
ou-yang220 Dec 19, 2025
1326c3e
Merge branch 'OpenHUTB:main' into main
pppzzz222 Dec 19, 2025
3ac7328
更新README文件
Dec 19, 2025
8be8c36
fix: 解决.gitignore和dataloader.py合并冲突,适配车路协同主题
ou-yang220 Dec 19, 2025
c6797db
feat: 车路协同与边缘智能 路侧YOLOv7模型新增V2X通信功能
ou-yang220 Dec 19, 2025
8a066a7
fix: 解决.idea/中文路径解析异常,忽略车路协同相关伪路径
ou-yang220 Dec 19, 2025
ebbb588
Merge branch 'OpenHUTB:main' into main
183899 Dec 19, 2025
532b4ab
新增预测功能,提前预测转弯效果
183899 Dec 19, 2025
05bd688
fix: 忽略.idea/文件夹,清理车路协同主题项目状态
ou-yang220 Dec 19, 2025
ae3ff1e
FadingText透明度计算优化
0023csw Dec 19, 2025
02776d0
feat: 车路协同与边缘智能 路侧YOLOv7模型新增V2X通信功能
ou-yang220 Dec 19, 2025
3a4253b
车路协同(V2X)+边缘智能 路侧感知轻量化模型
ou-yang220 Dec 19, 2025
0cd6a4c
添加新的检测模块
abc123335 Dec 19, 2025
3269feb
Merge branch 'main' of https://github.com/abc123335/nn
abc123335 Dec 19, 2025
ce54974
Merge pull request #3955 from 0023csw/main
William4861 Dec 19, 2025
aa9599b
Merge pull request #3959 from abc123335/main
William4861 Dec 19, 2025
f154c65
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
8d860d2
添加帧率控制
Arrebol01 Dec 19, 2025
fa24369
重新更新了主程序文件
abc123335 Dec 19, 2025
763de6f
Merge branch 'main' of https://github.com/abc123335/nn
abc123335 Dec 19, 2025
f5f36d5
Merge pull request #3949 from pppzzz222/main
Arrebol01 Dec 19, 2025
ba47035
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
896affd
Merge pull request #3961 from abc123335/main
William4861 Dec 19, 2025
9a72249
Merge pull request #3957 from ou-yang220/main
William4861 Dec 19, 2025
cff87b1
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 2025
39c052d
Merge pull request #3954 from 183899/main
William4861 Dec 19, 2025
03cef70
Merge branch 'OpenHUTB:main' into main
Arrebol01 Dec 19, 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
Binary file modified .gitignore
Binary file not shown.
258 changes: 152 additions & 106 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,118 +1,164 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Lane Line Detection (精简版)
核心功能:Canny边缘检测 + 霍夫变换实现车道线检测,单视频处理+结果保存
适用环境:Ubuntu (Python 3.10 + OpenCV + numpy)
"""

import cv2
import numpy as np
import argparse
import os
from pathlib import Path

# ===================== 核心参数(仅保留必要的) =====================
# 车道线检测核心参数
CANNY_LOW_THRESH = 50 # Canny边缘检测低阈值
CANNY_HIGH_THRESH = 150 # Canny边缘检测高阈值
HOUGH_RHO = 1 # 霍夫变换rho步长
HOUGH_THETA = np.pi / 180 # 霍夫变换theta步长
HOUGH_THRESHOLD = 20 # 霍夫变换阈值
HOUGH_MIN_LINE_LEN = 40 # 最小线段长度
HOUGH_MAX_LINE_GAP = 20 # 最大线段间隙

# ===================== 核心函数:车道线检测 =====================
def detect_lane_lines(frame):
"""核心:检测并绘制车道线(Canny + 霍夫变换)"""
# 1. 灰度化 + 高斯模糊
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)

# 2. Canny边缘检测
edges = cv2.Canny(blur, CANNY_LOW_THRESH, CANNY_HIGH_THRESH)

# 3. 区域掩码(仅检测图像下半部分,聚焦车道)
h, w = frame.shape[:2]
mask = np.zeros_like(edges)
polygon = np.array([[(0, h), (w//2, h//2), (w, h)]], np.int32)
cv2.fillPoly(mask, polygon, 255)
masked_edges = cv2.bitwise_and(edges, mask)

# 4. 霍夫变换检测直线
lines = cv2.HoughLinesP(
masked_edges, HOUGH_RHO, HOUGH_THETA, HOUGH_THRESHOLD,
minLineLength=HOUGH_MIN_LINE_LEN, maxLineGap=HOUGH_MAX_LINE_GAP
)

# 5. 绘制车道线
frame_with_lane = frame.copy()
if lines is not None:
import sys
from collections import deque
import time

# 引入我们刚才写的 YOLO 模块
from yolo_det import ObjectDetector

# ==========================================
# 👇 参数配置区 (填入你之前 Tuner 调好的参数)
# ==========================================
CANNY_LOW = 50
CANNY_HIGH = 150
ROI_TOP_WIDTH = 0.40
ROI_HEIGHT_POS = 0.60
HOUGH_THRESH = 20
MIN_LINE_LEN = 20
MAX_LINE_GAP = 100
# ==========================================

class LaneDetector:
def __init__(self):
self.left_lines_buffer = deque(maxlen=10)
self.right_lines_buffer = deque(maxlen=10)
self.vertices = None

def region_of_interest(self, img):
mask = np.zeros_like(img)
if self.vertices is None:
height, width = img.shape
top_w = width * ROI_TOP_WIDTH
top_x_center = width * 0.5
bl = (0, height)
tl = (int(top_x_center - top_w/2), int(height * ROI_HEIGHT_POS))
tr = (int(top_x_center + top_w/2), int(height * ROI_HEIGHT_POS))
br = (width, height)
self.vertices = np.array([[bl, tl, tr, br]], dtype=np.int32)
cv2.fillPoly(mask, self.vertices, 255)
return cv2.bitwise_and(img, mask)

def process_lane(self, frame):
if frame is None: return frame

# 1. 边缘检测
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
edges = cv2.Canny(blur, CANNY_LOW, CANNY_HIGH)

# 2. ROI
roi = self.region_of_interest(edges)

# 3. 霍夫变换
lines = cv2.HoughLinesP(roi, 1, np.pi/180, HOUGH_THRESH,
minLineLength=MIN_LINE_LEN,
maxLineGap=MAX_LINE_GAP)

# 4. 计算与平滑
left_raw, right_raw = self.average_slope_intercept(lines)
left_avg, right_avg = self.smooth_lines(left_raw, right_raw)

# 5. 绘制
height = frame.shape[0]
y_min = int(height * ROI_HEIGHT_POS) + 50
y_max = height
left_pts = self.make_line_points(left_avg, y_min, y_max)
right_pts = self.make_line_points(right_avg, y_min, y_max)

return self.draw_lane(frame, left_pts, right_pts)

def average_slope_intercept(self, lines):
left_lines = []
right_lines = []
if lines is None: return None, None
for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(frame_with_lane, (x1, y1), (x2, y2), (0, 255, 0), 3)

return frame_with_lane

# ===================== 核心函数:视频处理 =====================
def process_video(video_path, max_frames=10):
"""处理单视频:读取帧→检测车道线→保存结果"""
# 校验视频文件
if not os.path.exists(video_path):
print(f"错误:视频文件不存在 → {video_path}")
return

# 打开视频流
cap = cv2.VideoCapture(video_path)
if x2 == x1: continue
slope = (y2 - y1) / (x2 - x1)
intercept = y1 - slope * x1
if abs(slope) < 0.3 or abs(slope) > 10: continue
if slope < 0: left_lines.append((slope, intercept))
else: right_lines.append((slope, intercept))
left_avg = np.average(left_lines, axis=0) if left_lines else None
right_avg = np.average(right_lines, axis=0) if right_lines else None
return left_avg, right_avg

def smooth_lines(self, left_current, right_current):
if left_current is not None: self.left_lines_buffer.append(left_current)
if right_current is not None: self.right_lines_buffer.append(right_current)
left_smooth = np.average(self.left_lines_buffer, axis=0) if self.left_lines_buffer else None
right_smooth = np.average(self.right_lines_buffer, axis=0) if self.right_lines_buffer else None
return left_smooth, right_smooth

def make_line_points(self, line, y_min, y_max):
if line is None: return None
slope, intercept = line
if abs(slope) < 1e-3: return None
try:
x_min = int((y_min - intercept) / slope)
x_max = int((y_max - intercept) / slope)
return ((x_min, y_min), (x_max, y_max))
except: return None

def draw_lane(self, img, left_pts, right_pts):
lane_img = np.zeros_like(img)
if left_pts is not None and right_pts is not None:
pts = np.array([left_pts[0], left_pts[1], right_pts[1], right_pts[0]], dtype=np.int32)
cv2.fillPoly(lane_img, [pts], (0, 255, 0))
if left_pts: cv2.line(lane_img, left_pts[0], left_pts[1], (255, 0, 0), 10)
if right_pts: cv2.line(lane_img, right_pts[0], right_pts[1], (0, 0, 255), 10)
# 注意:这里我们返回 lane_img (纯遮罩),而不是叠加后的图,方便后面统一叠加
return lane_img

def main():
input_source = sys.argv[1] if len(sys.argv) > 1 else "sample.hevc"
cap = cv2.VideoCapture(input_source)
if not cap.isOpened():
print(f"错误:无法打开视频 → {video_path}")
print("无法打开视频")
return

# 获取视频基础信息
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(cap.get(cv2.CAP_PROP_FPS)) or 25

# 初始化结果视频写入器
video_name = Path(video_path).stem
result_path = f"{video_name}_lane_detected.mp4"
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
writer = cv2.VideoWriter(result_path, fourcc, fps, (width, height))

# 逐帧处理
count = 0
print(f"开始处理视频(最大{max_frames}帧)...")
while cap.isOpened() and count < max_frames:

# 1. 初始化两个检测器
lane_detector = LaneDetector()
yolo_detector = ObjectDetector(model_name='yolov8n.pt') # 首次运行会自动下载 6MB 的模型

print("系统启动中...")

while True:
start_time = time.time()
ret, frame = cap.read()
if not ret:
break

# 核心:检测车道线
frame_with_lane = detect_lane_lines(frame)

# 写入结果视频
writer.write(frame_with_lane)

# 实时显示(可选,按Q退出)
cv2.imshow("Lane Detection", frame_with_lane)
if cv2.waitKey(10) & 0xFF == ord('q'):
if not ret:
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
continue

# -----------------------------------------------------
# 步骤 A: 运行 YOLO 车辆检测 (返回画好框的图)
# -----------------------------------------------------
frame_with_cars = yolo_detector.detect(frame)

# -----------------------------------------------------
# 步骤 B: 运行车道线检测 (返回纯车道层)
# -----------------------------------------------------
lane_layer = lane_detector.process_lane(frame)

# -----------------------------------------------------
# 步骤 C: 合并图层
# -----------------------------------------------------
# 将半透明车道层 叠加到 画了车的图上
final_result = cv2.addWeighted(frame_with_cars, 1, lane_layer, 0.4, 0)

# 计算并显示 FPS
fps = 1.0 / (time.time() - start_time)
cv2.putText(final_result, f"FPS: {fps:.1f}", (20, 50),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2)

cv2.imshow('AutoPilot System V2.0', final_result)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

count += 1

# 释放资源

cap.release()
writer.release()
cv2.destroyAllWindows()
print(f"处理完成!结果保存至 → {result_path}")

# ===================== 主函数(精简参数) =====================
if __name__ == "__main__":
# 简化命令行参数:仅保留输入视频、最大帧数
parser = argparse.ArgumentParser(description="车道线检测(精简版)")
parser.add_argument("video_path", type=str, help="输入视频文件路径")
parser.add_argument("--max-frames", type=int, default=10, help="最大处理帧数(默认10)")
args = parser.parse_args()

# 执行核心逻辑
process_video(args.video_path, args.max_frames)
main()
31 changes: 22 additions & 9 deletions src/Drone_hand_gesture_project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# 导入自定义模块
try:
from gesture_detector_enhanced import EnhancedGestureDetector

print("✅ 导入增强版手势检测器 (机器学习)")
HAS_ENHANCED_DETECTOR = True
except ImportError:
print("⚠️ 未找到增强版检测器,使用原始手势检测器")
from gesture_detector import GestureDetector

HAS_ENHANCED_DETECTOR = False

from drone_controller import DroneController
Expand Down Expand Up @@ -246,11 +248,11 @@ def _gesture_recognition_loop(self):
# 虚拟模式
frame = np.ones((480, 640, 3), dtype=np.uint8) * 255
cv2.putText(frame, "虚拟摄像头模式", (50, 50),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.putText(frame, f"手势指令 ({mode_text}):", (50, 100),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 100, 0), 2)
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 100, 0), 2)
cv2.putText(frame, "张开手掌 - 起飞", (50, 140),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)
cv2.putText(frame, "握拳 - 降落", (50, 170),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)
cv2.putText(frame, "胜利手势 - 前进", (50, 200),
Expand Down Expand Up @@ -428,6 +430,10 @@ def _simulation_loop(self):
frame_count = 0
last_status_print = time.time()

# 帧率控制
target_fps = 60
frame_delay = 1.0 / target_fps

print("\n🎮 键盘提示:按 'R' 键重置无人机位置到原点")
print(" 按 'T' 键手动起飞")
print(" 按 'L' 键手动降落")
Expand All @@ -437,10 +443,16 @@ def _simulation_loop(self):
self._last_key_press = {}

while self.running:
start_time = time.time()
current_time = time.time()
dt = current_time - last_time
last_time = current_time

if dt <= 0:
dt = frame_delay
elif dt > 0.1:
dt = 0.1

# 每3秒打印一次状态
if current_time - last_status_print > 3:
status = self.drone_controller.get_status_string()
Expand All @@ -449,11 +461,6 @@ def _simulation_loop(self):
print(f"[状态监控] 当前手势: {self.current_gesture} (置信度: {self.gesture_confidence:.2f})")
last_status_print = current_time

if dt <= 0:
dt = 0.016
elif dt > 0.1:
dt = 0.1

if self.paused:
if not self.viewer.handle_events():
self.running = False
Expand Down Expand Up @@ -526,9 +533,15 @@ def _simulation_loop(self):

self.viewer.render(drone_state_with_gesture, trajectory)

# 控制帧率,避免CPU占用过高
elapsed = time.time() - start_time
sleep_time = frame_delay - elapsed
if sleep_time > 0:
time.sleep(sleep_time)

frame_count += 1
if frame_count % 120 == 0:
fps = 1.0 / dt if dt > 0 else 0
fps = 1.0 / (time.time() - start_time) if start_time > 0 else 0
print(f"3D仿真帧率: {fps:.1f} FPS")

print("3D仿真线程结束")
Expand Down
Loading
Loading