【问题标题】:how to draw a circle in video如何在视频中画一个圆圈
【发布时间】:2015-09-11 00:23:34
【问题描述】:

我试图在我的网络摄像头的视频中画一个圆圈我使用这个功能

 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;

}

【问题讨论】:

  • 在框架上画圆圈(而不是帽子),然后将 imshow 移动到圆圈之后

标签: c++ opencv video opencv3.0


【解决方案1】:

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

因此,将代码中的 imshow / circle 部分替换为:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-12
    • 2014-11-15
    • 1970-01-01
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多