用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;
}
相关推荐
IT_陈寒1 小时前
用了Proxy才发现以前的JavaScript白写了
前端·人工智能·后端
甲维斯1 小时前
Claude Opus5手搓“NewAPI Plus”首轮成果!
人工智能
程序猿DD1 小时前
分享两个我每天都在用的 Skill,拖进豆包就能跑,限时领 30 天会员
人工智能
程与留2 小时前
15_国际化和本地化:tr()、ts 文件、QM 文件、多语言切换
c++·qt
阿里云大数据AI技术2 小时前
Agentic Search 2.0:从单轮对话迈向企业级 AI 搜索自动驾驶Agent
人工智能·elasticsearch·agent
东风破_2 小时前
从 messages 数组到 Memory:大模型到底是怎么“记住”上一轮对话的?
人工智能
AEI2 小时前
四年间大模型的演进历程
人工智能·面试·程序员
狂师3 小时前
阿里开源:skill-up,一款Agent Skill 评测工具!
人工智能·开源·agent
武子康3 小时前
同一套 Agent Runtime,为什么 Web、Headless 和 Python SDK 仍然不是同一个产品
人工智能·llm·agent
天天代码码天天3 小时前
一个纯 C 的 OCR Runtime,又向前走了一步:lw.PPOCR.C preview.5 发布
人工智能