How to link QT and OpenCV in Linux - c++

I'm trying to link QT with the OpenCV library, but I can't.
OpenCV works, Qt works, but I can't work with both together.
I add a build step in the Qt creator, and this kind of work, I mean, I write cv:: and automatically a list has been show with all methods of OpenCV, but when I compile, I have around 20 errors, with OpenCV methods.
But, if i compile the same code in terminal, without Qt, all is fine.
Anyone knows how to link Correctly OpenCV and Qt?
Please help :(
Qt version: 5.2.1
Qt Creator version: 3.0.1
OpenCV version: 2.4.8
PD: remember, I'm using Linux, there are thousands of tutorials about this but in windows :/
PD2: Sorry for my English.
Edit: This is an example of my error, this happen with all OpenCV methods, like imread and waitKey
error: undefined reference to `cv::getRotationMatrix2D(cv::Point_, double, double)'

In your QtCreators Edit view you need to add a link to the library files, on my setup I have this within my .pro file:
CONFIG += use_webcam_opencv
...
use_webcam_opencv {
message("Using OpenCV Webcam")
LIBS += -lopencv_core247 -lopencv_highgui247
HEADERS += widgets/camerawidget.h \
widgets/camerawindow.h
SOURCES += widgets/camerawidget.cpp \
widgets/camerawindow.cpp
}
The HEADERS and SOURCES are of course my own, since I only compile them if I enable OpenCV.

Do you have pkg-config configured/installed with opencv?
You can check by simply typing 'pkg-config pkg-config opencv --libs. If you get any output, you're good.
Then, in QT, just edit .pro project setting file and add the following line(I had to put the image as I didn't know how to put those quotes in an answer) :-
http://imgur.com/DtQ0Zjr
Sample .pro file : http://pastebin.com/KDYqW5Wj
Should Work

Related

Tesseract in QT

This is the first time I am asking a question here.
I want to use Tesseract API in QT.
My idea was to design a programme using QT that would read aloud messages (QSpeech) from Telegram Desktop version (not that important).
Tesseract came across as a tool I needed so I tried to implement it. I wanted to use its API, but finally I ended up using QProcess to call Tesseract as a programme.
HERE'S THE PROBLEM.
After including tesseract and leptonica libraries to .pro file i get this:
(.qtversion[qt_version_tag]+0x0):-1: error: undefined reference to `qt_version_tag'
How to fix it?
I use QT 5_12_3
I included the libs.
INCLUDEPATH += "/usr/include"
LIBS += -L"/usr/local/lib" -ltesseract
INCLUDEPATH += "/usr/include"
LIBS += -L"/usr/lib/x86_64-linux-gnu" -llept
I downloaded QT from the official website. Tesseract API code is an example taken from the documentation. From the same documentation I followed instructions to download everything needed. As I mentioned before, if I compile a text file with the code sample, then it works fine. I just can't integrate it into QT.
Tesseract and Leptonica create pkg-config files, so you didn't have to manually add INCLUDEPATH or LIBS to your project, instead use
QT_CONFIG -= no-pkg-config
Config *= link_pkgconfig
PKGCONFIG *= tesseract
If it doesn't work for you, check whether the Tesseract is installed correctly (also check that you have tesseract.pc file in your system).

How to link DCMTK with Qt on Mac OSX

I am new with all of these Qt, Dcmtk and CMake and I am suppose to use it for a school project. A lot of things are available on the internet but essentially for Windows..
I am trying to link Dcmtk with Qt and make it run on my mac but It is not working, the error is:
Error output
I have already built dcmtk with CMake (note the CMake wasn't generating the right paths...)
I know this error seems recurrent and I should add a LIB += ...
But I tried a lot of different one and I couldn't find anything that solve my problem according to linking dcmtk
Here is my current code according to some found online:
.pro file
main.cpp
I am feeling a bit powerless right now if someone could enlighten me.
Thank you!
Did you forget to link with dcmimage?
try adding LIBS += -ldcmimage

QT Creator: OpenCV dll lib can not be added ("File format not recognized")

I'm trying to get openCV 3.1.0 to work in QT Creator 4.4.1 using this tutorial from their official site.
Right now, I'm setting up my project file. The whole file looks identical to the on in the tutorial apart from the last couple of lines, as my openCV build is in another place and it's a different version This is what I got:
INCLUDEPATH += C:\opencv\opencv-3.1.0\build\include
LIBS += -LC:\opencv\opencv-3.1.0\build\x64\vc14\bin \
libopencv_world310d \
As far as I understand, the "world" module has been introduced to openCV to unify all the different modules into one.
However, when I try to run this, QT produces the following error:
C:\opencv\opencv-3.1.0\build\x64\vc14\bin\opencv_world310d.dll:-1: error: file not recognized: File format not recognized
What am I doing wrong? In the tutorial there's an alternative way to link the libraries which even explicitly states them as .dll files. Why is this a problem?
You need to link to the .lib contained in the lib folder:
LIBS += -LC:\opencv\opencv-3.1.0\build\x64\vc14\lib \
and put the .dll in the PATH, or the same folder of the .exe

how to view a 3D pcd in Qt on Ubunto with PCL library?

I am starting to use PCL library in my project , which is in Qt in Ubuntu.
I have a PCD file and i want to see it.
all the answers I have seen so far are about using visualization library
#include <pcl/visualization/cloud_viewer.h>
which gives me error in my project and according to other discussions this usage is not ment for Qt.
any help on how could i view my pcd file?
thanx
Edit your ".pro" file. This is how I attach Irrlicht to my Qt projects which may have something similar to what you're after. By adding the references for the include directory and the libs directly.
Hope this helps.
win32:INCLUDEPATH += C:\irrlicht-1.8\include
win32:LIBS += c:\irrlicht-1.8\lib\win32-gcc\libirrlicht.a
I found the cause!
it was because I did not have installed the visualization library!
the problem was that I had not checked the output of compiling the PCL library and it had said that it would not compile some modules because of dependency problems.

How to Link Imagemagick library to Qt(windows)

I have developed an application with mac and for one month now, Im trying to link Qt with ImageMagick on windows.
I just cant find the files and the version of Imagemagick library that need to be linked to Qt in order to make my application work on windows.
I have tried most of the libraries from here
Thats the only thing I added to the .pro file while I was developing on a mac
INCLUDEPATH += . /opt/local/include/ImageMagick
LIBS += -L/opt/local/lib -lMagick++
When I add this to my .pro
INCLUDEPATH += C:/im6/include/ImageMagick
LIBS += C:/im6/lib/libMagickWand.a
LIBS += C:/im6/lib/libMagick++.a
LIBS += C:/im6/lib/libMagickCore.a
C:/im6/lib/libMagick++.a
I get 10.000 + simmilar errors to that:
(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `__gxx_personality_sj0'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `_Unwind_SjLj_Register'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4178: undefined reference to `_Unwind_SjLj_Unregister'
For more errors check this
Has anyone tried to build and deploy an ImageMagick application using qt on windows ?
Which files do I need to link while building and which files while deploying ?
The error message tells me that you
use mingw (with qtcreator). Your
library might not work with this
compiler. You need a mingw version
of the library, probably named
libmagick.a.
LIBS += -L$$quote(c:/Program Files/ImageMagick-6.6.5-Q16/lib) -lmagick
(see the documentation about qmake Project Files
I have found that the minGW tool set is very much treated as a "stepchild" in the Windows world. I know it doesn't help your particular situation, but we had numerous problems with third-party libs while trying to use Qt with minGW. There were always extra steps, or non-existent build instructions that we had to figure out or tweak.
Once we switched to the MSVC version, all of those problems went away. Note that this doesn't mean you have to use Visual Studio (you can still use Qt creator), it just means that the Visual Studio compiler is being used. You can get the compiler for free using the Platform SDK. If this is an option, you might save yourself a lot of pain by switching now. It's unfortunate, but that is just the current status quo, at least as we discovered.
Please go get ImageMagick source package.
I can’t give direct instructions how to work with MinGW of Qt Creator, but basically following. I prefer to use qtvars.bat that comes with binary distributions of Qt to set environment.
Open Windows cmd
Set PATH to have /path/to/mingw/bin and /path/to/qt/bin before other paths
Go to directory where you have extracted ImageMagick source
read README, INSTALL and such to compile the ImageMagick (most likely just ./configure ; mingw32-make, but never be sure)
Edit your .pro file with something like LIBS += -L$$quote(/path/to/imagemagick/lib/dir) -lmagick . The lib may be in bin dir or in lib dir. See hmuelner’s answer for more information.
At this point, the configuration should be ready. Compilation at Qt Creator should work, but you can as well use this cmd windows to compile your program: go to program directory, run “qmake” and “mingw32-make”.
You cannot link against a ImageMagick++ library built with MSVC, as mingw and MSVC DLLs are incompatible for C++ libraries. You can't link a MSVC-built C++ library into a mingw project, nor vice versa. C-only libraries work fine. Also, according to this fortum thread, using builds against old mingw-versions with current mingw versions doesn't work as the exception handling changed (as you get more errors than that, I wouldn't expect that to be the only problem though). If there is no binary package for your mingw version (and I don't see any on the imagemagick website), your only option is to use a source package, as Smar suggests.
Another option of course is to install Visual Studio, download Qt for MSVC and build your project with MSVC.