如何在opencv视频中添加圆圈/圆点?

时间:2015-01-09 15:10:02

标签: c++ opencv video

我有一个逗号分隔的值文件x& y坐标。我需要在摄像机的opencv视频上放置一个圆点/圆圈,并使用逗号分隔值文件中的x y坐标进行跟踪。我有显示相机的代码:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // open the video camera no. 0

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

    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

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

    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 a frame from video stream" << endl;
             break;
        }

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

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

1 个答案:

答案 0 :(得分:0)

您的网络摄像头捕获的帧只是一张图像。因此,您可以像对待单张图片一样,在网络摄像头视频中放置一个圆圈。

以下是在图片上放置圆圈的openCV方法:

void circle(Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

例如:

circle(frame, Point2i(x-coordinate, y-coordinate), 5, Scalar(0,125,230), 4, 3);