我之所以发布这篇文章,是因为我已经在网上搜索过,试图找到一些错误的解释,但没有找到任何解释。
所以我试着从4个不同的角度拍摄一株生长的植物的时间流逝。我有4个摄像头(罗技B525)连接到我的树莓派3。每小时一次,所有4个摄像头应该拍摄一个尽可能窄和准确的时间同步帧。
在顺利运行后,它应该做的事情,有时几分钟,有时几个小时,连接的摄像头不再被V4L或输出损坏的信息。产生错误的摄像头是随机的,所以没有坏的usb端口,没有断线。一段时间后,失败的摄像头再次开始工作,然后另一个摄像头出现故障,这种情况一直持续到所有摄像头都失败,程序停止。
下面是错误输出的示例
我的保存周期的程序输出:
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!然后就会出现错误:
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摄像头永远不会断开连接,并且总是存在于设备文件夹/dev/videoX中,我想假设这不是电源问题是可以接受的。
导致错误的代码部分是开关部分,一遍又一遍地重复,延迟5秒。我猜是USB带宽问题,因为raspberry只有一条USB2.0总线被分成4个端口。我尝试在关闭和再次打开捕获之间添加更多的时间,但都没有真正的帮助。我是不是遗漏了什么?
下面是我的代码:
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;
}
}
}
}
}发布于 2018-12-03 06:58:48
刚刚发现了这篇文章:https://stackoverflow.com/a/53472812/3643138尝试用文件名而不是索引来打开你的设备!这对我来说很有效!
发布于 2020-03-13 06:15:10
所以伙计们来晚了。我去年发现这一切都和树莓派有关。USB Bandwith和覆盆子pi 3B+就是动力不足。我也在我的电脑上运行了我在树莓树上使用的相同的代码,没有任何问题。我甚至可以在多线程任务的同时运行4个摄像头流。Pi可以一次处理一个低分辨率网络摄像头,但一旦要使用另一个摄像头,同时流式传输甚至单个图像捕获将不起作用。
https://stackoverflow.com/questions/52985542
复制相似问题