Results 1 to 8 of 8

Thread: How to Display Multi Webcam with QT + OpenCV + Eclipse?

  1. #1
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default How to Display Multi Webcam with QT + OpenCV + Eclipse?

    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:

    Qt Code:
    1. CvCapture *cam1;//structure where camera link is stored
    2. CvCapture *cam2;
    3. cam1 = cvCaptureFromCAM(2);
    4. cam2 = cvCaptureFromCAM(1);
    5.  
    6. cvSetCaptureProperty(cam1, CV_CAP_PROP_FRAME_WIDTH, 640);
    7. cvSetCaptureProperty(cam1, CV_CAP_PROP_FRAME_HEIGHT, 480);
    8.  
    9. cvSetCaptureProperty(cam2, CV_CAP_PROP_FRAME_WIDTH, 640);
    10. cvSetCaptureProperty(cam2, CV_CAP_PROP_FRAME_HEIGHT, 480);
    11.  
    12. cvSetCaptureProperty(cam1, CV_CAP_PROP_FPS, 8);
    13. cvSetCaptureProperty(cam2, CV_CAP_PROP_FPS, 8);
    14.  
    15. IplImage *frame1, *frame2;
    16.  
    17. while(1)
    18. {
    19.  
    20. frame1 = cvQueryFrame(cam1);
    21. frame2 = cvQueryFrame(cam2);
    22.  
    23. cvShowImage("Left", frame1);
    24. cvShowImage("Right",frame2);
    25. char k;
    26. if(k==27)
    27. break;
    28. }
    29. cvReleaseCapture(&cam1);
    30. cvReleaseCapture(&cam2);
    31. cvDestroyAllWindows();
    To copy to clipboard, switch view to plain text mode 
    WHY when I Run Program It show Dialog tell me choose 1 in 2 Webcam?????
    a.png

    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.
    Last edited by thaihoangluu; 28th December 2011 at 02:21.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to Display Multi Webcam with QT + OpenCV + Eclipse?

    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?

  3. #3
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to Display Multi Webcam with QT + OpenCV + Eclipse?

    Qt Code:
    1. #include <stdio.h>
    2. #include "cv.h"
    3. #include "highgui.h"
    4.  
    5.  
    6. int main( int argc, char **argv )
    7. {
    8.  
    9.  
    10.  
    11.  
    12. CvCapture *capture = 0;
    13. CvCapture *capture1 =0;
    14. IplImage *frame = 0;
    15. IplImage *frame1=0;
    16. int key = 0;
    17. /* initialize camera */
    18. capture = cvCaptureFromCAM( 0 );
    19. capture = cvCaptureFromCAM( 1 );
    20.  
    21. /* always check */
    22. // if ( !capture ) {
    23. // fprintf( stderr, "Cannot open initialize webcam!\n" );
    24. // return 1;
    25. // }
    26. //
    27. // if ( !capture1 ) {
    28. // fprintf( stderr, "Cannot open initialize webcam!\n" );
    29. // return 1;
    30. // }
    31. cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);
    32. cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);
    33.  
    34. cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_WIDTH, 640);
    35. cvSetCaptureProperty(capture1, CV_CAP_PROP_FRAME_HEIGHT, 480);
    36.  
    37. cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 8);
    38. cvSetCaptureProperty(capture1, CV_CAP_PROP_FPS, 8);
    39. /* create a window for the video */
    40. cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
    41.  
    42. while( key != 'q' ) {
    43. /* get a frame */
    44. frame = cvQueryFrame( capture );
    45. frame1 = cvQueryFrame( capture1 );
    46. /* always check */
    47. // if( !frame ) break;
    48. // if( !frame1 ) break;
    49.  
    50. /* display current frame */
    51.  
    52.  
    53. cvShowImage("Left", frame);
    54. cvShowImage("Right",frame1);
    55.  
    56.  
    57.  
    58. /* exit if user press 'q' */
    59. key = cvWaitKey( 1 );
    60. }
    61.  
    62. /* free memory */
    63. cvDestroyWindow( "result" );
    64. cvDestroyWindow( "result1" );
    65. cvReleaseCapture( &capture );
    66. cvReleaseCapture( &capture1 );
    67.  
    68. return 0;
    69. }
    To copy to clipboard, switch view to plain text mode 

    It's not RUN

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to Display Multi Webcam with QT + OpenCV + Eclipse?

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

  5. The following user says thank you to ChrisW67 for this useful post:

    thaihoangluu (28th December 2011)

  6. #5
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to Display Multi Webcam with QT + OpenCV + Eclipse?

    Quote Originally Posted by ChrisW67 View Post
    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
    THANKs
    Nguyá»…n LÆ°u VÅ© - Http://nguyenluuvu.com

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to Display Multi Webcam with QT + OpenCV + Eclipse?

    Quote Originally Posted by thaihoangluu View Post
    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. 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.

  8. The following user says thank you to ChrisW67 for this useful post:

    thaihoangluu (29th December 2011)

  9. #7
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to Display Multi Webcam with QT + OpenCV + Eclipse?

    how to display multi camera in multi Qlabel on QT
    Nguyá»…n LÆ°u VÅ© - Http://nguyenluuvu.com

  10. #8
    Join Date
    Jun 2010
    Posts
    102
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to Display Multi Webcam with QT + OpenCV + Eclipse?

    Quote Originally Posted by thaihoangluu View Post
    how to display multi camera in multi Qlabel on QT
    open by 0,1,2, with 0 = default, 1 = webcam 1, 2 = webcam2
    Contact: Skype: sonnh89
    Yahoo: nhs_0702@yahoo.com

    Liên hệ SKype: sonnh89

Similar Threads

  1. OpenCV Record Webcam And Audio ???
    By Thành Viên Mới in forum Qt Programming
    Replies: 0
    Last Post: 25th December 2011, 04:18
  2. Display webcam stream with phonon and the qt
    By nyquist82 in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2011, 08:03
  3. Replies: 4
    Last Post: 22nd July 2011, 06:40
  4. Replies: 8
    Last Post: 18th March 2011, 11:27
  5. Replies: 2
    Last Post: 15th November 2010, 17:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.