【问题标题】:Abnormal termination when calling `cvCreateCameraCapture(-1)`调用 `cvCreateCameraCapture(-1)` 时异常终止
【发布时间】:2012-02-07 08:49:40
【问题描述】:

我的代码如下。当我在openCamera 中执行cvCreateCameraCapture(-1) 时,应用程序结束。

提示:程序异常终止。在启动期间程序退出,代码为 0X000135

为什么?电脑是笔记本,内置摄像头。

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

>

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

class MainWindow : public QMainWindow
{
    Q_OBJECT  
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void openCamera();
    void readFrame();
    void closeCamera();
    void takingPhote();

private:
    Ui::MainWindow *ui;
    QTimer* timer;
    QImage* image;
    CvCapture* cam;
    IplImage* frame;
};

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    cam = NULL;
    timer = new QTimer(this);
    image = new QImage;

    connect(ui->openCamera, SIGNAL(clicked()), this, SLOT(openCamera()));
}

void MainWindow::openCamera()
{
   cam = cvCreateCameraCapture(-1);
   // timer->start(33);
   // connect(timer, SIGNAL(timeout()), this, SLOT(readFrame()));
}

【问题讨论】:

  • 什么操作系统?我建议尝试使用0 而不是1,在调用执行后,检查它的返回:if (!cam) qDebug() &lt;&lt; "!!! cam failed";
  • 操作系统是win7、按运行键提示:1:RUN 2:异常终止 3:结束。即该应用程序不起作用。如果我没有使用opencv函数,它可以正常运行。有什么问题,或者我需要设置环境变量来运行 opencv?谢谢你..
  • 我希望您将 cvCreateCameraCapture() 调用替换为其他内容,例如 cvWaitKey(0);。如果这是与环境变量相关的运行时问题并且 Windows 未找到 OpenCV,则会显示此简单测试。如果继续崩溃,那可能真的和环境配置有关。
  • 是的,环境配置是重点..我已经解决了。谢谢你帮助我...

标签: c++ qt opencv


【解决方案1】:

添加我之前的评论作为答案,因为它可以帮助您解决问题:

我希望您将 cvCreateCameraCapture() 调用替换为其他内容,例如 cvWaitKey(0);。如果这是与环境变量相关的运行时问题并且 Windows 未找到 OpenCV,则会显示此简单测试。所以,如果它继续崩溃,那么它可能真的与环境配置有关。

【讨论】:

    猜你喜欢
    • 2016-12-23
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多