如何在视频中画一个圆圈

how to draw a circle in video

我正在尝试在我使用此功能的网络摄像头的视频中画一个圆

 cv::circle(cap,points(1,0),3,cv::Scalar(255,255,255),-1);

我在文档中找到它,但我不知道为什么它不起作用我多次编辑我的代码但它仍然给我错误,这是我使用 opencv3 的完整代码

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>
#include <iostream>
#include <sstream>
#include <opencv2/video/background_segm.hpp>  
#include <opencv2/video/background_segm.hpp>

using namespace cv;
using namespace std;



int main()
{
    VideoCapture cap(0); // open the video file for reading

    if ( !cap.isOpened() )  // if not success, exit program
    {
         cout << "Cannot open the video file" << endl;
         return -1;
    }

    //cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

    double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

     cout << "Frame per seconds : " << fps << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    while(1)
    {
        Mat frame;

        bool bSuccess = cap.read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
        {
                        cout << "Cannot read the frame from video file" << endl;
                       break;
        }

        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        cv::circle(cap,points(1,0),3,cv::Scalar(255,255,255),-1);

        if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
       {
                cout << "esc key is pressed by user" << endl; 
                break; 
       }
    }

    return 0;

}

circle 接受 Mat 对象,而不是 VideoCapture 对象。所以你需要在 frame 上画圆圈。 另外你需要在实际画完圆后显示图像。

所以将代码的 imshow / circle 部分替换为:

...
cv::circle(frame, points(1,0), 3, cv::Scalar(255,255,255), -1);
imshow("MyVideo", frame);
...