PDA

View Full Version : How to Display Multi Webcam with QT + OpenCV + Eclipse?



thaihoangluu
28th December 2011, 02:02
hi everybody
I am using two Logitech Webcam. But at my first stage I am unable to view image from 2 webcam

i used QT as my platform

I used the openCv function as follows:


CvCapture *cam1;//structure where camera link is stored
CvCapture *cam2;
cam1 = cvCaptureFromCAM(2);
cam2 = cvCaptureFromCAM(1);

cvSetCaptureProperty(cam1, CV_CAP_PROP_FRAME_WIDTH, 640);
cvSetCaptureProperty(cam1, CV_CAP_PROP_FRAME_HEIGHT, 480);

cvSetCaptureProperty(cam2, CV_CAP_PROP_FRAME_WIDTH, 640);
cvSetCaptureProperty(cam2, CV_CAP_PROP_FRAME_HEIGHT, 480);

cvSetCaptureProperty(cam1, CV_CAP_PROP_FPS, 8);
cvSetCaptureProperty(cam2, CV_CAP_PROP_FPS, 8);

IplImage *frame1, *frame2;

while(1)
{

frame1 = cvQueryFrame(cam1);
frame2 = cvQueryFrame(cam2);

cvShowImage("Left", frame1);
cvShowImage("Right",frame2);
char k;
if(k==27)
break;
}
cvReleaseCapture(&cam1);
cvReleaseCapture(&cam2);
cvDestroyAllWindows();
WHY when I Run Program It show Dialog tell me choose 1 in 2 Webcam?????
7206

But here I get image frames from one camera only.
how can I solve the problem.....Is it the bandwidth problem??
I am using windows 7. Please help me.
Thanks.

ChrisW67
28th December 2011, 05:52
This question has nothing to do with Qt or Eclipse.

I assume that is Microsoft's dialog, presumably asking you to set the default camera for Windows.

As for opening two separate cameras with OpenCV, I would bet that the first two cameras are numbered 0 and 1 not 1 and 2. Your calls to cvCameraCapture() should change to reflect this.

Incidentally, what is going to set a value on 'k' between line 25 and 26?

thaihoangluu
28th December 2011, 06:14
#include <stdio.h>
#include "cv.h"
#include "highgui.h"


int main( int argc, char **argv )
{




CvCapture *capture = 0;
CvCapture *capture1 =0;
IplImage *frame = 0;
IplImage *frame1=0;
int key = 0;
/* initialize camera */
capture = cvCaptureFromCAM( 0 );
capture = cvCaptureFromCAM( 1 );

/* always check */
// if ( !capture ) {
// fprintf( stderr, "Cannot open initialize webcam!\n" );
// return 1;
// }
//
// if ( !capture1 ) {
// fprintf( stderr, "Cannot open initialize webcam!\n" );
// return 1;
// }
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);

cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_WIDTH, 640);
cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_HEIGHT, 480);

cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 8);
cvSetCaptureProperty(capture1, CV_CAP_PROP_FPS, 8);
/* create a window for the video */
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );

while( key != 'q' ) {
/* get a frame */
frame = cvQueryFrame( capture );
frame1 = cvQueryFrame( capture1 );
/* always check */
// if( !frame ) break;
// if( !frame1 ) break;

/* display current frame */


cvShowImage("Left", frame);
cvShowImage("Right",frame1);



/* exit if user press 'q' */
key = cvWaitKey( 1 );
}

/* free memory */
cvDestroyWindow( "result" );
cvDestroyWindow( "result1" );
cvReleaseCapture( &capture );
cvReleaseCapture( &capture1 );

return 0;
}


It's not RUN :(

ChrisW67
28th December 2011, 07:42
This question still has nothing to do with Qt

You never initialise capture1 with a valid, non-NULL pointer so you are probably going to crash the program at line 34 when you first use that pointer. If you had not commented out the checks between line 22 and 30 you would have known this.

You only create a single display window called "result", and then try to output two video streams to windows called "Left" and "Right" (which don't exist), and finally clean up a two windows called "result" (which exist) and "result1" (which does not).

thaihoangluu
28th December 2011, 09:39
This question still has nothing to do with Qt

You never initialise capture1 with a valid, non-NULL pointer so you are probably going to crash the program at line 34 when you first use that pointer. If you had not commented out the checks between line 22 and 30 you would have known this.

You only create a single display window called "result", and then try to output two video streams to windows called "Left" and "Right" (which don't exist), and finally clean up a two windows called "result" (which exist) and "result1" (which does not).
Okay, Thank you very much, can you share code for Multi webcam Display on multi QLabel?
And resolve error when i start program http://www.qtcentre.org/attachment.php?attachmentid=7206&d=1325038879
THANKs

ChrisW67
28th December 2011, 21:18
Okay, Thank you very much, can you share code for Multi webcam Display on multi QLabel?
No. I have never done any OpenCV programming to share. Everything I am telling you comes from a brief scan of the OpenCV documentation and the example here (http://opencv.willowgarage.com/wiki/CameraCapture). Thread 45669 shows one way to convert an OpenCV frame buffer into a QImage/QPixmap that you can use with a QLabel. It also offers an alternate approach.

And resolve error when i start program
Select one. If it keeps asking then you might need to ask in an OpenCV forum why OpenCV triggers this behaviour in Windows and how to avoid it.

thaihoangluu
29th December 2011, 03:02
how to display multi camera in multi Qlabel on QT :D

Thành Viên Mới
31st January 2012, 15:19
how to display multi camera in multi Qlabel on QT :D

open by 0,1,2, with 0 = default, 1 = webcam 1, 2 = webcam2