Green output image from second Camera

asked 2016-11-08 05:26:21 -0600

Saghir Khatri gravatar image

Hi All. I have setup OpenCV 3.1.0 on my BeagleBone Black Rev C. All basic operations are working well. I have attached 3 cameras using USB hub to BBB. I have a simple OpenCV program that iterates through all the available programs and generate images in 3 different folders in OpenCV. I have verified that all cameras are available using lsusb command. Output in first image is fine with just weird lines on image. Output in second image is Green(Weird!). No Image is generated from third camera and i get the following output:

Not Working select timeout

Here is my code:

    int numberOfCameras = 3;
    for(int i=0; i<numberOfCameras; i++){
        cout << i<<endl;
        VideoCapture cap(i);
        if (cap.isOpened())
        {
            cout << "Camera working"<<endl;
        }
        else
        {
            cout<< "Not Working"<<endl;
        }
        cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
        Mat frame;

       stringstream ss;
       ss << i;
       if(i==0)
       { 
            string fileName = "/electric1/" + ss.str() + ".jpg";
            Mat frame0;
            cap >> frame0;
            cout << fileName << endl;
            imwrite(fileName, frame0);
      }
      else if(i==1)
      {
            string fileName = "/gas1/" + ss.str() + ".jpg";
            Mat frame1;
            cap >> frame1;
            cout << fileName << endl;
            imwrite(fileName, frame1);
      }
      else if(i==2)
      {
             string fileName = "/water1/" + ss.str() + ".jpg";
             Mat frame2;
             cap >> frame2;
             cout << fileName << endl;
             imwrite(fileName, frame2);
      }
   }

Please let me know why i am getting this issue. Or any hint to right direction will be really great. Thanks

edit retag flag offensive close merge delete

Comments

In some systems you mustn't use first images. try like this :

vector<VideoCapture> cap;
for(int i=0; i<numberOfCameras; i++)
{
    VideoCapture v(i);

    cout << i<<endl;
    if (cap.isOpened())
    {
        cout << "Camera working"<<endl;
        cap.push_back(v);
    }
    else
    {
        cout<< "Not Working"<<endl;
    }
    v.set(CV_CAP_PROP_FRAME_WIDTH,320);
    v.set(CV_CAP_PROP_FRAME_HEIGHT,240);
}
Mat frame;
for (int j=0;j<10;j++)
     for(int i=0; i<cap.size(); i++)
         cap[i]>>frame;

     for(int i=0; i<cap.size(); i++)
     {
         cap[i]>>frame;
         imwrite(format("cam%d",i),frame);
     }
LBerger gravatar imageLBerger ( 2016-11-08 07:16:57 -0600 )edit