TasostheGreat
TasostheGreat

Reputation: 442

opencv close camera

ok I have this code

IplImage *frame;
CvCapture *capture = cvCaptureFromCAM(0);
frame = cvQueryFrame(capture);
cvSaveImage("sample.jpg",frame);
cvReleaseImage(&frame);

which saves an image, but after saving that image, I want to release that camera so that it closes. Now the camera stays on until the program stops, I want to relase and close the camera exactly after cvReleaseImage(&frame);

I tried

cvReleaseCapture(&capture)

but it gives me a runtime error: the application has requested the Runtime to terminate in an unusual way and this error

OpenCV Error: Bad argument (unrecognized or unsupported array type) in unknown function, file ......\modules\core\src\array.cpp, line 996

Upvotes: 0

Views: 3740

Answers (3)

Genís
Genís

Reputation: 1508

I think that what you're looking for is cvReleaseCapture. There's the code that worked for me:


int main (void) {

  IplImage *frame;
  CvCapture *capture = cvCaptureFromCAM(0);
  frame = cvQueryFrame(capture);
  cvSaveImage("sample.jpg",frame);
  cvReleaseImage(&frame);
  cvReleaseCapture( &capture );

  return 0;
}

It's a quite a simple code, but it should terminate properly, without any error raised.

Upvotes: 0

DeyyyFF
DeyyyFF

Reputation: 953

I am not completely sure. But try removing the cvReleaseImage call.

I remember that the image-pointer retrieved by the cvQueryImage method points allways at the same adress. so my guess is that this image-data is managed by the capture. so releasing it is done when you release the capture.

EDIT:

found here: http://opencv.jp/opencv-1.0.0_org/docs/ref/opencvref_highgui.htm

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.

Upvotes: 3

BlueDog
BlueDog

Reputation: 976

Tried cvReleaseCapture()? (30 characters.)

Upvotes: 0

Related Questions