c++ - 在 OpenCV 中什么是 VideoCapture 析构函数

标签 c++ opencv

在 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/

相关文章:

c++ - 解释为什么第二次分配会改变性能

c++ - 可能的 Qt5 错误 : calling setFixedSize() disables the main window's close button (under Win7)

c++ - 找到找到的圆opencv的半径

c++ - 使用pcl transformcloud将3d点平移并旋转到原点

c++ - 将侧面图像与其正面图像对齐

c++ - 如何将稀疏矩阵乘以具有特征的密集矩阵?

c++ - 我用 winsock2 在 C++ 中做了一个简单的套接字,我把 recv 函数放到一个变量中,它给出了一些奇怪的符号

c++ - 私有(private)嵌套类 c++ 的实例

python - 从源文件构建 OpenCV 库

opencv - 如何在openCV中的图像上绘制不同的形状?