Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

openning multiple webcam

Hey guyes i'm having trouble opening two webcam with version 2.4.6. One webcam is the mounted laptop webcam and the other is a usb webcam.

include "opencv2/highgui/highgui.hpp"

include <iostream>

using namespace cv; using namespace std;

int main(int argc, char* argv[]) { VideoCapture cap(0); // open the video file for reading VideoCapture cap2(1); if ( !cap.isOpened() ) // if not success, exit program { cout << "Cannot open the video file" << endl; return -1; }

if ( !cap2.isOpened() )  // if not success, exit program
{
     cout << "Cannot open the video2 file" << endl;
     return -2;
}
//cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

 cout << "Frame per seconds : " << fps << endl;

namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

while(1)
{
    Mat frame;
    Mat frame2;
    bool bSuccess = cap.read(frame); // read a new frame from video
    bool bSuccess2 = cap2.read(frame2); // read a new frame from video
     if (!bSuccess) //if not success, break loop
    {
                    cout << "Cannot read the frame from video file" << endl;
                   break;
    }

    imshow("MyVideo", frame); //show the frame in "MyVideo" window
    imshow("MyVideo", frame2); //show the frame in "MyVideo" window
    if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
   {
            cout << "esc key is pressed by user" << endl; 
            break; 
   }
}

return 0;

}

openning multiple webcam

Hey guyes i'm having trouble opening two webcam with version 2.4.6. One webcam is the mounted laptop webcam and the other is a usb webcam.

include "opencv2/highgui/highgui.hpp"

include <iostream>

using namespace cv; using namespace std;

int main(int argc, char* argv[]) { VideoCapture cap(0); // open the video file for reading VideoCapture cap2(1); if ( !cap.isOpened() ) // if not success, exit program { cout << "Cannot open the video file" << endl; return -1; }

if ( !cap2.isOpened() )  // if not success, exit program
{
     cout << "Cannot open the video2 file" << endl;
     return -2;
}
//cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

 cout << "Frame per seconds : " << fps << endl;

namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

while(1)
{
    Mat frame;
    Mat frame2;
    bool bSuccess = cap.read(frame); // read a new frame from video
    bool bSuccess2 = cap2.read(frame2); // read a new frame from video
     if (!bSuccess) //if not success, break loop
    {
                    cout << "Cannot read the frame from video file" << endl;
                   break;
    }

    imshow("MyVideo", frame); //show the frame in "MyVideo" window
    imshow("MyVideo", frame2); //show the frame in "MyVideo" window
    if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
   {
            cout << "esc key is pressed by user" << endl; 
            break; 
   }
}

return 0;

}

click to hide/show revision 3
No.3 Revision

updated 2013-11-22 10:08:25 -0600

berak gravatar image

openning multiple webcam

Hey guyes i'm having trouble opening two webcam with version 2.4.6. One webcam is the mounted laptop webcam and the other is a usb webcam.

include "opencv2/highgui/highgui.hpp"

include <iostream>

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;

std; int main(int argc, char* argv[]) { VideoCapture cap(0); // open the video file for reading VideoCapture cap2(1); if ( !cap.isOpened() ) // if not success, exit program { cout << "Cannot open the video file" << endl; return -1; }

}
if ( !cap2.isOpened() ) // if not success, exit program
 {
  cout << "Cannot open the video2 file" << endl;
 return -2;
 }
 //cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms
 double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
 cout << "Frame per seconds : " << fps << endl;
 namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
 while(1)
 {
  Mat frame;
 Mat frame2;
  bool bSuccess = cap.read(frame); // read a new frame from video
 bool bSuccess2 = cap2.read(frame2); // read a new frame from video
 if (!bSuccess) //if not success, break loop
 {
  cout << "Cannot read the frame from video file" << endl;
 break;
 }
  imshow("MyVideo", frame); //show the frame in "MyVideo" window
 imshow("MyVideo", frame2); //show the frame in "MyVideo" window
  if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
 {
  cout << "esc key is pressed by user" << endl;
 break;
 }
 }
 return 0;

}

}