0

I'm using two GigE (basler aca2500-14gm) cameras on win10 opencv3.4, I connect the wires of the 2 cameras to the switch, and then connect it to my computer.but I can't open the camera and get the frames at the same time。 my code: `

int main()
{
PylonInitialize();
VideoCapture cap(0);
VideoCapture cap1(2);

if (!cap.isOpened())
{
    cout << "Camera 1 unsuccessfully opened" << endl;
}
if (!cap1.isOpened())
{
    cout << "Camera 2 unsuccessfully opened" << endl;
}

bool stop = false;
while (!stop)
{

    Mat frame;
    Mat frame1;


    cap >> frame;
    cap1 >> frame1;

    if (frame.empty() || frame1.empty())
    {
        break;
    }


    imshow("Open the camera 1", frame);
    imshow("Open the camera 2", frame1);

    if (waitKey(100) >= 0)
    {
        PylonTerminate();//
        stop = true;
    }
}

}`

by the way,when I tried to run the sample of basler SDK :Grab_MultipleCameras.cpp, I can open the camera but the image in the window is grey.

is there anyone help me to solve this problem? Thanks in advance.

  • Why do you use `cap(0)` and `cap(2)` rather than `cap(0)` and `cap(1)`? Can you open each camera singly? What happens if you open the two in the reverse order? – Mark Setchell Jan 24 '18 at 09:11
  • I can open each camera singly,and if I reverse the order, cap(0) can open and get frame.I also tried different ID cap(1) to cap(10), there still one camera(cap(0)) can work. – berlinpand Jan 25 '18 at 01:33

1 Answers1

0

When you run this sample of basler SDK it might happen that the second camera still could not be open but it just show you the window with defualt color (grey).

Another likely thing is that your are passing wrong device ID for VideoCapture to work, See this OpenCv VideoCap documentation. Also from what I know if you are using GigE cameras it will be better to pass ip address of each camera to VideoCapture

So I would say only to try change one think in your code:

From

VideoCapture cap(0);
VideoCapture cap1(2);

To:

VideoCapture cap(/*camera Ip Address*/);  //or try with different IDs
VideoCapture cap1(/*camera Ip Address*/);

Also take a look at this answer VideoCapture and GigE camera . It is stated there that when there is more than one camera you would be better with passing IP address.

Another thing to check will be if you can see both cameras in your device manager.

EDIT:

Hey I found nice documentation about working with Pylon SDK( from camera vendor) andOpenCV (it is probably older version of OpenCV but still can be useful)

wdudzik
  • 1,264
  • 15
  • 24
  • Thanks for your solution. I tried to specify the camera's IP just like:'VideoCapture cap;VideoCapture cap1;cap.open("htt p://172.20.12.163");cap1.open("htt p://172.20.12.51");' but it didn't work,and show that "Error opening file",I know there is something wrong with the address,but I can't find the correct IP or URL format of my cameras. Different IDs didn't work as well. Also I could'n see the cameras in my device manager,but they can work in the PYLON VIEWER. – berlinpand Jan 24 '18 at 06:55
  • And have you tried getting video through Pylon SDK? Here is some instruction https://www.baslerweb.com/fp-1508418766/media/downloads/documents/application_notes/AW00064406000_Application_Note_Build_pylon_C_Apps_with_Free_Visual_Studio_IDE.pdf – wdudzik Jan 24 '18 at 07:13
  • This instruction only tell me how to build Basler pylon c++ applications,and I could run some of the SDK like grab images with sigle camera with opencv3, but still can't open 2 cameras with Grab_MultipleCameras.cpp. – berlinpand Jan 24 '18 at 08:24