用opencv绘制一个箭头,沿着圆运动并留下运动轨迹(c++)

用opencv绘制一个箭头,沿着圆运动并留下运动轨迹(c++)。基于该例程可以简单实现一个运动小车的模型。

cpp 复制代码
using namespace cv;

int main()
{
    // 创建一个黑色背景的图像,大小为400*400
    Mat image(400, 400, CV_8UC3, Scalar(0, 0, 0));

    //设置箭头的初始位置和方向
    Point2f arrow_center(200, 200);  //箭头中心点
    double arrow_angle = 0.0;        //箭头角度(弧度)

    // 循环处理每帧图像
    while (true) {
        // 旋转箭头
        arrow_angle += 0.1;
        if (arrow_angle >= 2 * CV_PI) {
            arrow_angle -= 2 * CV_PI;
        }

        // 计算箭头的头和尾位置
        Point2f arrow_head(arrow_center.x + 50 * cos(arrow_angle),
            arrow_center.y + 50 * sin(arrow_angle));
        Point2f arrow_tail(arrow_center.x - 50 * cos(arrow_angle),
            arrow_center.y - 50 * sin(arrow_angle));

        // 绘制箭头
        arrowedLine(image, arrow_tail, arrow_head, Scalar(0, 0, 255), 3);

        // 将箭头中心向前移动10个像素
        arrow_center.x += 10 * cos(arrow_angle);
        arrow_center.y += 10 * sin(arrow_angle);

        // 如果箭头越过边界,则将其移回中央
        if (arrow_center.x < 0 || arrow_center.y < 0 ||
            arrow_center.x > image.rows || arrow_center.y > image.cols) {
            arrow_center.x = image.cols / 2;
            arrow_center.y = image.rows / 2;
        }

        // 如果应该闪烁,将箭头颜色改为绿色,否则为红色


        // 显示图像
        imshow("Arrow", image);

        // 等待一会儿
        waitKey(100);
        //if ((int)(arrow_angle / CV_PI * 5) % 2 == 0) {
            arrowedLine(image, arrow_tail, arrow_head, Scalar(0, 255, 0), 3);
        //}
        imshow("Arrow", image);
    }

    return 0;
}
相关推荐
视***间6 小时前
视程空间全系列产品解析:以边缘算力为核,铸就全场景智能硬件标杆
人工智能·机器人·边缘计算·智能硬件·视程空间
微学AI6 小时前
内网穿透的应用-随时随地用 OpenClaw!cpolar 内网穿透,打造你的专属随身 AI
人工智能
Alsian6 小时前
Day 42 通道注意力
人工智能·深度学习·机器学习
郝学胜-神的一滴6 小时前
循环队列深度剖析:从算法原理到C++实现全解析
开发语言·数据结构·c++·算法·leetcode
九硕智慧建筑一体化厂家6 小时前
什么是楼宇自控?全面解析楼宇自控与楼宇自控系统的作用
大数据·运维·人工智能·网络协议·制造
Dxy12393102166 小时前
深度学习的优雅收尾:PyTorch中PolynomialLR的终极指南
人工智能·pytorch·深度学习
云境筑桃源哇6 小时前
极光EngageLab 发布 OpenClaw Skills
人工智能
tjl521314_216 小时前
深度学习与医学图像分割论文写作:统一符号、公式与 LaTeX 规范(附模板)
人工智能·深度学习
FirstFrost --sy6 小时前
仿mudou库one thread one loop式并发服务器实现
运维·服务器·开发语言·c++
csdn_aspnet6 小时前
使用 C# 和 Microsoft Agent Framework 构建 AI 代理
人工智能·microsoft·ai·c#·.net·agent·ai agent