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

Hey,

I just run the code and can confirm it works fine.

On my mac the "Video" window was hiding behind my IDE and the "ball" window was visible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.