当我运行我的代码时,出现如下错误:
D:\ubunto\OpenCV\opencv\build\include\opencv2\imgproc\imgproc.hpp:50: 错误: opencv2/core/core.hpp: 没有那个文件或目录
我不知道这是因为opencv链接还是其他原因。
您可以在下面找到我的代码。
Form1.h
#ifndef FORM1_H
#define FORM1_H
#include <QDialog>
//#include<highgui.h>
//#include<core/core.hpp>
//#include<cvwimage.h>
#include<opencv.hpp>
#include<imgproc/imgproc.hpp>
//#include <opencv_modules.hpp>
//#include <video/video.hpp>
#include <highgui/highgui.hpp>
namespace Ui {
class Form1;
}
class Form1 : public QDialog
{
Q_OBJECT
public:
explicit Form1(QWidget *parent = 0);
QImage getQImageFromFrame(cv::Mat frame);
~Form1();
private slots:
void on_pushButton_clicked();
void updatePicture();
private:
Ui::Form1 *ui;
cv::Mat *mt;
cv::VideoCapture *video;
QTimer * timer;
QImage *img;
};
#endif // FORM1_H
Form1.cpp
#include "form1.h"
#include "ui_form1.h"
#include <QtCore>
#include <QtGui>
#include <QGraphicsAnchorLayout>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsWidget>
#include "qimage.h"
#include <QFileDialog>
#include <QPixmap>
#include "qpixmap.h"
Form1::Form1(QWidget *parent) :
QDialog(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);
}
QImage Form1::getQImageFromFrame(cv::Mat frame) {
//converts the color model of the image from RGB to BGR because OpenCV uses BGR
cv::cvtColor(frame, frame, CV_RGB2BGR);
return QImage((uchar*) (frame.data), frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
}
Form1::~Form1()
{
delete ui;
}
void Form1::updatePicture()
{
video >> mt;
img = getQImageFromFrame(mt);
ui->label->setPixmap(QPixmap::fromImage(image));
}
void Form1::on_pushButton_clicked()
{
fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), "/elhandasya/Desktop", tr("Image Files (*.png *.jpg *.bmp)"));
//QPixmap pix(fileName);
video->open(filename);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updatePicture());
timer->start(20);
}
还有这个当我调用我的库和文件时
#-------------------------------------------------
#
# Project created by QtCreator 2013-12-16T09:23:28
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Video_Player
TEMPLATE = app
SOURCES += main.cpp\
form1.cpp
HEADERS += form1.h
FORMS += form1.ui
INCLUDEPATH += -I"D:\ubunto\OpenCV\opencv\build\include\opencv2\imgproc"
INCLUDEPATH += -I"D:\ubunto\OpenCV\opencv\build\include\opencv2\core"
INCLUDEPATH += -I"D:\ubunto\OpenCV\opencv\build\include\opencv2"
LIBS += -LD:\ubunto\OpenCV\opencv\build\x86\mingw\bin
-lopencv_core
-lopencv_imgproc
-lopencv_highgui
-lopencv_legacy
-lopencv_gpu
-lopencv_video
-lopencv_ml
-lopencv_contrib
#LIBS += D:\ubunto\emgu\emgucv-windows-x86 2.4.0.1717\lib
#-opencv_calib3d240
#-opencv_videostab240
#-opencv_calib3d240
#-opencv_contrib240
#-opencv_core240
#-opencv_features2d240
#-opencv_flann240
#-opencv_gpu240
#-opencv_highgui240
#-opencv_imgproc240
#-opencv_legacy240
#-opencv_ml240
#-opencv_nonfree240
#-opencv_objdetect240
#-opencv_photo240
#-opencv_stitching240
#-opencv_video240
最佳答案
一开始出现这个错误是因为编译器找不到core.hpp
来自 #include <core.hpp>
进入imgproc.hpp
.
我想你可以尝试改变你的INCLUDEPATH
到:
-
INCLUDEPATH += -I"D:\ubunto\OpenCV\opencv\build\include\"
或 -
INCLUDEPATH += -I"D:\ubunto\OpenCV\opencv\build\include\opencv2\imgproc"
INCLUDEPATH += D:\ubunto\OpenCV\opencv\build\include\opencv2\core
和其他。
其次,你把动态库链接错了。你应该写:
-
LIBS += -L"D:\ubunto\OpenCV\opencv\build\x86\mingw\bin" -lopencv_core -lopencv_imgproc
您应该按以下方式链接库:-l<name_of_concrete_library>
希望对你有帮助。
关于c++ - 将 OpenCV 与 Qt 链接时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20607997/