在opencv中,什么是视频攻击器

In OpenCV what is the VideoCapture destructor

本文关键字:视频 攻击 什么 opencv      更新时间:2023-10-16

在videocapture ::文档中的链接中%3AREAD#VIDEOCAPTURE-REELE

它说这条线

"这些方法是通过随后的视频仪式自动调用的:: open()和通过视频攻击器。"

我希望有人能告诉我视频关注灾难源是我谷歌搜索的内容,但没有确切的答案...我敢肯定,它在某些通常的视频仪功能下自动称呼它,但是如果有人可以告诉我什么完全是,当它完全被调用和在源中,我将最感激=)。

这很容易。一旦对象离开范围,攻击器就会被调用。

{ // the capture only lives inside those brackets
    VideoCapture cap;
    if ( cap.open() )
    {  
        //... do some work 
    }
} // here it will release itself

如果您尝试自己的课程,也许会变得更加明显:

class MyClass 
{
public:
    MyClass()  { cerr << "created MyClass" << endl; }    // constructor
    ~MyClass() { cerr << "destroyed MyClass" << endl; }  // destructor
};

void foo()
{ // scope starts
    MyClass mc;
    int z=17;
    z *= 3;
    cerr << z << endl;
} // scope ends, mc will get destroyed.
int main()
{
    return foo();
}

destructor是类的方法,当类的实例脱离范围或使用delete关键字发布的内存时,称为类型。Destructor有一个名称,该名称从~

在这种特殊情况下,如果方法~VideoCapture,则在以下情况下称为:

// One case
{
VideoCapture vc;
} // <- here ~VideoCapture called as it goes out of scope
// Another one
VideoCapture *vc = new VideoCapture();
delete vc; //<- here ~VideoCapture called as it is being deleted
// One more
{
    std:unique_ptr<VideoCapture> vc = std::make_unique<VideoCapture>();
} // <- here ~VideoCapture called as its handler goes out of scope