Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

visual c++ - how to draw a line in a video with opencv 3.0.0 using c++

Please let me know if you have any If you have a source code to draw a line in a video with opencv 3.0.0 using c++ cordially

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First of all you should consider that a video is basicly just some images displayed quickly after each other. Therefor you only need to know how to draw a line onto an image to draw it in a video (do the same for each frame). The cv::line function is documented here : 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;
}

This will draw a horizontal, black, 3 pixel thick line on the video-feed from your webcam.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...