![](/img/trans.png)
[英]Unable to read frames from VideoCapture from secondary webcam with OpenCV
[英]VideoCapture dosnt read from webcam openCV2.4.0 linux
我正在嘗試通過閱讀openCV中的網絡攝像頭流來制作一些計算機視頻。 我已經嘗試過使用內部攝像頭和外部USB攝像頭,它們都可以很好地與camorama,streamer等程序配合使用。
我的代碼的一部分:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include "pic_manipulation.hpp"
#include "colorDetector.h"
#include <time.h>
using namespace std;
int main ( int argc, char **argv ){
string file="../test.avi";
cv::VideoCapture capture(0);//les video
if(!capture.isOpened()){
cout <<"could not read file"<<endl;
return -1;
}
double rate=capture.get(CV_CAP_PROP_FPS);
bool stop(false);
cv::Mat frame;
cv::namedWindow("Extract frame");
int delay=1000/rate;
while(!stop){
if(!capture.read(frame))break;
cv::imshow("Extract frame", frame);
sleep(delay/1000);
if(cv::waitKey(delay)>=0){
cout<<"stop"<<endl;
stop=true;
capture.release();
}
cout<< "one loop finished"<<endl;
}
return 0;
}
當我編譯並運行程序時,我沒有收到任何錯誤或警告,它只是返回到if(!capture.isOpened())(或者如果我跳過了isOpened,它將返回到下一個if(...))。 它可以毫無問題地讀取視頻文件。 有人知道我的opencv安裝是否有錯誤,或者是導致問題的linux網絡攝像頭設置嗎? 我正在使用Linux Mint並使用cmake / g ++構建項目
再看一下您的代碼:
cv::VideoCapture capture(0); // open the default camera
if(!capture.isOpened()) // check if it succeeded
{
//...
}
isOpened()
對於索引0
失敗的事實表明您無法打開默認相機。 既然你已經連接到電腦上的其他相機,你也可以嘗試通過1
, 2
, 3
,...
檢查文檔並了解每種方法的作用並返回總是很有益的。
以下是受支持的網絡攝像頭列表, OpenCV可能不支持您的某些攝像頭 。 那可以解釋為什么默認相機不起作用。
我通過遵循這份出色的指南來安裝openCV來解決了該問題: 在Ubuntu上安裝和配置OpenCV 2.4.2的綜合指南
我懷疑我沒有按照上述指南中的說明在64位平台上設置用於構建ffmpeg,v4l的正確配置。 無論如何,它終於可以工作了!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.