Building an OpenCV application in QT Creator - qt

I built OpenCV with CMake under Visual studio 10, copied the binaries to a /bin folder in the opencv directory. I have a simple OpenCV program with no syntax errors, but I am getting several errors such as "undefined reference to cv::imread". Why is this?
My .pro file has the following appended at the end of it:
INCLUDEPATH += C:/opencv/build/include/
LIBS += -LC:/opencv/build/x64/vc10/lib \
-lopencv_core231 \
-lopencv_highgui231 \
-lopencv_imgproc231 \
-lopencv_features2d231 \
-lopencv_calib3d231
Thanks

undefined reference instead of unresolved external symbol means you are probably using MinGW for your application, and you can't use gcc with a VC++ compiled C++ library.

Related

Must compile Opencv with Mingw in order to use in QT under Windows?

I've visit these blogs
https://zahidhasan.wordpress.com/2014/08/19/qt-5-3-1-64-bit-mingw-windows/
How to link opencv in QtCreator and use Qt library
http://www.cnblogs.com/grandyang/p/4328896.html
All of them are using Mingw to compile Opencv through Cmake.
If I want to use Opencv in QT, is compiling with Mingw the only way?
I have this question because I already compiled my Opencv 2.4.11 with Visual Studio 2013(in Cmake---Visual Studio 12 2013 Win64),
when I follow the directions setting up the INCLUDEPATH and LIBS in QT
"C:\\opencv2.4.11\\opencv\\build\\include\\opencv"
"C:\\opencv2.4.11\\opencv\\build\\include\\opencv2"
-L"C:\\opencv2.4.11\\opencv\\build\\x64\\vc12\\lib" \
-lopencv_core2411 \
-lopencv_highgui2411 \
-lopencv_imgproc2411 \
-lopencv_features2d2411 \
-lopencv_calib3d2411 \
I get this error message:
C1083:Cannot open include file:'opencv2/opencv.hpp': No such file or directory
You can compile it with Visual Studio as well. The opencv includepaths already have the opencv2 part of it. So the correct includepath would only be:
C:\\opencv2.4.11\\opencv\\build\\include

including opencv libraries with qtsdk 1.2.1

I have been struggling recently to get opencv to work with qt. At this moment my issue is this: It cant find the libraries. No matter what I do it says the same thing:
:-1: error: LNK1104: cannot open file 'opencv_improc245d.lib'
I included the bin in my path variable, and added each file to libs:
INCLUDEPATH += C:\\OpenCV-2.4.5\\opencv\\build\\include
LIBS += -LC:\\OpenCV-2.4.5\\mybuild\\lib\\Debug \
-lopencv_calib3d245d \
-lopencv_contrib245d \
-lopencv_core245d \
-lopencv_features2d245d \
-lopencv_flann245d \
-lopencv_gpu245d \
-lopencv_highgui245d \
-lopencv_improc245d \
-lopencv_legacy245d \
-lopencv_ ml245d \
-lopencv_ objdetect245d \
-lopencv_ ts245d \
-lopencv_ video245d
also, my opencv library is compiled from source for msvc2010 with qt enabled, and my qt is using msvc2010 as it's compiler.
Am I adding the libraries wrong or is something wrong with my includepath?
Look in the leftmost pane of Qt Creator. There is a Projects tab. (ctrl+5) should reach you there. Go to Build Environment. Click on Details to get list of System Environment Variables. Goto INCLUDE variable in the list. Select and click Edit. Add path_to_opencv/opencv/build/include.
[ path_to_opencv is the path where your opencv directory resides.]
Clean the project, run qmake and build the project again.

Qt Creator release mode undefined references to std::out_of_range

