1

I executed a simple C++ program in Visual Studio2010 using OpencV version 2.2 to start the camera and display the video simaltaneously.But the camera gets started and only the window came as output and not the video capture simaltaneously..Here is my code.Is there any error in camera..Do we need to install any softwares..Please suggest as soon as possible.

#include "stdafx.h" #include <cv.h> #include <highgui.h> #include <stdio.h> #include <conio.h> int main() { CvCapture* capture =0; capture = cvCaptureFromCAM(0); if(!capture) { printf("Capture failure\n"); return -1; } IplImage* frame=NULL; cvNamedWindow("Video"); cvNamedWindow ("Ball"); //iterate through each frames of the video while(true) { frame = cvQueryFrame(capture); if(!frame) break; //frame=cvCloneImage(frame); cvShowImage("Video", frame); //Clean up used images cvReleaseImage(&frame); //Wait 50mS int c = cvWaitKey(10); //If 'ESC' is pressed, break the loop if((char)c==27 ) break; } cvDestroyAllWindows() ; //cvReleaseCapture(&capture); return 0; 

}

and there is a warning in the output window is as:

OpenCV Error: Bad argument (unrecognized or unsupported array type) in unknown f unction, file ........\ocv\opencv\modules\core\src\array.cpp, line 995

1
  • @guneykayim.. It is not a solution. Commented Dec 30, 2013 at 7:36

1 Answer 1

4

The error is caused, because you are releasing the frame returned by cvQueryFrame. It is stated in the documentation that only a single image buffer is used by all the frames of the video. So modifying the frame returned by cvQueryFrame will release that buffer and subsequent calls will fail.

To fix the problem, just remove cvReleaseImage(&frame);.

If you want to modify the frame, create a deep copy of the frame by using cvCloneImage.

Also, don't forget to release the capture once you are done.

cvReleaseCapture(&capture); 
Sign up to request clarification or add additional context in comments.

2 Comments

I tried as you said i removed cvReleaseImage(&frame) and i placed cvRelease capture after the line cvDestroyAll statement ..Am i right? still i am not getting..Can you suggest some other.
Or will it run only with 32-bit os?Or if any cybercam already installed has to be removed..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.