Ask Your Question
0

capture vidio from 2 cameras

asked Dec 2 '12

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Hi OpenCV. I tryed to capture vidio from 2 cameras but only one camera works, and the other one shows a green screen. Please Help Me!

My system:

#include stdafx.h
#include highgui.h
#include stdio.h 
#include dshow.h

int main()
{ 
CvCapture* capture1 = cvCaptureFromCAM(CV_CAM_ANY);
CvCapture* capture2 = cvCaptureFromCAM(CV_CAM_ANY);

if ( !capture1 )
{
fprintf( stderr, "ERROR: capture1 is NULL \n" );
getchar();
return -1;
}

if ( !capture2 )
{
fprintf( stderr, "ERROR: capture2 is NULL \n" );
getchar();
return -1;
}

cvNamedWindow( "cam1");
cvNamedWindow( "cam2");

while (1)
{    
IplImage* frame1 = cvQueryFrame( capture1 );
IplImage* frame2 = cvQueryFrame( capture2 );
if ( !frame1 )
{
fprintf( stderr, "ERROR: frame1 is null...\n" );
getchar();
break;
}

if (!frame2 )
{
fprintf( stderr, "ERROR: frame2 is null...\n" );
getchar();
break;
}

cvShowImage( "cam1", frame1 );
cvShowImage( "cam2", frame2 );
if ( (cvWaitKey(10) & 255) == 27 ) break; 
}
cvReleaseCapture( &capture1 ); 
cvDestroyWindow( "cam1" );
cvReleaseCapture( &capture2 );

cvDestroyWindow( "cam2" );
return 0;
}
Preview: (hide)

2 answers

Sort by » oldest newest most voted
2

answered Dec 2 '12

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

I think you should use explicit camera index (0, 1) in the place of the two cvCaptureFromCAM(CV_CAM_ANY); calls.

Preview: (hide)

Comments

It isn't works. but thank you :)

shelly gravatar imageshelly (Dec 3 '12)edit

You have more ideas?

shelly gravatar imageshelly (Dec 3 '12)edit

May be this (http://stackoverflow.com/questions/7322939/how-to-count-cameras-in-opencv-2-3) stackoverflow question could help you. It is about checking connected cameras.

rics gravatar imagerics (Dec 4 '12)edit
0

answered Dec 3 '12

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Had a problem using Ubuntu 12.04, the fix was to put the 2 cams on to 2 different Usb Buses. Maybe this could help under Windows too.

Preview: (hide)

Comments

Thank you! It is working. But when I stop the program, the problem is coming back...

shelly gravatar imageshelly (Dec 3 '12)edit

Question Tools

Stats

Asked: Dec 2 '12

Seen: 1,205 times

Last updated: Dec 04 '12