Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV can';t从网络摄像头捕获帧_C++_Opencv - Fatal编程技术网

C++ OpenCV can';t从网络摄像头捕获帧

C++ OpenCV can';t从网络摄像头捕获帧,c++,opencv,C++,Opencv,我正在VS2010中使用OpenCV 2.4.6 我想我的摄像头拍不到画面。当我执行代码时,它成功构建,但我没有得到输出。我想,当我检查是否(!bsucces)时,它已被执行,无法从网络摄像头捕获帧 我如何解决这个问题?我的代码如下: #include "opencv2/highgui/highgui.hpp" #include using namespace cv; using namespace std; int main(int argc, char* argv[]) {

我正在VS2010中使用OpenCV 2.4.6

我想我的摄像头拍不到画面。当我执行代码时,它成功构建,但我没有得到输出。我想,当我检查
是否(!bsucces)
时,它已被执行,无法从网络摄像头捕获帧

我如何解决这个问题?我的代码如下:


#include "opencv2/highgui/highgui.hpp"
#include 

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // open the video camera no. 0

    if (!cap.isOpened())  // if not success, exit program
    {
    cout  << "Cannot open the video file" << endl;
        return -1;
    }

   double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
   double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the  video
    cout << "Frame size : " << dWidth << " x " << dHeight << endl;
    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
    while (1)
    {
       Mat frame;
       bool bSuccess = cap.read(frame); // read a new frame from video
       if (!bSuccess) //if not success, break loop
        {
         cout << "Cannot read a frame from video file" << endl;
            break;
        }

        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        if (waitKey(30) == 27) 
        {
        cout << "esc key is pressed by user" << endl;
          break; 
        }
    }
    return 0;

}

尝试不使用这部分代码:

double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the  video
cout << "Frame size : " << dWidth << " x " << dHeight << endl;
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
double dWidth=cap.get(CV\u cap\u PROP\u FRAME\u WIDTH)//获取视频帧的宽度
双DHHEIGHT=盖获取(CV、盖、支柱、框架、高度)//获取视频帧的高度

cout添加此行
cap.retrieve(框架)


bool bSuccess=cap.read(帧)在同一行之前

不仅可以跳过第一帧,还可以跳过许多其他帧;-)

opencv 2.4.9 visual studio 10

#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
int main()
{
视频捕获网络摄像头_0(0);//开放流
如果(!webcam_0.isopend())
{

请尝试以下代码:

#include "stdafx.h"
#include "highgui\highgui.hpp"  

using namespace cv;


void main()
{
    Mat Frame;

    VideoCapture cap(0);  // change the number to 1 for an external USB webcam

    while(1)
    {
        cap >> Frame;
        imshow("Camera Feed", Frame);

        if (waitKey(10) == 27)  return;
    }
}
修复视频捕获失败的问题 在一些openCV库中,
VideoCapture(0);bool bSuccess=cap.read(frame);
将首先返回一个
0
。因此,在
while(1)
循环中,它将在第一次迭代时失败。因此,在进入无限循环之前,需要运行
cap.read(frame);
行一次

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // open the video camera no. 0

    if (!cap.isOpened())  // if not success, exit program
    {
        cout << "Cannot open the video cam" << endl;
        return -1;
    }

   double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
   double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    Mat frame;
cap.read(frame);

while (1)
{

    bool bSuccess = cap.read(frame); // read a new frame from video

     if (!bSuccess) //if not success, break loop
    {
         cout << "Cannot read a frame from video stream" << endl;
         break;
    }

    imshow("MyVideo", frame); //show the frame in "MyVideo" window

    if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
   {
        cout << "esc key is pressed by user" << endl;
        break;
   }
}
return 0;

}
#包括“opencv2/highgui/highgui.hpp”
#包括
使用名称空间cv;
使用名称空间std;
int main(int argc,char*argv[])
{
VideoCapture(0);//打开0号摄像机
如果(!cap.isopend())//如果不成功,退出程序
{
在与以下提到的情况类似的所有情况下,都不能删除“
cv”:

double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);

这对我很有效。

您好,亲爱的,谢谢您的回答。我在没有上述部分的情况下进行了尝试。但没有得到任何结果。2.4.6在从网络摄像头捕获图像方面存在一些问题。您可能希望尝试2.4.6.1,因为他们已经解决了该问题。