在 VideoCapture::Release 文档中的链接 - C++ here http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture%3A%3Aread#videocapture-release
上面写着这一行
“这些方法由后续的 VideoCapture::open() 和 VideoCapture 析构函数自动调用。”
我希望有人能告诉我 VideoCapture 析构函数到底是什么我用谷歌搜索但没有得到明确的答案......我确定它会在某个特定时间由通常的 VideoCapture 函数自动调用但是如果有人可以告诉我什么确切地说,它的确切调用时间以及它在源代码中的位置,我将非常感激=)。
最佳答案
这很容易。一旦对象离开作用域,就会调用析构函数。
{ // 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();
}
关于c++ - 在 OpenCV 中什么是 VideoCapture 析构函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22266875/