1

I am trying to configure a new Qt Creator project in order to use OpenCV 3.1.0 in Windows 10. I downloaded the precompiled binaries from http://opencv.org/downloads.html, and I created an empty Qt gui project. The problem is that qmake doesn't find the opencv headers, no matter how I try to include their path. Here is my last attempt:

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = App_v1
TEMPLATE = app

INCLUDEPATH += C:/OpenCV-3.1.0/opencv/build/include
LIBS += -L”C:\OpenCV-3.1.0\opencv\build\x64\vc14\lib”
LIBS += -lopencv_world310d

SOURCES += main.cpp\
        mainwindow.cpp
HEADERS  += mainwindow.h
FORMS    += mainwindow.ui

And the source:

#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include "mainwindow.h"
#include <QApplication>

using namespace std;

int main(int argc, char *argv[])
{
    cv::Mat image = cv::Mat::zeros(100, 100, CV_8UC3);
    cv::imshow("image", image);
    cv::waitKey(10);

    cout << "Hello cout!" << endl;
    cerr << "Hello cerr!" << endl;
    printf("Hello printf!");
    cout << flush;

    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

When I try to compile this, I get: "C1083: Cannot open include file: 'opencv2/core/core.hpp": No such file or directory (btw thanks Qt Creator for not letting me select and copy the text of the error. Sorry I digress...)

I am sure that the path is correct, and the funny thing is that when I type cv:: the auto completion finds and lists the classes and functions in the cv namespace.... what is going on here?

And btw, OpenCV works perfectly with Visual Studio, so I know that It is installed correctly...

2
  • 1
    Shouldn't it be C:\OpenCV-3.1.0\opencv\build\x64\vc14\lib instead of C:\OpenCV-3.1.0\opencv\build\x64\vc14\bin ? Commented Jun 16, 2016 at 13:29
  • @Sunreef Yes indeed. That was my second mistake, and it caused a linking error (corrected now). In this case, core.hpp could not be loaded not because of an incorrect setting in the .pro file, but because the project needed a cleaning... Commented Jun 17, 2016 at 9:13

1 Answer 1

1

It turns out that the problem was that the project needed a cleaning... I did not think about it, since I am used to visual studio. I believe that the cleaning step should be performed automatically before each rebuild, since it does not make sense that some leftovers from previous builds make the current build fail...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.