[英]getting multiple v4l errors using opencv with multiple webcams on a raspberry to shoot a timelapse
我發布這個是因為我已經在網上搜索,試圖為所引起的錯誤找到一些解釋,但沒有找到。
所以我試圖從 4 個不同的角度拍攝正在生長的植物的延時攝影。 我有 4 個網絡攝像頭 (Logitech B525) 連接到我的 raspberry Pi 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 帶寬問題,因為樹莓派只有一個 USB 2.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;
}
}
}
}
}
剛剛找到這篇文章: https : //stackoverflow.com/a/53472812/3643138嘗試使用文件名而不是索引打開您的設備! 這對我有用!
所以伙計們更新晚了。 我去年發現這一切都與樹莓派有關。 USB Bandwith 和 Raspberry pi 3B+ 只是功率不足。 我也在我的計算機上運行了我在 Raspberry 上使用的相同代碼,並且那里沒有問題。 我什至能夠在多線程處理任務的同時同時運行 4 個相機流。 Pi 可以同時處理一個低分辨率網絡攝像頭,但一旦要使用另一個網絡攝像頭,同時流式傳輸甚至單個圖像捕獲都將無法工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.