I'd like to start using OpenCV for C++ on Windows after a bunch of OpenCV4Android work. From this forum post, it seems that not all C++ IDEs have equivalent capabilities to display OpenCV images, since some do not have an integrated GUI plugin. Are there any differences between IDEs in terms of OpenCV functionality that I should be aware of?
Go with Qt Creator. It's a cross-platform IDE for C/C++ development that supports the Qt framework. When you move to Linux/Mac you can continue to use Qt Creator to develop your projects.
It's an IDE that you'll spent a day or two to master, and it will be useful for the rest of your career.
Qt Creator uses a .pro file to configure the project. The instructions on this file are used to build all the Makefiles needed to build the .exe.
This is the .pro file I use to build my Qt Creator projects on Windows/Mac/Linux:
TEMPLATE = app
SOURCES += \
main.cpp \
cvImage.cpp
HEADERS += \
cvImage.h
## 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
}
Related
I am trying to use google protobuf 2.6 in QT 5.7 (clang 7.0) with QT creator 4.0.3 on OSX without much luck.
The .pro file has
LIBS += `pkg-config --cflags -- libs protobuf`
to include the protobuf library.
In the header file I generated using my proto file contains the line
#include <google/protobuf/stubs/common.h>
this produces a compiler error of
error: 'google/protobuf/stubs/common.h' file not found
The protobuf package is found by QT with the LIBS += command in the pro file and I have the unfound header files in
/Users/<username>/Qt/5.7/Src/qtwebengine/src/3rdparty/chromium/third_party/protobuf/src/google/protobuf/stubs
and
/usr/local/include/google/protobuf/stubs/common.h
I installed protobuf using macports.
The header file autocompletes so QT knows where it is so I am not sure how to deal with the file not found error.
Any help much appreciated.
Thanks,
a.
edit:
I think the problem is /usr/local/ not being included is qt path, thus I can find the protobuf package but not any of the header files (even though it autocompletes?). How do I add to PATH in QT with el capitain?
edit 2:
Project file
#-------------------------------------------------
#
# Project created by QtCreator 2016-07-13T12:13:47
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testexample
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
../../../protobuf/message.pb.cc
QT_CONFIG -= no-pkg-config
HEADERS += mainwindow.h \
../../../protobuf/message.pb.h
FORMS += mainwindow.ui
RESOURCES += \
resources.qrc
LIBS += `pkg-config --cflags -- libs protobuf`
Using Protobuf 2.4 with Qt 5.7 in Windows/Linux/Mac. Download and compile Protobuf 2.4 with the compiler you are using, (Im using MSVC/MinGW on Windows, gcc in Linux, clan on Mac OS). And edit your .pro file. My .pro configuration using this steps:
Load the compiled library for debug/release mode:
#For Windows
win32 {
CONFIG(debug, release|debug) {
win32:LIBS += -llibprotobuf-debug
} else {
win32:LIBS += -llibprotobuf
}
}
#For linux
!win32:LIBS += -lprotobuf
Include the path with all protobuf source code:
win32:INCLUDEPATH += "..\\...\\directoty_protobuf\\src"
Its working fine for me.
I am working on a desktop application with the Qt and OpenCV on my mac. I have installed both qmake on version 5.3.2(currently used) and 4.6.8 , OpenCV 2.4.9 , I use the GCC compiler, my Qt version is 5.3.2, Qt creator version is 3.2.2.
Previously I have a Qt project previously run on a Ubuntu, now it migrates to the mac, the only change is just on the .pro, in which the INCLUDEPATH and LIB path must change to the include and lib path of OpenCV in the mac.
Here is my configuration.
INCLUDEPATH += /usr/local/Cellar/opencv/2.4.9/include
LIBS += -L/usr/local/Cellar/opencv/2.4.9/lib \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_video \
-lopencv_objdetect \
-lopencv_ml \
-lopencv_features2d
/usr/local/Cellar/opencv/2.4.9/include and /usr/local/Cellar/opencv/2.4.9/lib are the exact location for the opencv. There should be no reason to have this error, since the opencv libraries are all there and should be linked in the right format.
right now I could not figure out how and why
When I include something in Qt Creator, later I find out that that include does not exist, I want to correct that mistake by using a right path, or just deleting the include. But, that did not work, even if I delete the wrong include, but Qt Creator still try to find that include in the next build/run. I have already try to rebuild/clean the project but that does not work either. The only solution was to create a new project, or place the included file in that "wrong" place. I thought this question should not be a difficult one. But I fail to solve it.
for example, this is my pro. file.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = simpleStitch
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv249\build\includes
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_core249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_highgui249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_features2d249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_imgproc249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_calib3d249.lib
LIBS += C:\opencv249\build\x64\vc12\lib\opencv_nonfree249.lib
I have make a mistake in the LIBS += C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib.
the right one should be stitching249.lib.
after I correct it to be stitching249.lib. the qt still try to find the C:\opencv249\build\x64\vc12\lib\opencv_stitcher249.lib. it is pretty strange. qt does not recognize my change in the pro. file even if I use the clean/ rebuild.
Run qmake? if you make changes to the .pro file then you need to qmake again or it will just be building against whatever is there from your last qmake
Please give more information, so that we can understand specific problem. Here is what you need to do before starting a new project.
To add kits, select Tools > Options > Build & Run > Kits > Add.
Each kit consists of a set of values that define one environment, such as a device, compiler, and Qt version. If you know you have installed a Qt version, but it is not listed in Tools > Options > Build & Run > Qt Versions, you must add it.
Also check that your compiler is listed in Tools > Options > Build & Run > Compilers.
And also you should modify your .pro file in order to your settings. Here is one of my project's .pro file. You can modified it yourself...
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = myTarget
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib \
-lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_ml \
-lopencv_video \
-lopencv_features2d \
-lopencv_calib3d \
-lopencv_objdetect \
-lopencv_contrib \
-lopencv_legacy \
-lopencv_flann
Then, in your code you need to include which libraries you want to use.. Such as:
#include <QMainWindow>
#include <opencv/cv.h>
#include <opencv/highgui.h>
I have never used Windows. As I know in windows symbol \ occurs problem if you not use 2 of them. Here is an example to understand clearly..
INCLUDEPATH += D:\\ProgrammingTools\\opencv\\build\\include
CONFIG( debug, debug|release ) {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246d\
-lopencv_highgui246d\
-lopencv_imgproc246d\
-lopencv_features2d246d\
}
else {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246\
-lopencv_highgui246\
-lopencv_imgproc246\
-lopencv_features2d246\
}
I'm trying to follow this exemple but I'm stuck where the documentation don't show how to actually create the toolbar they're showing ...
(I'm working on Visual Studio 2013 with OpenCV 2.4.9 on a 64bit based aplication)
Am I missing something ?
EDIT : Here's a picture of the Toolbar(left), next to a Trackbar.
Please, if there is still confusion, tell me before downvoting so I can explain more.
You can't create a toolbar. The toolbar is created automatically by the OpenCV highgui module in every "NamedWindow" if OpenCV is compiled with Qt support. If you can't see this toolbars you should re-build OpenCV with Qt support. To do so, build OpenCV from source (by using CMAKE) and make sure the option WITH_QT is set.
If you build OpenCV with CMAKE GUI you can find this option in the configuration menu:
One thing you should have in mind is that OpenCV won't allow you to modify the toolbars as it does with the TrackBar or the NamedWindow.
I had the same problem and now solved it after 2 days :D
I'm using OSX 10.9 with opencv 2.4.9 installed with brew and Qt Creator.
The Problem is the installation in brew. To see the toolbar you have to install -- with qt.
write in terminal (with brew) to install opencv (uninstall if opencv is already installed)
brew install opencv --with-qt
Now you can use the toolbar in Xcode or
in QT Creator, create for instants QT widget App and add in the *.pro file:
QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
LIBS += -L/usr/local/lib
LIBS += \
-lopencv_calib3d \
-lopencv_contrib \
-lopencv_core \
-lopencv_flann \
-lopencv_gpu \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_legacy \
-lopencv_ml \
-lopencv_objdetect \
-lopencv_ocl \
-lopencv_photo \
-lopencv_stitching \
-lopencv_superres \
-lopencv_ts \
-lopencv_video \
-lopencv_videostab
-lopencv_nonfree
INCLUDEPATH += /usr/local/include/opencv \
/usr/include/opencv \
/usr/local/include
DEPENDPATH += /usr/local/include/opencv/include
My program won't start, complaining that libgcc_s_sjlj-1.dll is needed. However, this file doesn't exist in Qt directory. I did some search and found that -static-libgcc and -static-libstdc++ should be added. So here is my .pro file:
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = mouseEventProcess
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
fileOp.cpp \
xmlpraser.cpp \
pixmapOp.cpp \
mathOp.cpp
HEADERS += mainwindow.h \
fileOp.h \
xmlpraser.h \
pixmapOp.h \
mathOp.h
FORMS += mainwindow.ui
#COMPILE LIBGCC_S_SJLJ-1.DLL AND LIBSTDC++-6.DLL INTO THE EXE FILE
win32{
QMAKE_LFLAGS += -static-libgcc
QMAKE_LFLAGS += -static-libstdc++
#BOOST LIBRARIES. CHANGE TO YOUR OWN.
INCLUDEPATH += D:/boost_1_51_0
#OPENCV LIBRARIES. CHANGE TO YOUR OWN.
INCLUDEPATH += D:/opencv2.4.4/include
INCLUDEPATH += D:/opencv2.4.4/release/install/include
LIBS += -LD:/opencv2.4.4/release/install/lib \
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
#-lopencv_features2d244 \
#-lopencv_calib3d244
}
unix{
#BOOST LIBRARIES. CHANGE TO YOUR OWN.
INCLUDEPATH += /home/panda/boost_1_51_0
#OPENCV LIBRARIES.IF YOU COMPILED AND INSALLED
#OPENCV FROM CMAKE & MINGW, JUST LEAVE IT BE,
#UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING.
INCLUDEPATH += /usr/local/include/opencv
INCLUDEPATH += /usr/local/include/opencv2
LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui
LIBS += -lopencv_ml -lopencv_video -lopencv_features2d
LIBS += -lopencv_calib3d -lopencv_objdetect -lopencv_contrib
LIBS += -lopencv_legacy -lopencv_flann
}
If this works, neither libgcc_s_sjlj-1.dll and libstdc++-6.dll is needed. However, the program still needs libstdc++-6.dll before I put it into .exe folder.
So my question is: Where can I get libgcc_s_sjlj-1.dll or is there any problem in my .pro file?
Bah, I am stupid. Your 'my program lacks libgcc_s_sjlj-1.dll, not libgcc_s_dw2-1.dll' should have rung a bell.
You compile with the wrong MinGW. There are several different exception handler for MinGW available: sjlj, dwarf, seh. Dwarf is 32bin only. When you have the libgcc_s_dw2-1.dll it means, you have a 32bit only MinGW installed.
You must compile your programs with the same MinGW, which was used to compile your Qt. The sjlj MinGW works for 32bit and 64bit so I suppose it makes sense that the qt-project provides binary packages, which were compiled with sjlj-MinGW.
There are some MinGW packages available, which allow you to choose, which exception handling mechanism you will use. Best choice is probably to use the MinGW, which is bundled in the Qt 5.1.1 installer packages.