Ask Your Question
0

Multiple Camera recording with openCV

asked 2012-05-24 22:00:03 -0500

wtom gravatar image

updated 2014-01-28 17:12:27 -0500

ngrennan gravatar image

Hi, atm my goal is to connect several standard USB webcameras (2-4) to one single computer and try to run/record them at the same time. I'm using MSVS with C++ and the openCV libraries. Getting data from one single camera just works fine.

cv::VideoCapture vidCap(0); 
if(vidCap.isOpen())
    cout << ...

this just works fine and i can record pictures. But if I trie to set up an other VideoCapture object:

cv::VideoCapture vidCap2(1);
if(vidCap2.isOpen())...

it allways fails! I tried to run it in different threads, but this didn't work either - even got a bluescreen after closing the programm. And even with some software tools like Dorgem I got a bluescreen after trying.

I'm using Windows 7 64bit as operating system.

Any clues about what could be wrong here? I'd be happy about any help.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2012-05-25 01:12:02 -0500

StFS gravatar image

Hi.

First of all, your problem is an OpenCV problem so I would think you might have better luck asking in the OpenCV group: http://tech.groups.yahoo.com/group/OpenCV/

Secondly, as pointed out here (http://stackoverflow.com/questions/10194033/opencv-with-2-cameras-vc) OpenCV does not seem to handle >1 USB cameras on Windows all that well in general.

One suggestion would be to try something different. For example, you could try to actually use ROS to communicate with the cameras and set them up as ROS topics. Then create a node that subscribes to the images and does whatever OpenCV processing you need to do. There's no guarantee this would work, but it's worth the shot I'd think.

Kind regards, Stefan Freyr.

edit flag offensive delete link more

Comments

1

You may also find the OpenCV equivalent of ROS Answers helpful: http://answers.opencv.org/questions/

mjcarroll gravatar image mjcarroll  ( 2013-01-17 04:06:13 -0500 )edit
0

answered 2013-01-17 20:05:25 -0500

updated 2013-01-17 20:49:55 -0500

The following code works for me. two usb cameras, opencv2.1, MSVS2008, windows7 32 bit

#include "highgui.h"
#include "stdio.h"
int main()
{
   CvCapture * capture1=cvCaptureFromCAM(0);
   CvCapture * capture2=cvCaptureFromCAM(1);
   if(!capture1)
   {
      printf("Cannot find device1!\n");
      exit(0);
   }
   if(!capture2)
   {
      printf("Cannot find device2!\n");
      exit(0);
   }
   IplImage * image1=0;
   IplImage * image2=0;
   cvNamedWindow("Grab1");
   cvNamedWindow("Grab2");
   while(1)
   {
      image1=cvQueryFrame(capture1);
      image2=cvQueryFrame(capture2);
      if(!image1||!image2)
         break;
      cvShowImage("Grab1",image1);
      cvShowImage("Grab2",image2);
      int key=cvWaitKey(10);
      if(27==key)
         break;
   }
   cvReleaseCapture(&capture1);
   cvReleaseCapture(&capture2);
   cvDestroyWindow("Grab1");
   cvDestroyWindow("Grab2");

   return 0;
}

the following code is with opencv2.3.1. also succeed.

    #include <iostream>
    #include <opencv2/highgui/highgui.hpp>

    int main()

    {
    cv::VideoCapture cap1, cap2;
    cv::Mat frame1, image1, frame2, image2;

    cap1.open(0);
    cap2.open(1);
    if( !cap1.isOpened() )
    {
        std::cout << "Could not initialize cap1"<<std::endl;
        return -1;
    }
    if( !cap2.isOpened() )
    {
        std::cout << "Could not initialize cap2"<<std::endl;
        return -1;
    }
    for(;;)
    {
        cap1 >> frame1;
        if( frame1.empty() )
            break;
        frame1.copyTo(image1);
        cap2 >> frame2;
        if( frame2.empty() )
            break;
        frame2.copyTo(image2);
        cv::imshow( "Img1", image1 );
        cv::imshow( "Img2", image2 );

        char c = (char)cv::waitKey(10);
        if( c == 27 )
            break;
    }

    return 1;
}
edit flag offensive delete link more
-1

answered 2013-01-17 01:20:48 -0500

bayhaki09 gravatar image

updated 2013-01-17 01:22:31 -0500

how to use 2 cameras? And the captures of camera in picture control?

Thanks

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-24 22:00:03 -0500

Seen: 10,921 times

Last updated: Jan 17 '13