使用 OpenCV C++ 界面是否需要释放使用 VideoCapture 创建的相机捕获(int 设备?

Using OpenCV C++ interface do i need to release camera capture created with VideoCapture(int device?)

本文关键字:相机 创建 设备 int VideoCapture 界面 C++ OpenCV 是否 释放 使用      更新时间:2023-10-16

文档什么也没说...但是这个,但 cvCapture 是 C 类型。

" 注意

In C API, when you finished working with video, release
 CvCapture structure with      cvReleaseCapture(), or 
use Ptr<CvCapture> that calls cvReleaseCapture() automa
tically in the destructor."

我认为视频捕获是一个对象,所以不是吗?

VideoCapture 的析构函数是

VideoCapture::~VideoCapture() 
{
    cap.release();
}

所以没有必要释放它。

如果你想在不破坏在 VideoCapture 对象上调用 release() 方法的对象的情况下释放,你会得到同样的效果:

void VideoCapture::release()
{
    cap.release();
}