Ask Your Question

xiongtec's profile - activity

2013-11-22 13:42:43 -0500 asked a question multiple webcam test

So I have a usb logitech webcam and a built in laptop webcam. I am trying to start both the webcam at same time. I made a demo code below to test but cap2 object keep failing to open. Do any you guys have a suggestion. cap is the default which is the logitech webcam and cap2 is the built in web cap.

#include <iostream>
#include <opencv2\highgui\highgui.hpp>
#include <string>

int main(int arg, char * args[])
{
    cv::VideoCapture cap, cap2;
    cv::Mat mat1;
    cv::Mat mat2;

    cap.open(0);
    cap2.open(1);
    if(!cap.isOpened())
        return -1;
    if(!cap2.isOpened())
        return -2;

    cv::namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
    cv::namedWindow("MyVideo2",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo2"
    while(true)
    {
        cap.read(mat1);
        cap2.read(mat2);

        cv::imshow("MyVideo",mat1);

        cv::imshow("MyVideo2", mat2);
    }
    cap.release();
    cap2.release();
    return 0;
}
2013-11-22 09:53:46 -0500 received badge  Editor (source)
2013-11-22 09:52:50 -0500 asked a question 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;

}