OpenCV VideoCapture in Win10 VS17 cannot open more than four USB 3.0 cameras

asked 2019-05-22 23:50:01 -0500

UT_Doug gravatar image

updated 2019-05-23 22:23:44 -0500

supra56 gravatar image

I am trying set up a multi-camera system in VS17 win10 OpenCV environment using VideoCapture function from OpenCV library. Cameras are Basler USB 3.0 (3840*2748 monochrome). I had no issue to open and stream up to four cameras. However, the fifth camera or more was not able to be opened. Whereas, all six cameras can be accessed with no issue using Basler software. I am not sure if there is a hardware limitation (like USB bandwidth or PCI bus), which should not be because in Basler SDK, all cameras can be used as normal.

I have tried to set lower resolution image to see if it is USB bandwidth limit, but still not working.

int main(){
VideoCapture cap0(0), cap1(1), cap2(2), cap3(3), cap4(4), cap5(5);

Mat ca1, ca2, ca3, ca4, ca5, ca6;

cv::namedWindow("Camera1", WINDOW_NORMAL);
cv::namedWindow("Camera2", WINDOW_NORMAL);
cv::namedWindow("Camera3", WINDOW_NORMAL);
cv::namedWindow("Camera4", WINDOW_NORMAL);
cv::namedWindow("Camera5", WINDOW_NORMAL);
cv::namedWindow("Camera6", WINDOW_NORMAL);

while (true) {

    if (cap0.grab()) {
        cap0.retrieve(ca1);
    }
    if (!cap0.grab()) {
        std::cout << "camera 0 cannot be grabbed\n";
    }
    if (cap1.grab()) {
        cap1.retrieve(ca2);
    }
    if (!cap1.grab()) {
        std::cout << "camera 1 cannot be grabbed\n";
    }
    if (cap2.grab()) {
        cap2.retrieve(ca3);
    }
    if (!cap2.grab()) {
        std::cout << "camera 2 cannot be grabbed\n";
    }
    if (cap3.grab()) {
        cap3.retrieve(ca4);
    }
    if (!cap3.grab()) {
        std::cout << "camera 3 cannot be grabbed\n";
    }
    if (cap4.grab()) {
        cap3.retrieve(ca5);
    }
    if (!cap4.grab()) {
        std::cout << "camera 4 cannot be grabbed\n";
    }
    if (cap5.grab()) {
        cap3.retrieve(ca6);
    }
    if (!cap5.grab()) {
        std::cout << "camera 5 cannot be grabbed\n";
    }
    cv::imshow("Camera1", ca1);
    cv::imshow("Camera2", ca2);
    cv::imshow("Camera3", ca3);
    cv::imshow("Camera4", ca4);
    cv::imshow("Camera5", ca5);
    cv::imshow("Camera6", ca6);
    char c = waitKey(1);
    if (c == 'q') {
        destroyAllWindows();
        break;
    }
}

cap0.release();

cap1.release();

cap2.release();

cap3.release();

cap4.release();

cap5.release();

return 0;

}

Compile fails at cap4.grab(), basically it said camera 4 and 5 cannot be grabbed (opened). Can someone please help? Thank you very much in advance.image description

edit retag flag offensive close merge delete

Comments

1

read this and check camera power consumption

LBerger gravatar imageLBerger ( 2019-05-23 01:58:21 -0500 )edit