Error while opening a video with OpenCV and Qt - c++

I have about 15 errors, when I want to get a video capture to view it frame by frame in an image.
First I call my video from my link.
Then get from it my frame.
Then convert it into image.
Finally view it in pixmap.
MY CODE
#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);
video->open("D:/Downloads/DirectX/Zlatan Ibrahimovic ● Taekwondo Goals.mp4");
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updatePicture()));
timer->start(20);
}
QString fileName;
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()
{
cv::Mat frame1;
video->operator >>( frame1);
img = getQImageFromFrame(frame1);
ui->label->setPixmap(QPixmap::fromImage(img));
}
void Form1::on_pushButton_clicked()
{
//fileName = QFileDialog::getOpenFileName(this,
//tr("Open Image"), "/elhandasya/Desktop", tr("Image Files (*.png *.jpg *.bmp)"));
//QPixmap pix(fileName);
}
'
The errors like this:
undefined reference to `cv::Mat::Mat()
D:\ubunto\QT5\Tools\QtCreator\bin\Video_Player-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug\debug\form1.o:-1: In function `ZN5Form1D2Ev'
My LIBS
#-------------------------------------------------
#
# 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/"
#INCLUDEPATH += "D:/ubunto/OpenCV/opencv/build/include/"
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

If you take a look at the source code of cvVideo (an application that shows how to create a Qt window to display videos loaded with OpenCV) you can see how to achieve what you are looking for.
cvVideo.pro:
TEMPLATE = app
QT += core gui
contains(QT_VERSION, ^5\\.[0-8]\\..*) {
message("* Using Qt $${QT_VERSION}.")
QT += widgets
# On my system I have to specify g++ as compiler else it will use clang++ by default
#QMAKE_CXX=g++
#QMAKE_CC=gcc
}
HEADERS += \
cvWindow.h
SOURCES += \
main.cpp \
cvWindow.cpp
## OpenCV settings for Unix/Linux
unix:!mac {
message("* Using settings for Unix/Linux.")
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}
## OpenCV settings for Mac OS X
macx {
message("* Using settings for Mac OS X.")
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib/ \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc
}
## OpenCV settings for Windows and OpenCV 2.4.2
win32 {
message("* Using settings for Windows.")
INCLUDEPATH += "C:\\opencv\\build\\include" \
"C:\\opencv\\build\\include\\opencv" \
"C:\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\opencv\\build\\x86\\vc10\\lib" \
-lopencv_core242 \
-lopencv_highgui242 \
-lopencv_imgproc242
}
# Runs this app automatically after the building has succeeded
#QMAKE_POST_LINK=./$$TARGET

