Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:38:28+00:00 2026-06-16T02:38:28+00:00

I have two cameras that I need to display video from at the same

  • 0

I have two cameras that I need to display video from at the same time, either in separate windows or in the same window. However, using the following code, only one of the camera feeds (camera(1)) displays. Could someone point out what needs to be changed in my code, or link to other code that would achieve the desired effect?

N.B. This is NOT for stereo vision.

int main()
{

    //initialize and allocate memory to load the video stream from camera 
    CvCapture *capture1 = cvCaptureFromCAM(0);

    if( !capture1 ) return 1;

    //create a window with the title "Video1"
    cvNamedWindow("Video1");

    while(true) {
        //grab and retrieve each frames of the video sequentially 
        IplImage* frame1 = cvQueryFrame( capture1 );

        if( !frame1 ) break;

        //show the retrieved frame in the "Video1" window
        cvShowImage( "Video1", frame1 );

        //wait for 40 milliseconds
        int c = cvWaitKey(40);

        //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27) 
        if((char)c==27 ) break;
    }

    //initialize and allocate memory to load the video stream from camera 
    CvCapture *capture2 = cvCaptureFromCAM(1);

    if( !capture2 ) return 1;

    //create a window with the title "Video2"
    cvNamedWindow("Video2");

    while(true) {
        //grab and retrieve each frames of the video sequentially 
        IplImage* frame2 = cvQueryFrame( capture2 );

        if( !frame2 ) break;        

        //show the retrieved frame in the "Video2" window
        cvShowImage( "Video2", frame2 );

        //wait for 40 milliseconds
        int c = cvWaitKey(40);

        //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27) 
        if((char)c==27 ) break;
    }

    //destroy the opened window
    cvDestroyWindow("Video1"); 
    cvDestroyWindow("Video2");   
    //release memory
    cvReleaseCapture( &capture1 );
    cvReleaseCapture( &capture2 );

    return 0;  

    //VideoCapture1();
    //VideoCapture2();


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:38:30+00:00Added an answer on June 16, 2026 at 2:38 am

    Just to clarify, are you using C or C++? If you are using C++, please use C++ interfaces of OpenCV.

    Example below works for me:

    #include <opencv2/opencv.hpp>
    
    int main()
    {
        //initialize and allocate memory to load the video stream from camera 
        cv::VideoCapture camera0(0);
        cv::VideoCapture camera1(1);
    
        if( !camera0.isOpened() ) return 1;
        if( !camera1.isOpened() ) return 1;
    
        while(true) {
            //grab and retrieve each frames of the video sequentially 
            cv::Mat3b frame0;
            camera0 >> frame0;
            cv::Mat3b frame1;
            camera1 >> frame1;
    
            cv::imshow("Video0", frame0);
            cv::imshow("Video1", frame1);
    
            //wait for 40 milliseconds
            int c = cvWaitKey(40);
    
            //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27) 
            if(27 == char(c)) break;
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to store different objects that have been extended from the same
I have two classes (MVC view model) which inherits from one abstract base class.
I have two columns say Main and Sub . (they can be of same
I have two queries that find both the Zip codes, and the States for
I have three videos: a lecture that was filmed with a video camera a
I have two 3D vectors called A and B that both only have a
I need to parse xml files from two sources. Both xml files contain the
We have created an application that records web camera streams using Xuggler, but video
I have stereo cameras systems. In my program I catch the images from each
I have two overlay images that I want show in camera view depending on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.