简体   繁体   English

在C ++中使用OpenCV从相机流式传输视频时,程序无法启动

[英]Program won't start when using OpenCV in C++ to stream video from camera

right, I have a USB camera connected to the PC and I want to use OpenCV to stream images from it. 是的,我有一台连接到PC的USB摄像头,我想用OpenCV来传输它的图像。 Here is my code: 这是我的代码:

#include <cv.h>
#include <highgui.h>
#include <stdio.h>

int main()
{

    CvCapture* cameraCapture = cvCaptureFromCAM(CV_CAP_ANY);
    cvNamedWindow("Camera");

    while(1)
    {
        IplImage* frame = cvQueryFrame(cameraCapture);
        cvShowImage("Camera", frame);
        if((cvWaitKey(10) & 255) == 27)
            break;
    }

    cvReleaseCapture(&cameraCapture);
    cvDestroyWindow("Camera");
}

The problem is that when I start the program I get this pop-up error: "The application was unable to start correctly (0xc0150002). Click OK to close the application". 问题是,当我启动程序时,我收到此弹出错误:“应用程序无法正确启动(0xc0150002)。单击确定关闭应用程序”。 I have made sure I have included all the correct libraries, header files and ddl's so I'm really not sure whats wrong with it. 我已经确定我已经包含了所有正确的库,头文件和ddl,所以我真的不确定它有什么问题。

Any help to solve this problem will be greatly appreciated. 任何帮助解决这个问题将不胜感激。

I suggest you to try this way of dealing with cameras, using the OpenCV 2.3.1. 我建议你尝试使用OpenCV 2.3.1来处理相机。

VideoCapture _videoSource;
bool camera = 1;

if(camera)
{
   if(!_videoSource.open(0))                // Try to start camera. 0 = default camera
   {                                    
    cout << "Error opening camera" << endl; // here you control why the error happens
    exit(1);                // Exit if fail         
   }
}
else
{
   if(!_videoSource.open(Path+"video.avi")) 
   {
        cout << "Error opening file" << endl;
        exit(2);                        // Exit if fail
   }
}
_videoSource.set(CV_CAP_PROP_CONVERT_RGB, 1);

Mat frame;
namedWindow("Image");

while(1) 
{
  _videoSource >> frame; 
  imshow("output", frame);
  return 0;
}

If this fails, the you will know for sure that the problem is with your camera. 如果此操作失败,您将确定问题出在您的相机上。 Maybe the drivers. 也许是司机。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用带有 OpenCV 的 C++ 从视频中提取帧 - Can't extract frames from video using C++ with OpenCV 通过OpenCV和C ++从IP摄像机流式传输视频 - Streaming video from ip camera by opencv and c++ 无法在Android上使用C ++ OpenCV打开相机 - Can't open camera using C++ OpenCV on android 无法从 ip 相机 (rtsp) 与 C++ dll 使用 ZCFAF4DE8D6AAA9548C17936.AFE 抓取帧。 - Can't grab frames from an ip camera (rtsp) with a C++ dll using OpenCv 3.4.5 测试回文率(C ++)时程序将不会继续运行 - Program Won't Continue to Run When Testing for Palindromes (C++) 使用 GStreamer OpenCV Videocapture 时的灰色视频帧 C++ - Grey Video frames when using OpenCV Videocapture with GStreamer C++ “程序无法启动,因为您的计算机中缺少 opencv_world300.dll”错误 C++ - "The program can't start because opencv_world300.dll is missing from your computer" error in C++ 当有来自 GLEW 库 (C++) 的任何函数时,程序将不会运行 - Program won't run when there's any function from the GLEW library (C++) C++ 程序从 R 调用时无法运行(符号查找错误) - C++ Program Won't Run When Invoked From R (Symbol Lookup Error) 当从凸轮检测到运动时,OpenCv C ++记录视频 - OpenCv C++ record video when motion detected from cam
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM