【问题标题】:how to draw a line in a video with opencv 3.0.0 using c++如何使用 c++ 在带有 opencv 3.0.0 的视频中画一条线
【发布时间】:2017-05-13 18:23:39
【问题描述】:

如果您有任何源代码,请让我知道,如果您有使用 c++ 使用 opencv 3.0.0 在视频中画线的源代码 亲切地

【问题讨论】:

    标签: visual-c++ opencv3.0


    【解决方案1】:

    首先,您应该考虑到视频基本上只是一些快速显示的图像。因此,您只需要知道如何在图像上画一条线以在视频中绘制它(对每一帧都做同样的事情)。 cv::line 函数记录在这里:http://docs.opencv.org/3.0-beta/modules/imgproc/doc/drawing_functions.html

    int main(int argc, char** argv)
    {
        // read the camera input
        VideoCapture cap(0);
    
        if (!cap.isOpened())
            return -1;
        Mat frame;
    
        /// Create Window
        namedWindow("Result", 1);
        while (true) {
    
            //grab and retrieve each frames of the video sequentially 
            cap >> frame;
            //draw a line onto the frame
            line(frame, Point(0, frame.rows / 2), Point(frame.cols, frame.rows / 2), Scalar(0), 3);
            //display the result
            imshow("Result", frame);
            //wait some time for the frame to render
            waitKey(30);
        }
        return 0;
    }
    

    这将在您的网络摄像头的视频源上绘制一条水平的黑色 3 像素粗线。

    【讨论】:

    • 如果我想添加另一条与另一条平行的线并更改线的颜色?我可以为这个源代码添加什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-20
    • 2014-03-01
    • 1970-01-01
    • 2014-01-03
    • 2013-09-09
    • 2020-05-11
    相关资源
    最近更新 更多