hello,

I'm a newbie to opencv. I'm doing a project using c++ and I use opencv for image processing. So for that I need to capture two video streams at the same time. before doing processing part I try to display both videos from cameras on two windows. But it is not working. the massage on terminal is NO SPACE LEFT ON THE DEVICE. I search on web but couldn't find any helpful thing to get this done. So if anyone knows how to do this please help me.

here is my code that how I try to do it.

#include <stdio.h>
#include "cv.h"
#include "highgui.h"
#include "iostream"
#include <pthread.h>
#include <stdlib.h>
#define NUM_THREADS     2

using namespace std;

CvCapture* capture[2];

void *side_cam(void *z){
        capture[0] = cvCreateCameraCapture(1);
        capture[1] = cvCreateCameraCapture(0);
        IplImage *img = 0;
        IplImage *img1 = 0;
        cvNamedWindow("Cam1",CV_WINDOW_AUTOSIZE);
        cvNamedWindow("Cam2",CV_WINDOW_AUTOSIZE);
        if(!capture[0] && !capture[1])
                printf("Webcam error\n");
        while(1){
                img = cvQueryFrame(capture[0]);
                img1 = cvQueryFrame(capture[1]);
                if(!img)break;
                if(!img1)break;
                cvShowImage("Cam1",img);
                cvShowImage("Cam2",img1);
                char c = cvWaitKey(33);
                if( c == 27 ) break;
        }
        cvReleaseImage(&img);
        cvDestroyWindow("Cam1");
        cvReleaseCapture(&capture[0]);
        pthread_exit(0);
}

void *bottom_cam(void *z){
        capture[1] = cvCreateCameraCapture(0);
        IplImage *img1 = 0;
        cvNamedWindow("Cam2",CV_WINDOW_AUTOSIZE);
        if(!capture[1])
                printf("Webcam error\n");
        while(1){
                img1 = cvQueryFrame(capture[2]);
                if(!img1)break;
                cvShowImage("Cam2",img1);
                char c = cvWaitKey(33);
                if( c == 27 ) break;
        }
        cvReleaseImage(&img1);
        cvDestroyWindow("Cam1");
        cvReleaseCapture(&capture[1]);
        pthread_exit(0);
}


int main()
{
        pthread_t threads[NUM_THREADS];
    int rc;int z=0;
        rc = pthread_create(&threads[0], NULL,side_cam, (void *)z);
        if (rc){
          printf("ERROR; return code from pthread_create() is %d\n", rc);
          exit(-1);
      }
        rc = pthread_create(&threads[1], NULL,bottom_cam, (void *)z);
        if (rc){
        printf("ERROR; return code from pthread_create() is %d\n", rc);
          exit(-1);
      }
        pthread_join(threads[0],NULL);
        pthread_join(threads[1],NULL);
}

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.