1
我发现Qt创建者默认使用OpenCV功能的Qt。OpenCV无法使用Qt打开相机
甚至当运行一个测试代码(见下文)时会打开并显示相机流。在这里,无法打开相机(我正在使用XIMEA xiQ)。使用正常的摄像头,它正在工作。
在Eclipse中这两个工作。
至今我已经做了步骤小结:
- 的OpenCV与XIMEA摄像头支持编译
- 我重新编译的OpenCV使用Qt支持
make uninstall
为OpenCV的make 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();
}