1
votes

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.sgarizvi

1 Answers

4
votes

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);