Question

Good Day,

I am trying to figure out how to close the camera on a beaglebone in openCV. I have tried numerous commands such as release(&camera) but none exist and the camera continues to stay on when I don't want it to.

VideoCapture capture(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH,320);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,240);
if(!capture.isOpened()){
     cout << "Failed to connect to the camera." << endl;
}
Mat frame, edges, cont;

while(1){
    cout<<sending<<endl;
    if(sending){
        for(int i=0; i<frames; i++){
            capture >> frame;
            if(frame.empty()){
            cout << "Failed to capture an image" << endl;
            return 0;
            }
            cvtColor(frame, edges, CV_BGR2GRAY);

Code is something like this, at the end of the for loop, I want to close the camera, but of course it still stays open

Was it helpful?

Solution

The camera will be deinitialized automatically in VideoCapture destructor.

Check this example from opencv docu:

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        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;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

Also

cvQueryFrame

Grabs and returns a frame from camera or file

IplImage* cvQueryFrame( CvCapture* capture );

capture video capturing structure.

The function cvQueryFrame grabs a frame from camera or video file, decompresses and > returns it. This function is just a combination of cvGrabFrame and cvRetrieveFrame in one > call. The returned image should not be released or modified by user.

Also check: http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/

I hope this works for you. Best of luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top