繁体   English   中英

在OpenCV中,VideoCapture析构函数是什么

[英]In OpenCV what is the VideoCapture destructor

在VideoCapture :: Release - C ++文档中的链接http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture%3A%3Aread#videocapture-release

它说这条线

“这些方法由后续的VideoCapture :: open()和VideoCapture析构函数自动调用。”

我希望有人可以告诉我VideoCapture析构函数究竟是什么我用Google搜索但没有明确的答案...我确定它会在某些指定时间通过常见的VideoCapture函数自动调用但是如果有人可以告诉我它究竟是什么,当它完全被调用时,在源中的位置,我将是最感性的=)。

析构函数是一个类的方法,当类的实例超出范围或使用delete关键字释放内存时调用该方法。 析构函数有一个名称,从~开始。

在这种特殊情况下,如果方法~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

这很容易。 一旦对象离开范围,析构函数就会被调用。

{ // 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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM