My 2 camera's video capture program didn't work

asked 2019-11-07 11:17:39 -0500

patrick129 gravatar image

updated 2019-11-07 11:29:21 -0500

berak gravatar image

I have used exactly the program suggested in my previous question and this is the that program:

int main()

{

cv::VideoCapture camera0(2);

cv::VideoCapture camera1(1);

if( !camera0.isOpened() ) return 1;

if( !camera1.isOpened() ) return 1;

int nbImage=0;

while(true) {

    cv::Mat frame0;

    camera0 >> frame0;

    cv::Mat frame1;

    camera1 >> frame1;

cv::imshow("Video0", frame0);

cv::imshow("Video1", frame1);

    int c = cvWaitKey(40);

    if ((static_cast<char>(c)=='s')

   {

       imwrite(format("image0_%d.jpg",nbImage),frame0);

       imwrite(format("image1_%d.jpg",nbImage++),frame1);

   }

    if(27 == char(c)) break;

}

I've runed this program and it had no error. But the console window just opened and I can't not capture my video because it didn't opened. I've using Basler twin cameras which has 3.0 USB cable, I've wonder if because of the bandwith of cable that the computer can not deal with 2 cameras at the same time or Gstreamer I've dowloaded didn't support 2 cameras? If i use the camera one by one it works. Do somebody have a solution for my problem? Thank you.

edit retag flag offensive close merge delete

Comments

Leaving any potential camera problem aside, I think your use of waitkey is incorrect. Waitkey is the only way for the program to know for how long the image should be displayed after a imshow. So, I would try to place a waitkey after the first imshow and after the second one as well.

urres_coding gravatar imageurres_coding ( 2019-11-08 01:22:32 -0500 )edit
1

@urres_coding you're wrong, also using 2 waitKey calls is a terrible idea.

berak gravatar imageberak ( 2019-11-08 01:54:19 -0500 )edit

Note This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.

Taken from the official documentation

urres_coding gravatar imageurres_coding ( 2019-11-08 02:02:43 -0500 )edit

@urres_coding I'll do this to see if what will be different

patrick129 gravatar imagepatrick129 ( 2019-11-08 02:25:51 -0500 )edit