I'm posting this because i was already searching the web trying to find some explenation for the errors caused but didn't find any.
So I'm trying to shoot a timelapse of a growing plant from 4 different angles. I have 4 webcams (Logitech B525) attached to my raspberry Pi 3. Once an hour all 4 cams should shoot a time synced frame as narrow and accurate as possible.
After running smoothly doing what it should, sometimes for minutes sometimes for hours, the cameras attached are not found anymore by V4L or putting out corrupted information. The cameras producing errors are random, so no bad usb ports, no broken cables. After a while the failing camera starts working again then another is failing, this continues until all cameras fail and the program stops.
Here an example of the Error Outputs
My programmed output of the saving period:
cam 1 attached
cam 2 attached
cam 3 attached
cam 4 attached
18-10-23_10-00-00
saving file of frame 4.. '../cam4/cam4_image_18-10-23_10-00-00.jpg'
18-10-23_10-00-01
saving file of frame 3.. '../cam3/cam3_image_18-10-23_10-00-01.jpg'
18-10-23_10-00-02
saving file of frame 2..'../cam2/cam2_image_18-10-23_10-00-02.jpg'
18-10-23_10-00-02
saving file of frame 1.. '../cam1/cam1_image_18-10-23_10-00-02.jpg'
waiting for next capture!
Then Errors occur:
libv4l2: error setting pixformat: Input-/Output Error
VIDEOIO ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Input-/Output Error
libv4l1: error setting pixformat: Input-/Output Error
libv4l2: error setting pixformat: Input-/Output Error
libv4l1: error setting pixformat: Input-/Output Error
VIDEOIO ERROR: libv4l unable to ioctl VIDIOCSPICT
cam 1 not attached
cam 2 attached
VIDEOIO ERROR: V4L: device /dev/video2: Unable to query number of channels
cam 3 not attached
libv4l2: error setting pixformat: Input-/Output Error
VIDEOIO ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Input-/Output Error
libv4l1: error setting pixformat: Input-/Output Error
libv4l2: error setting pixformat: Input-/Output Error
libv4l1: error setting pixformat: Input-/Output Error
VIDEOIO ERROR: libv4l unable to ioctl VIDIOCSPICT
cam 4 not attached
sh: 1: reboot: not found
libv4l2: error setting pixformat: Input-/Output Error
VIDEOIO ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Input-/Output Error
libv4l1: error setting pixformat: Input-/Output Error
libv4l2: error setting pixformat: Input-/Output Error
libv4l1: error setting pixformat: Input-/Output Error
VIDEOIO ERROR: libv4l unable to ioctl VIDIOCSPICT
cam 1 attached
cam 2 attached
cam 3 attached
VIDEOIO ERROR: V4L: device /dev/video3: Unable to query number of channels
cam 4 not attached
The Cameras never disconnect and are always present within the device folder /dev/videoX all the time, i guess it is ok to assume it's not a power issue.
my part of the code causing the errors is the switch part repeating over and over again with a 5 seconds delay. My guess is a USB bandwith issue since the raspberry has only one USB 2.0 bus split up into 4 ports. I tried adding more time between closing and opening a capture again but nothing really helped. Am i missing something?
Here's my Code:
switch(4)
{
case 4:
{
VideoCapture cap4(3);
if(!cap4.isOpened())
{
cout<<"cam 4 not functional or attached!"<<endl;
}
else
{
//cap4.set(5, 30); //5=FPS settings
//cap4.set(38, 3); //38=Buffersize settings, Frames saved in Buffer
cap4.set(3,1280);//3=Width, Pixelcount
cap4.set(4,720); //4=Height, Pixelcount
Mat frame4;
cap4 >> frame4; // get a new frame from camera
waitKey(30); //wait for 2 Frames
cap4.release();
imshow("camera_4", frame4);
if(frame4.empty())
{
cerr<<"Something is wrong with the camera 4, could not get frame 4!"<<endl;
}
else
{
try
{
if(save_next_file)
{
string name4 = "../cam4/cam4_image_"+currentDateTime()+".jpg";
cout<<"saving file of frame 4.. '"<<name4<<"'"<<endl;
imwrite(name4.c_str(),frame4);
waitKey(30);
gettimeofday(&last_save, NULL); //reset the time interval
}
}
catch(cv::Exception e)
{
cout<<"error saving frame 4. >__<"<<endl;
}
}
}
}
case 3:
{
VideoCapture cap3(2);
if(!cap3.isOpened())
{
cout<<"cam 3 not functional or attached!"<<endl;
}
else
{
//cap3.set(5, 30); //5=FPS settings
//cap3.set(38, 3); //38=Buffersize settings, Frames saved in Buffer
cap3.set(3,1280);//3=Width, Pixelcount
cap3.set(4,720); //4=Height, Pixelcount
Mat frame3;
cap3 >> frame3; // get a new frame from camera
waitKey(30); //wait for 2 Frames
cap3.release();
imshow("camera_3", frame3);
if(frame3.empty())
{
cerr<<"Something is wrong with the camrea 3, could not get frame 3. >__<"<<endl;
}
else
{
try
{
if(save_next_file)
{
string name3 = "../cam3/cam3_image_"+currentDateTime()+".jpg";
cout<<"saving file of frame 3.. '"<<name3<<"'"<<endl;
imwrite(name3.c_str(),frame3);
waitKey(25);
gettimeofday(&last_save, NULL); //reset the time interval
}
}
catch(cv::Exception e)
{
cout<<"error saving frame 3."<<endl;
}
}
}
}
case 2:
{
VideoCapture cap2(1);
if(!cap2.isOpened())
{
cout<<"cam 2 not functional or attached!"<<endl;
}
else
{
//cap2.set(5, 30); //5=FPS settings
//cap2.set(38, 3); //38=Buffersize settings, Frames saved in Buffer
cap2.set(3,1280);//3=Width, Pixelcount
cap2.set(4,720); //4=Height, Pixelcount
Mat frame2;
cap2 >> frame2; // get a new frame from camera
waitKey(30); //wait for 2 Frames
cap2.release();
imshow("camera_2", frame2);
if(frame2.empty())
{
cerr << "Something is wrong with the camera 2, could not get frame 2!" << endl;
}
else
{
try
{
if(save_next_file)
{
string name2 = "../cam2/cam2_image_"+currentDateTime()+".jpg";
cout<<"saving file of frame 2..'"<<name2<<"'"<<endl;
imwrite(name2.c_str(),frame2);
waitKey(25);
gettimeofday(&last_save, NULL); //reset the time interval
}
}
catch(cv::Exception e)
{
cout<<"error saving frame 2. >__<"<<endl;
}
}
}
}
case 1:
{
VideoCapture cap1(0);
if(cap1.isOpened())
if(!cap1.isOpened())
{
cout<<"cam 1 not functional or attached!"<<endl;
}
else
{
//cap1.set(5, 30); //5=FPS settings
//cap1.set(38, 3); //38=Buffersize settings, Frames saved in Buffer
cap1.set(3,1280);//3=Width, Pixelcount
cap1.set(4,720); //4=Height, Pixelcount
Mat frame1;
cap1 >> frame1; // get a new frame from camera
waitKey(30); //wait for 2 Frames
cap1.release();
imshow("camera_1", frame1);
if(frame1.empty())
{
cerr << "Something is wrong with camera 1, could not get frame 1!" << endl;
}
else
{
try
{
if(save_next_file)
{
string name1 = "../cam1/cam1_image_"+currentDateTime()+".jpg";
cout<<"saving file of frame 1.. '"<<name1<<"'"<<endl;
imwrite(name1.c_str(),frame1);
waitKey(25);
gettimeofday(&last_save, NULL); //reset the time interval
}
}
catch(cv::Exception e)
{
cout<<"error saving frame 1!"<<endl;
}
}
}
}
}