用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;
}
相关推荐
Dawson Zhu2 分钟前
【AI编译器入门②】TVM架构拆解:Relay、Relax、TIR与Runtime四层结构
人工智能·语言模型·架构·aigc·agi
阿狸猿4 分钟前
AI Agent自动写自动化脚本
运维·人工智能·自动化
云和数据.ChenGuang14 分钟前
项目打开后没有主类
开发语言·人工智能·langchain·1024程序员节
民乐团扒谱机15 分钟前
【读论文】音色在微分音程记忆中的作用
人工智能·深度学习·算法
推送者16 分钟前
立体桌宠定制:一张正脸照到本地九视角标定的工程链路
人工智能·立体桌宠定制
鬼手点金16 分钟前
缓存作为架构约束
开发语言·前端·人工智能·python·microsoft·缓存·架构
lucas_AI18 分钟前
24 天、4310 万行代码:AI 集群啃下了人类史上最长的数学证明
人工智能
SEO_juper21 分钟前
Node.js 页面主题聚焦度检测:title 和正文各说各的,AI 也读不懂
开发语言·人工智能·node.js·seo·外贸独立站
IT_陈寒21 分钟前
React实战技巧总结:如何优雅处理复杂列表的渲染卡顿问题?
前端·人工智能·后端
lucas_AI23 分钟前
DeepMind 发布 Genie 4:世界模型会「出声」了,一句话实时改写世界
人工智能·llm