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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…