I'm writing a small C++ program (with a GUI) with Qt Creator and compiling with MinGW. Everything works fine when I compile the project in debug mode but as soon as I move to release mode I get compiler errors:
undefined reference to 'std::out_of_range::~out_of_range()' thread.cpp
When I click on the error I also get:
File not found: thread.cpp
I have looked through my Boost installation and found thread.cpp and it should be on the include path for my project.
Any ideas?
EDIT: Here is my .pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2012-08-10T12:09:39
#
#-------------------------------------------------
QT += core gui
TARGET = GeneDropWin
TEMPLATE = app
SOURCES += main.cpp \
genedrop.cpp \
mainbody.cpp \
biofunctions.cpp \
fileio.cpp \
settings.cpp
HEADERS += genedrop.h \
geneclasses.h \
paramclass.h \
mainbody.h \
biofunctions.h \
fileio.h \
geneclasses.h \
settings.h
FORMS += genedrop.ui \
settings.ui
#Stuff I've added
INCLUDEPATH += "C:\\Program Files\\boost_1_50_0"
LIBS += -L"C:\\Program Files\\boost_1_50_0\\stage\\lib" -lboost_thread-mgw46-mt-1_50 -lboost_system-mgw46-mt-1_50 -lboost_date_time-mgw46-mt-1_50 -lboost_chrono-mgw46-mt-1_50
CONFIG += static \
release
RESOURCES += \
NIABLogo.qrc
Ok, the problem is fixed but perhaps not completely understood. I fixed it by switching compiler to MSVC and changing the syntax for the linker options (e.g. -lboost_thread-mgw46-mt-1_50 -> -llibboost_thread-vc100-mt-1_50), compiles without an issue now. I will put forward my reasoning as to what I think may have been the problem but would appreciate a better answer if wrong:
Although I thought I had built the Boost libraries with MinGW when looking through the installation I found a number of folders mentioning msvc instead (e.g. ...boost\bin.v2\libs\date_time\build_msvc-10.0) which suggested to me that I had built it with MSVC.
The linker error claimed not to be able to find files associated with thread.cpp.
Looking at the thread folder of the build directory all the .obj and .lib files had msvc-10.0 folders in their path.
Thus I think that the MinGW compiler was looking for boost objects within a non-existent MinGW folder and so was failing. The fact that it worked under debug mode I guess relates to a less-constrained search for files.

QT Creator integration with Physx

Is there any way to integrate Qt and Physx so i can use Physx inside Qt Creator?
Unfortunately PhysX is compiled against the /MT (static run-time version), while Qt MSVC uses /MD. Meaning you will have to build a Qt MSVC static build with /MT. Even if you get it to run using Qt's shared version you will run into the following warning and possible problems:
defaultlib 'LIBCMT' conflicts with use of other libs...
This stackoverflow answer will help you get you started for a qt static build: How to build Qt 4.8/5.2 statically under VS2012, using the static MSVC runtime, with Windows XP support?
To use the PhysX library with Qt MSVC (MinGW is not compatible with PhysX), here's an example qmake configuration.
PHYSX = /path/to/physx/library
INCLUDEPATH += $${PHYSX}/Include
LIBS += -L$${PHYSX}/Lib/win64
LIBS += \
-lPhysX3CharacterKinematic_x64 \
-lPhysX3_x64 \
-lPhysX3Common_x64 \
-lPhysX3Cooking_x64 \
-lPhysX3Extensions \
-lPhysX3Vehicle \
-lPhysXProfileSDK \
-lPhysXVisualDebuggerSDK \
-lPxTask

How to use Dcmtk in Qt?

