调用VideoCapture析构函数后,摄像头保持活动状态

时间:2012-12-13 14:29:25

标签: opencv

我已经运行了sample code

#include "cv.h"
#include "highgui.h"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0);
    if(!cap.isOpened()) return -1;

    Mat frame, edges;
    namedWindow("edges",1);
    for(;;)
    {
        cap >> frame;
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
        if(waitKey(30) >= 0) break;
    }
    return 0;
}

它工作正常,但在应用程序关闭后,相机仍然有效。我知道这一点,因为闪存导致一直持续到我杀死HPMediaSmartWebcam.exe进程。

使用完VideoCapture后如何关闭相机?

1 个答案:

答案 0 :(得分:0)

根据文档... here,相机将在类析构函数中自动取消初始化...析构函数调用虚函数cv::VideoCapture.release()...运行相机以获得固定数字框架,然后看看网络摄像头的LED是否熄灭..

int frames = 0;

while(frames!=1000)
{
  //do frame capture from webcam and image processing...
  ++frames;
}