Ask Your Question
0

capture vidio from 2 cameras

asked 2012-12-02 16:03:09 -0500

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;
}
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2012-12-02 16:25:11 -0500

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.

edit flag offensive delete link more

Comments

It isn't works. but thank you :)

shelly gravatar imageshelly ( 2012-12-03 09:54:15 -0500 )edit

You have more ideas?

shelly gravatar imageshelly ( 2012-12-03 10:14:27 -0500 )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 ( 2012-12-04 05:27:03 -0500 )edit
0

answered 2012-12-03 02:18:14 -0500

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.

edit flag offensive delete link more

Comments

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

shelly gravatar imageshelly ( 2012-12-03 10:26:30 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-12-02 16:03:09 -0500

Seen: 1,035 times

Last updated: Dec 04 '12