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


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

    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
  • 相关阅读:
    UNext:基于 MLP 的快速医学图像分割网络
    ACK 思维导图
    P4316 绿豆蛙的归宿 ( 拓扑 + 期望dp
    【mmCEsim】开源项目预告:毫米波信道估计仿真软件
    【深度学习】实验06 使用TensorFlow完成线性回归
    【JAVA】值传递与引用传递
    通用工作站设计方案 :807-ORI-S3R500 -多路PCIe3.0的单CPU通用工作站
    电脑如何激活windows
    Navicat导入SQL文件
    数据结构之二叉树(前提知识)
  • 原文地址:https://blog.csdn.net/LW_12345/article/details/134593213