0

I've run this 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;
}

It works fine, but after the application closes, the camera remains active. I know this because the flash led stays on until I kill the HPMediaSmartWebcam.exe process.

How do I close the camera after I've finished using VideoCapture?

1
  • 1
    It seems to be an issue with the way the camera driver is implemented. Probably nothing to do with OpenCV. You may try a hackish approach and kill that process programatically before exiting your app. But make sure it can be started correctly again.
    – Sam
    Dec 13, 2012 at 15:36

1 Answer 1

0

According to the docs...here the camera will be deinitializd automatically in the class destructor...the destructor calls a virtual function cv::VideoCapture.release()...run the camera for a fixed number of frames and then see whether the LED of the webcam goes off or not..

int frames = 0;

while(frames!=1000)
{
  //do frame capture from webcam and image processing...
  ++frames;
}
3
  • didn't work. I also think that the opencv buffer shouldn't hold the camera active even if it still holds frames. Dec 14, 2012 at 13:00
  • I ran your code with opencv 2.4.3...I have a Dell Integrated Webcam...your code is working fine with the webcam LED turning off with and without a number of frames constraint...try adding the line cap.release() after the while loop... Dec 14, 2012 at 13:17
  • already tried that, no luck... I guess it's something with the HP driver Dec 14, 2012 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.