Error tells you that you have to link, in you makefile, the specific library that include Mat:
-lopencv_core
Take a look at the documentaion.
When there are errors like:
In function `ZN5Form1D2Ev'
It could be that you have two different opencv version installed, isn't it?

Related

Qt + Ogre3D. I cannot build a very simple example

I use:
Qt 5.15.2 MinGW 32-bit Dynamic for Debug build
Ogre 13.1.1 MinGW Static build
There is a class called ApplicationContextQt that can help to use Qt with Ogre3D but I have errors:
This example is very simple:
main.cpp
#include "Ogre.h"
#include "OgreApplicationContextQt.h"
#include <QGuiApplication>
class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener
{
public:
MyTestApp();
void setup();
bool keyPressed(const OgreBites::KeyboardEvent& evt);
};
MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp")
{
}
bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
return true;
}
void MyTestApp::setup(void)
{
// do not forget to call the base first
OgreBites::ApplicationContextQt::setup();
}
int main(int argc, char *argv[])
{
QGuiApplication qapp(argc, argv);
MyTestApp app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
return qapp.exec();
}
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"
LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib"
LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib\OGRE"
LIBS += -lOgreBitesQtStatic
LIBS += -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic
LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml
LIBS += -lopengl32 -lgdi32
You can try this one ?
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"
LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic" -lOgreBitesQtStatic
LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OGRE" -lOgreBitesStatic
// OR ...
LIBS += "E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic/OgreBitesQtStatic.a"
LIBS += "E:/ProgramFiles/ogre-13.1.1/lib/OGRE/OgreBitesStatic.a"
// It just depends on the actual names of your libraries
// Same for the others unless their file location is decleared under system path.
// If so, you can add that libraries like how you did with opengl
And it is nice to add PRE_TARGETDEPS macros too if you make changes on those libraries so often:
PRE_TARGETDEPS += "E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic.a"
You can replace "/"s with "" too.
And the problem with your pro file was: You added library paths as libraries. And then tried to add that libraries from system environment.

Qt app crashing on linking with DLL made using Qt

Before asking the problem, I would like to tell that i have thoroughly searched for the answer here. None of them seems to address my issue.
Problem:
I have created a simple C++ DLL file using Qt after following steps given on the Qt wiki the problem is though the DLL is created and I have linked it to my Qt widget app, the app crashes on creating the object of the file.
Here I am posting the source code and the qdebug output
libraray Qt pro
QT += core gui widgets
TARGET = myLib
TEMPLATE = lib
DEFINES += MYLIB_LIBRARY
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
mylib.cpp
HEADERS += \
mylib.h \
mylib_global.h
unix {
target.path = /usr/lib
INSTALLS += target
}
mylib.h
#ifndef MYLIB_H
#define MYLIB_H
#include "mylib_global.h"
class MYLIBSHARED_EXPORT MyLib
{
public:
MyLib();
int add(int x, int y);
int sub(int x, int y);
};
#endif // MYLIB_H
mylib_global.h
#ifndef MYLIB_GLOBAL_H
#define MYLIB_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(MYLIB_LIBRARY)
# define MYLIBSHARED_EXPORT Q_DECL_EXPORT
#else
# define MYLIBSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // MYLIB_GLOBAL_H
mylib.cpp
#include "mylib.h"
#include<QDebug>
MyLib::MyLib()
{
}
int MyLib::add(int x, int y)
{
qDebug()<<"Adding";
return x+y;
}
int MyLib::sub(int x, int y)
{
return x-y;
}
Now the app
myWidgetApp.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = myWidgetApp
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
INCLUDEPATH += "D:\Gurushant\My Other Side Projects\Making dll Files\myLib"
LIBS += "D:\Gurushant\My Other Side Projects\Making dll Files\build-myLib-Desktop_Qt_5_9_1_MinGW_32bit-Release\release\myLib.dll"
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"mylib.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
MyLib lib;
lib.add(1,2);
}
MainWindow::~MainWindow()
{
delete ui;
}
Now the application output
D:\Gurushant\My Other Side Projects\Making dll Files\build-myWidgetApp-Desktop_Qt_5_9_1_MinGW_32bit-Release\release\myWidgetApp.exe crashed.
I am using Windows 7 Professional with Qt 5.9.1
So far after doing a lot of trial and error, the best way to include the library is to
INCLUDEPATH += (Your_Path)
DEPENDPATH += (Your Path)
(if your target path is win32)
win32:CONFIG(release, debug|release): LIBS += -L(path) -l(lib_file_without_dot_dll)
don't use space after -L

'_nextafter' not declared : CGAL in Qt Creator with Windows 8.1

I've build CGAL like explained here.
Everything went well.
But now, I'm using Qt Creator with CGAL.
I've included the libraries in the .pro file :
QT += core
QT -= gui
TARGET = TestCCGALAppliConsole
CONFIG += console
CONFIG -= app_bundle
CONFIG += c++11
TEMPLATE = app
INCLUDEPATH += /usr/local/include
DEPENDPATH += /usr/local/include
LIBS += -L/usr/local/include
macx: LIBS += -L/usr/local/lib/ -lgmp
macx: LIBS += -L/usr/local/lib/ -lmpfr
macx: LIBS += -L/usr/local/lib/ -lCGAL
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/CGAL-4.6/build/lib/release/ -lCGAL-vc100-mt-gd-4.6
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/CGAL-4.6/build/lib/debug/ -lCGAL-vc100-mt-4.6
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/build/lib/Debug
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/build/lib/Debug
INCLUDEPATH += C:\local\CGAL-4.6\include
win32: LIBS += -L$$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/lib/ -llibgmp-10
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
win32: LIBS += -L$$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/lib/ -llibmpfr-4
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_system-vc100-mt-1_57
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_system-vc100-mt-gd-1_57
INCLUDEPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
DEPENDPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_thread-vc100-mt-1_57
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_thread-vc100-mt-gd-1_57
INCLUDEPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
DEPENDPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
INCLUDEPATH += C:\local\boost_1_57_0
and in my main.cpp I have :
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K, CGAL::Polyhedron_items_with_id_3> Polyhedron;
typedef Polyhedron::Vertex_iterator Vertex_iterator;
int main() {
Polyhedron mesh;
std::ifstream input("inner.off");
if ( !input || !(input >> mesh) || mesh.empty() )
{
//Debug
std::cerr << "Not a valid off file." << std::endl;
return 0;
}
for (Vertex_iterator v = mesh.vertices_begin() ; v!= mesh.vertices_end() ; ++v )
{
std::cout << v->point() << std::endl;
}
std::cout << "Hello You" << std::endl;
return 0;
}
when I compile (with MinGW 4.9.1 32 bit with Qt 5.4.1) I'm having this error :
C:\local\CGAL-4.6\include\CGAL\double.h:191: erreur : '_nextafter' was
not declared in this scope return _nextafter(d1, d2); // works at
least for VC++-7.1
I can't figure out what's wrong...
Can you help me ?
EDIT
It seems that CGAL being compiled with Visual Studio C++ Compiler 10 involves that I have to compile with this compiler and not MinGW.
So I changed compile, I'm now using Microsoft Visual C++ Compiler 10 (amd64) in Qt Creator, but it still don't work. I have an error :
impossible to open 'CGAL-vc100-mt-4.6.lib' file
Here's the complete error (sorry, french version...) :
17:42:15: Exécution des étapes pour le projet TestCCGALAppliConsole...
17:42:15: Configuration inchangée, étape qmake sautée.
17:42:15: Débute : "C:\Qt\Tools\QtCreator\bin\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc /Fddebug\TestCCGALAppliConsole.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -I"..\TestCCGALAppliConsole" -I"." -I"\usr\local\include" -I"..\..\..\..\local\CGAL-4.6\build\lib\Debug" -I"..\..\..\..\local\CGAL-4.6\include" -I"..\..\..\..\local\CGAL-4.6\auxiliary\gmp\include" -I"..\..\..\..\local\CGAL-4.6\auxiliary\gmp\include" -I"..\..\..\..\local\boost_1_57_0\lib64-msvc-10.0" -I"..\..\..\..\local\boost_1_57_0\lib64-msvc-10.0" -I"..\..\..\..\local\boost_1_57_0" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\include" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\include\QtCore" -I"debug" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\mkspecs\win32-msvc2010" -Fodebug\ #C:\Users\Raphael\AppData\Local\Temp\main.obj.1988.32.jom
main.cpp
echo 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "debug\\TestCCGALAppliConsole.exe.embed.manifest">debug\TestCCGALAppliConsole.exe_manifest.rc
if not exist debug\TestCCGALAppliConsole.exe if exist debug\TestCCGALAppliConsole.exe.embed.manifest del debug\TestCCGALAppliConsole.exe.embed.manifest
if exist debug\TestCCGALAppliConsole.exe.embed.manifest copy /Y debug\TestCCGALAppliConsole.exe.embed.manifest debug\TestCCGALAppliConsole.exe_manifest.bak
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\TestCCGALAppliConsole.exe.embed.manifest /OUT:debug\TestCCGALAppliConsole.exe #C:\Users\Raphael\AppData\Local\Temp\TestCCGALAppliConsole.exe.1988.5000.jom
LINK : fatal error LNK1104: impossible d'ouvrir le fichier 'CGAL-vc100-mt-4.6.lib'
jom: C:\Users\Raphael\Desktop\build-TestCCGALAppliConsole-Desktop_Qt_5_4_1_MSVC2010_x64-Debug\Makefile.Debug [debug\TestCCGALAppliConsole.exe] Error 1104
jom: C:\Users\Raphael\Desktop\build-TestCCGALAppliConsole-Desktop_Qt_5_4_1_MSVC2010_x64-Debug\Makefile [debug] Error 2
17:42:21: Le processus "C:\Qt\Tools\QtCreator\bin\jom.exe" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet TestCCGALAppliConsole (kit : Desktop Qt 5.4.1 MSVC2010 x64)
When executing step "Make"
17:42:21: Temps écoulé : 00:05.
Well, it's right there in your message:
when I compile (with MinGW
versus
works at least for VC++-7.1
_nextafter is a Microsoft extension used by CGAL. MinGW doesn't appear to support it.

glew linking problems qt creator qmake

I am trying to get a project working with SDL2, assimp, opengl, and glew and cannot get glew to link properly (almost a duplicate but a more comprehensive question and answer, I think).
My qmake .pro file :
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
HEADERS += \
objloader.h \
display.h \
eventloop.h \
shader.h \
texture.h
SOURCES += main.cpp \
objloader.cpp \
display.cpp \
eventloop.cpp \
shader.cpp \
texture.cpp
INCLUDEPATH += "C:/code middleware/glew-1.12.0/include/" \
"C:\code middleware\glm\\" \
"C:\code middleware\SDL2-2.0.3\include\\" \
"C:\Users\smart_000\Desktop\assimp\include\\"
DEPENDPATH += "C:/code middleware/glew-1.10.0/bin/Release\Win32/" \
"C:\code middleware\SDL2-2.0.3\lib/x86/" \
"C:/Users/smart_000/Desktop/assimp/bin/" \
"C:/code middleware/glew-1.12.0/lib/Release/Win32/" \
"C:/code middleware/glew-1.12.0/bin/Release/Win32/"
LIBS += -L"C:\code middleware\SDL2-2.0.3\lib\x86" -lSDL2main -lSDL2
LIBS += -L"C:/Users/smart_000/Desktop/assimp/lib/" -lassimp.dll -lzlib
LIBS += -lopengl32
LIBS += -lglu32
LIBS += -L"C:/code middleware/glew-1.12.0/lib/Release/Win32/" -lglew32 -lglu32
The linker errors I am getting: linker errors
What I have tried already:
Checking file path problems ('/' and '\' kind of stuff and spaces in file names etc.)
Linking dynamically and statically (Yes, I defined GLEW_STATIC where I needed to, and I linked to -lglew32s and such)
SDL stuff: messing with and defining 'NO_SDL_GLEXT' above it
Making test programs and trying to link it with just g++ (I used the -static flag where I should have when I tried the static one and placed the linker flags after the files that needed them). These errors were the same as the qt ones minus the warnings.
Putting the glew source code directly in my project and building it (exact same errors) --- The issues were eerily similar and made no sense to me. I had commented out the qmake stuff and re ran qmake; I wasn't aware I could get linker errors like that if I put it in my project like I did.
Running qmake after my changes, lol
Moving 'LIBS' and 'DEPENDPATH' around and added 'CONFIG += opengl' in desperation
Messing with debug and release builds.
What I haven't tried:
Moving libraries and things to the system path
MAKING SURE THE LIBRARIES WERE BUILT FOR MINGW!
The relevant code(I know it's terrible; I was just hacking around when I encountered these issues) :
"main.cpp" :
#include <GL/glew.h>
#include <iostream>
#include <SDL.h>
#include <objloader.h>
#include "display.h"
#include "eventloop.h"
Display* display = NULL;
void callback()
{
std::cout << "yay" << std::endl;
display->Swap();
}
int main(int argc, char* argv[])
{
UShortVector indices;
Vec3Vector vertices;
Vec2Vector uvs;
Vec3Vector normals;
bool success = ObjLoader::loadObj("cube.obj", indices, vertices, uvs, normals);
display = new Display();
EventLoop eventLoop;
eventLoop.SetLoopCallback(&callback);
display->Create("yay");
eventLoop.Start();
return 0;
}
"display.h"
#ifndef DISPLAY_H
#define DISPLAY_H
#include <GL/glew.h>
#include <SDL.h>
#include <iostream>
class Display
{
public:
Display();
~Display();
void Create(const char* title);
void Swap();
SDL_Window* window_ = NULL;
SDL_GLContext glContext_;
};
#endif // DISPLAY_H
"shader.h"
#ifndef SHADER_H
#define SHADER_H
#include <GL/glew.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <memory.h>
class Shader
{
public:
GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path);
private:
Shader();
~Shader();
};
#endif // SHADER_H
"shader.cpp"
#include "shader.h"
Shader::Shader()
{
}
Shader::~Shader()
{
}
GLuint Shader::LoadShaders(const char * vertexShaderPath, const char * fragmentShaderPath)
{
FILE* vertexFile = fopen(vertexShaderPath, "r");
FILE* fragmentFile = fopen(fragmentShaderPath, "r");
if(!vertexFile || !fragmentFile)
{
if(!vertexFile)
{
perror("could not open the vertex shader file");
}
if(!fragmentFile)
{
perror("could not open the fragment shader file");
}
}
GLuint programID = glCreateProgram();
GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);
const size_t MAX_LINE_LENGTH = 120;
char line[MAX_LINE_LENGTH];
std::vector<GLchar*> vertShaderSource;
std::vector<GLchar*> fragmentShaderSource;
while(fgets(line, MAX_LINE_LENGTH, vertexFile) != NULL)
{
vertShaderSource.push_back((GLchar*)line);
memset((void*)line, '\0', sizeof(line));
}
while(fgets(line, MAX_LINE_LENGTH, fragmentFile) != NULL)
{
fragmentShaderSource.push_back((GLchar*)line);
memset((void*)line, '\0', sizeof(line));
}
glShaderSource(vertShader, vertShaderSource.size(), (const GLchar**)&vertShaderSource, NULL);
glShaderSource(fragShader, fragmentShaderSource.size(), (const GLchar**)&fragmentShaderSource, NULL);
// doesn't do anything at the moment, I know. It should still compile though.
return programID;
}
Right after I posted the question, I found the issue. Embarrassingly, it was an issue I have run into before with assimp (although I just now realized why re-building it with cmake worked).
The hallmarks:
Weird linker errors with a library when you know the library is being found.
You primarily work on a windows system :)
The solution:
Check the build kit that you are using with Qt creator Vs. the libs you are using.
I was using the MINGW one only and my libs were compiled using the MSVC++ compiler
The libs you are looking for are .a files: specifically lib{name}.a . In this case, I was looking for libglew32.dll.a <- note the .dll in there for whether it is a dll import library or a static one like libglew32s.a <- note the s for static.
Where to go to get the rights libs :
- Go here for building it: Building glew on windows with mingw.
- Go here to download the pre-built one that I did (older version of glew): https://launchpad.net/glew-cmake/+milestone/1.10.0
The Download link that I used: glew-gcc-1.10.0-win32.zip (md5) Glew-Cmake 1.10.0 Binaries (MinGW) <- I tried to post a picture, but apparently, I am not cool enough to do that yet.
My updated and working qmake .pro file :
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
HEADERS += \
objloader.h \
display.h \
eventloop.h \
shader.h \
texture.h
SOURCES += main.cpp \
objloader.cpp \
display.cpp \
eventloop.cpp \
shader.cpp \
texture.cpp
INCLUDEPATH += "C:/code middleware/glew-gcc-1.10.0-win32/include/" \
"C:/code middleware/glm/" \
"C:/code middleware/SDL2-2.0.3/include/" \
"C:/Users/smart_000/Desktop/assimp/include/"
DEPENDPATH += "C:/code middleware/SDL2-2.0.3/lib/x86/" \
"C:/Users/smart_000/Desktop/assimp/bin/" \
"C:/code middleware/glew-gcc-1.10.0-win32/lib/" \
"C:/code middleware/glew-gcc-1.10.0-win32/bin/"
LIBS += -L"C:/code middleware/SDL2-2.0.3/lib/x86" -lSDL2main -lSDL2
LIBS += -L"C:/Users/smart_000/Desktop/assimp/lib/" -lassimp.dll -lzlib
LIBS += -L"C:/code middleware/glew-gcc-1.10.0-win32/lib/" -lglew32.dll
LIBS += -lopengl32
LIBS += -lglu32
Note: Don't forget the .dll on the end of the libs (-lglew32.dll).
- Happy Linking!

Using OpenCV with Qt

I have been trying to use OpenCV with Qt Creator, but I had no success. I read lot of forums but none helped.
Here is my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <qDebug>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cv::Mat image = cv::imread("lol.jpg");
cv::namedWindow("MyImage",45);
cv::imshow("MyImage",image);
qDebug()<<"TEST-OCV-1";
cv::waitKey(1000);
return a.exec();
}
My .pro File
QT += core
QT -= gui
TARGET = ocv1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += F:/OpenCV/opencv/build/include
LIBS += -LF:/OpenCV/opencv/build/x64/vc12/bin \
-llibopencv_core240d \
-llibopencv_highgui240d \
-llibopencv_imgproc240d \
-llibopencv_features2d240d \
-llibopencv_calib3d240d \
I have also tried including the libs like
LIBS += -LF:/OpenCV/opencv/build/x64/vc12/lib \
-lopencv_core249 \
-lopencv_highgui249 \
-lopencv_imgproc249 \
-lopencv_features2d249 \
-lopencv_calib3d249 \
And
LIBS += -LF:/OpenCV/opencv/build/x64/vc12/lib \
-lopencv_core249 \
-lopencv_highgui249 \
-lopencv_imgproc249 \
-lopencv_features2d249 \
-lopencv_calib3d249 \
But I keep getting this error, though a command prompt starts it just as the text press enter to exit.
Starting C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-ocv1-Desktop_Qt_5_2_0_MSVC2012_64bit-Debug\debug\ocv1.exe...
C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-ocv1-Desktop_Qt_5_2_0_MSVC2012_64bit-Debug\debug\ocv1.exe exited with code -1073741515