I am working on a project where I have to read a dicom image.
I am unable to install dcmtk. I am using win7 64-bit and vs2010.
Please explain the procedure to include dcmtk in my program.
To use the Windows + DCMTK + QT, you need to execute these follow steps:
Compile the DCMTK (Step 1.A)
Create your sample application (Step 2)
Create your QT project file referring the compiled/installed DCMTK Libs (Step 3.B)
Compile your application in your IDE (Step 4.B)
If you are reading this and don't want to use the Qt, I am answering a version without Qt as well.
Windows+VisualStudio+DCMTK: Steps 1.A, 2, 3.A and 4.A
Linux+GCC+DCMTK: Steps 1.B, 2, N/A, 4.C
1) Compile the DCMTK
First of all, to use the DCMTK library in your application, you should compile the DCMTK source code to generate the libraries:
While I am writing this, the last available version is 3.6.0. So, we should download it:
ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip
After the download is finished, you need to unzip the folder. The DCMTK source doesn't have a project file, but it is not a problem, there is a CMakelist file responsible for generating a project file in your desirable Operational System/Compiler. If you are not familiar with CMake tool, you can read more here (https://cmake.org/)
1.A) Compiling on Windows/Visual Studio 2012
1.A.1) You need to have an installed compiler, in my case, it was the Visual Studio 2012
1.A.2) Run the CMake tool to generate a project file to Visual Studio 2012. You need be able to fill the source DCMTK directory.
1.A.3) Now, execute the VisualStudio 2012, open the file sln created in the previous step (2) and compile the target ALL_BUILD
1.A.4) Re-Execute VisualStudio in Admin mode (because of permission C:\Program Files) to compile the target INSTALL (it will copy and install the DCMTK to default path: C:/Program Files/DCMTK/, we can reference it such PATH_WHERE_DCMTK_WAS_INSTALLED)
(1.B) Compiling on GNU/Linux GCC
I have tested at Ubuntu/CentOS. The first, you should go to DCMTK Source and run these following three commands:
$ ./configure --prefix=path_to_dcmtk
$ make all
$ sudo make install
example: path_to_dcmtk = /home/user/dcmtk
2) Creating your sample application
Create a file called your_sample/testapp.cxx with the following content. This a demonstration found in DCMTK Forum to open a DICOM file and print the patient's name.
#include "dcmtk/dcmdata/dctk.h"
#include <iostream>
using namespace std;
int main()
{
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("test.dcm");
if (status.good())
{
OFString patientsName;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientsName).good())
{
cout << "Patient's Name: " << patientsName << endl;
}else{
cerr << "Error: cannot access Patient's Name!" << endl;
}
}else{
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
}
return 0;
}
3) Creating the Application Project using the VisuaStudio as Compiler
The created file at the previous step needs to be placed in a project. You can choose between the option Windows VisualStudio (3.1) and Windows Qt (3.2). If you are using Linux, you can skip this step.
3.A) Windows with Visual Studio 2012 IDE
To create a Visual Studio project, you can use the Wizard and set the necessary settings such: Linker, Libraries, etc. However, to make easier on this answer, I will use the CMakeList.txt to create a Project for Visual Studio 2012. So, please, create a file called your_sample/CmakeList.txt with the following content:
PROJECT(testapp)
SET(DCMTK_DIR ABSOLUTE_PATH_WHERE_DCMTK_WAS_INSTALLED)
#an example: SET(DCMTK_DIR "C:\\Users\\test\\test_dcmtk\\DCMTK")
# settings for Microsoft Visual C++ 6
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
ADD_DEFINITIONS(-D_REENTRANT)
INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)
ADD_EXECUTABLE(testapp testapp)
TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata)
3.B) Windows QtCreator IDE using the VisuaStudio as Compiler
To create a project file for QtCreator IDE. You need to create a file called your_sample/my_project.pro with the following content:
SOURCES += testapp.cxx
CONFIG += debug console
DEFINES += _REENTRANT
QMAKE_CFLAGS_RELEASE -= -MD
QMAKE_CFLAGS_RELEASE = -MT
QMAKE_CFLAGS_DEBUG -= -MDd
QMAKE_CFLAGS_DEBUG = -MTd
QMAKE_CXXFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE += -MT
QMAKE_CXXFLAGS_DEBUG -= -MDd
QMAKE_CXXFLAGS_DEBUG += -MTd
INCLUDEPATH += (RELATIVE_PATH_WHERE_DCMTK_WAS_INSTALLED)/include
#an example: INCLUDEPATH += ../../../test_dcmtk/DCMTK/include
LIBS += -L"(RELATIVE_PATH_WHERE_YOU_INSTALLED_DCMTK)/lib" \
-ladvapi32 \
-ldcmdata \
-loflog \
-lofstd \
-lws2_32 \
-lnetapi32 \
-lwsock32
#an example: LIBS += -L"../../../test_dcmtk/DCMTK/lib" \
4.A) Windows with Visual Studio 2012 IDE
Open the project file at VisualStudio and click on Build.
4.B) Windows with QtCreator IDE using the VisuaStudio as Compiler
Open the project file at QT and click on Build.
4.C) GNU/Linux - Command Line with GCC
g++ testapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main
Please, note that whether you have compiled the libraries in DEBUG mode, your application should be compiled in DEBUG mode as well.
References
How Install
http://support.dcmtk.org/docs/file_install.html
DCMTK Docs
http://support.dcmtk.org/docs/
FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC]
http://forum.dcmtk.org/viewtopic.php?f=4&t=652
CMake Configuration
http://support.dcmtk.org/wiki/dcmtk/howto/cmakeconfiguration360
Try to follow the instructions for the Dcmtk installation. If you don't know how to include the library in your project, study the qmake manual.
The Common Toolkit guys have addressed some of these issues. You could also use the Insight Toolkit
http://www.commontk.org/index.php/Main_Page
http://itk.org
In fact there is a bit of documentation on the ITK wiki, but ITK uses gdcm instead of dcmtk.
http://www.itk.org/Wiki/ITK_FAQ#How_to_read_a_volume_from_a_DICOM_series
We have a project that is an implementation of DCMTk in Qt -- we call it QtDICOM, and it forms the foundation of many of our products (http://fluxinc.ca/medical)/. Worth a look (https://bitbucket.org/fluxinc/qt-dicom). We haven't documented the configuration particularly well, but you can probably figure it out if you have a look.
Note: It does depend on DCMTk being built and included in the various paths.

Resources