我发现 Qt 创建者默认使用 Qt 作为 OpenCV 函数。
甚至运行打开并显示相机流的测试代码(见下文)时。在这里,无法打开相机(我使用的是 XIMEA xiQ)。使用普通的网络摄像头,它可以正常工作。
在 Eclipse 中,两者都在工作。
到目前为止我已完成的步骤的简要总结:
- OpenCV 编译时带有 XIMEA 摄像头支持
- 我用 Qt 支持重新编译了 OpenCV
make uninstall
对于当前安装的 OpenCVmake install
对于启用了新的 XIMEA 和 Qt 支持的安装
我的测试代码:
#include "mainwindow.h"
#include <QApplication>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char *argv[]){
QApplication a(argc, argv);
MainWindow w;
w.show();
VideoCapture cap(0);
if (!cap.isOpened()){
cout << "Cannot open the video cam" << endl;
return -1;
}
while (1){
Mat frame;
bool bSuccess = cap.read(frame);
if (!bSuccess){
cout << "Cannot read a frame from video stream" << endl;
break;
}
imshow("MyVideo", frame);
if (waitKey(30) == 27){
cout << "esc key is pressed by user" << endl;
break;
}
}
return a.exec();
}