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