You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于像素变化求解无人机跟踪目标的横滚角与俯仰角

问题:无人机图像制导中像素偏移到横滚/俯仰角的转换

我正在为无人机编写基于图像的制导程序,图像检测与跟踪算法已正常运行,但为实现前方目标车辆的跟踪,需根据其移动产生的像素变化求解横滚角和俯仰角,该如何完成这一转换?

参考代码如下:

def convert_pixel_to_angle(x, y, image_width, image_height, fov_width, fov_height):
    center_x = image_width / 2
    center_y = image_height / 2
    dx = x - center_x
    dy = y - center_y
    angle_x = (dx / image_width) * 2 * fov_width
    angle_y = (dy / image_height) * 2 * fov_height
    return angle_x, angle_y;

注:完整代码还会包含卡尔曼滤波等算法,仅需实现基于图像像素变化获取跟踪目标的横滚角与俯仰角。


解决方案

核心逻辑说明

像素到角度的转换依赖相机的视场角(FOV)参数,需提前获取相机的水平视场角(FOV Horizontal)和垂直视场角(FOV Vertical),可从相机规格手册获取或通过标定得到。图像中心对应无人机视场的中心(0角度),目标的像素偏移量与角度偏移量呈线性映射关系。

修正后的转换函数

原参考代码的角度计算逻辑存在错误,正确的转换应基于像素偏移占半幅图像的比例映射到半视场角,实现如下:

def pixel_to_angles(target_x, target_y, img_width, img_height, fov_horizontal, fov_vertical):
    # 计算图像中心坐标
    center_x = img_width / 2.0
    center_y = img_height / 2.0
    
    # 计算目标相对于图像中心的像素偏移
    offset_x = target_x - center_x
    offset_y = target_y - center_y
    
    # 计算横滚角(水平方向角度)
    roll_angle = (offset_x / (img_width / 2.0)) * (fov_horizontal / 2.0)
    # 计算俯仰角(垂直方向角度)
    pitch_angle = (offset_y / (img_height / 2.0)) * (fov_vertical / 2.0)
    
    return roll_angle, pitch_angle

基于像素变化量计算角度变化

若要通过目标的像素移动量得到角度调整量,只需对前后两帧的目标坐标分别计算角度,再求差值即可:

# 示例:t1时刻目标坐标(x1, y1),t2时刻坐标(x2, y2)
roll_prev, pitch_prev = pixel_to_angles(x1, y1, img_width, img_height, fov_h, fov_v)
roll_curr, pitch_curr = pixel_to_angles(x2, y2, img_width, img_height, fov_h, fov_v)

# 角度变化量(用于无人机姿态调整)
delta_roll = roll_curr - roll_prev
delta_pitch = pitch_curr - pitch_prev

符号说明

  • 横滚角:目标在图像中心右侧时为正(无人机需向右横滚),左侧为负
  • 俯仰角:目标在图像中心下方时为正(无人机需向下俯仰),上方为负;可根据实际控制逻辑调整符号方向

内容的提问来源于stack exchange,提问作者Necati Aziz Mahmut FERAH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 14:22:48