link error- Qt Creator OpenCV Ubuntu - c++

I am currently having a link error with Qt.
I cant compile my code since i got the error message:
error: undefined reference to `cv::imread(cv::String const&, int)'
Heres the content of my .pro
QT += core
QT -= gui
TARGET = edge_detection
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
INCLUDEPATH += /usr/local/include/opencv2
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
Heres my simple code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main(){
cv::Mat img;
img=cv::imread("/home/cgross/Downloads/2.jpg");
return 0;
}
I am not sure of where is the problem

includepath must show opencv and opencv2.just like that:
INCLUDEPATH += C:\\opencv-2.4.6.1\\build-msvc2012\\install\\include
LIBS+=-LC:\\opencv-2.4.6.1\\build-msvc2012\\install\\lib \
-lopencv_calib3d246d \
-lopencv_contrib246d \
-lopencv_core246d \
-lopencv_features2d246d \
-lopencv_flann246d \
lıbs must show .lib file

Your code builds and runs just fine for me on a somewhat antique stock ubuntu 12.10 with opencv 2.3 from the distribution packages.
It picks up a cv::imread(std::string const &, int) from libopencv_highgui.

Related

Library Version Mismatch (C++ HDF5 Windows)

When trying to run a simple program using the hdf5-file format i get these messages and the program crashes:
I found posts to other problems like this, but most of them refer to linux and python. I use C++ (Qt Creator) and Windows (Windows 7 64bit) with the MSVC17 64bit Compiler, so these solutions dont work for me.
I don't understand why this occurs, because i simply donwloaded the HDF5 version 1.10.2 and installed it, i don't know why it says something about the version 1.8.15. Where could this come from?
I guess "library version" (1.8.15) is the version of my hdf5.lib file, right?
What does "header version" (1.10.2) mean? I simply #include <hdf5.h> and #include <H5Cpp.h> in the main.cpp and added paths in the hdf5_test_2.pro (my project) file.
Here is my code:
hdf5_test.pro:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
win32: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5 -lhdf5_cpp -lhdf5_hl_cpp
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/libhdf5.lib'
else:win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/liblibhdf5.a'
main.cpp:
#include <iostream>
#include <hdf5.h>
#include <H5Cpp.h>
using namespace std;
using namespace H5;
int main()
{
hid_t file_id;
herr_t status;
file_id = H5Fcreate("file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
status = H5Fclose(file_id);
cout << "Hello World!" << endl;
return 0;
}
The code example i tried to use comes from High Level Introduction to HDF5 (Pages 16/17).
Solved (meaning next error)
I think i solved the problem: There was another Version of HDF5 installed (1.8.15) on the system (the one who used this PC before me installed it).
I told my programm to link my lib (1.10.2) and passed the path, but somehow he found the 1.8.15 version previously installed. I now told my program to link the old version and it worked.
My hdf5_test_2.pro (my project) looks now like this:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
win32: LIBS += -LC:/Anaconda2/Library/lib/ -lhdf5 -lhdf5_cpp
INCLUDEPATH += C:/Anaconda2/Library/include
DEPENDPATH += C:/Anaconda2/Library/include
Nice so far, but i get these two warnings now:
Any ideas, what that means?

undefined reference in Qt creator for DCMTK libraries

I'm trying to run a simple application in Qt creator using DCMTK libraries and it doesn't work as it should. I receive the following message:
error: undefined reference to `DicomImage::DicomImage(char const*, unsigned long, unsigned long, unsigned long)'
main.cpp:
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmimgle/dcmimage.h"
#include "iostream"
int main(int argc, char *argv[])
{
DicomImage *image = new DicomImage("test.dcm");
if (image != NULL){
std::cout << "hell yeah!";
}
return 0;
}
.pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2016-02-18T19:16:51
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
#------------------
CONFIG += c++11
INCLUDEPATH += "C:\Program Files (x86)\DCMTK_1\include"
LIBS += -L"C:\Program Files (x86)\DCMTK_1\lib"
LIBS +=-ldcmimgle -ldcmdata -loflog -lofstd
win32:LIBS += -lAdvapi32 -lofstd -loflog -ldcmdata -ldcmnet -ldcmimage -ldcmimgle -lws2_32 -lnetapi32 -lwsock32
I think something is wrong with .pro file but I cannot figure out. I have included the necessary libraries and still no use.. I read that for DCMTK the order of libraries is important but I think it is already in order and cannot figure out what could be. Can you provide a solution to this problem?

Qt project set to version 5 but qtcreator still looking for qt4 header files?

Here is a screenshot from the project view:
Here is the .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2014-05-18T15:34:14
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = bedcoll
CONFIG += console
CONFIG -= app_bundle
QMAKE_CC = clang
QMAKE_CXX = clang++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -D_FILE_OFFSET_BITS=64
INCLUDEPATH += /usr/include/c++/4.8
INCLUDEPATH += /usr/include/boost
LIBS += -lboost_system
LIBS += -lboost_filesystem
LIBS += -lboost_program_options
TEMPLATE = app
SOURCES += \
src/util.cpp \
src/bedcoll.cpp \
src/main.cpp
HEADERS += \
src/collgen_memo.h \
src/util.h \
src/bedcoll.h \
src/error_enum.h
This project builds without any problem in a kubuntu 13.10, but after upgrading to 14.04, it gives the following error:
/usr/include/qt4/QtCore/qstring.h:1045: error: undefined reference to `QString::toAscii() const'
/usr/include/qt4/QtCore/qstring.h:880: error: undefined reference to `QString::free(QString::Data*)'
/usr/include/qt4/QtCore/qstring.h:879: error: undefined reference to `QString::shared_null'
Kubuntu 14.04 ships qt5 as default, but qtcreator is still looking for qt4, very confusing.
#Netjat is right, cleaning up solves the problem, in fact there is a shortcut, just right click on the project and choose "rebuild".

OpenCV with Qt: The program has unexpectedly finished

I am trying to configure OpenCV with Qt Creator 2.7.0 (Qt 5.0.2) on windows 8 64bit.
While executing my program, I get the following error:
The program has unexpectedly finished.
This is my main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
IplImage *image = cvLoadImage("E:\\lena.jpg"); //If this is removed, the program runs OK
return a.exec();
}
My .pro file is
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
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
win32 {
message("* Using settings for Windows.")
INCLUDEPATH += "C:\\OpenCV\\opencv\\build\\include" \
"C:\\OpenCV\\opencv\\build\\include\\opencv" \
"C:\\OpenCV\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\OpenCV\\opencv\\build\\x64\\mingw\\lib" \
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
}
Environment Variables are:
OPENCV_DIR:C:\OpenCV\opencv\build\x64\mingw Path:
G:\5.0.2\Tools\MinGW\bin;G:\Qt\5.0.2\mingw47_32\bin
What could be the problem ?
I suggest you use the OpenCV 2.x API if possible. The error handling is better.
This would be cv::Mat image = cv::imread("E:\lena.jpg");
If the image is empty, it means you have the wrong path.
Also, make sure the opencv dll are in the path of your executable (core, highgui and imgproc).
You might need to change
-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244
to
-lopencv_core244d \
-lopencv_highgui244d \
-lopencv_imgproc244d
note 'd' at the end of each lib (if you are to build in debug)
Have you solved the problem?
Have you tried adding system("PAUSE"); after the return a.exec(); ?
Just some extra notes:
Also try
try
{
...
}
catch (Exception e)
{
...
}
to see if you can find the error
thirdly, check the file permissions for lena.jpg
Lastly, see if you can use the path E:\lena.jpg

Cannot open camera with OpenCV in Linux

I am using OpenCV 2.4.3 on linux now. And in my /dev/ there is a device called video0 that is working fine with cheese.
Currently I am using the following code to try to access the camera. This code is written in qtcreator and compiled with qmake to include the necessary library. As for the OpenCV library, I downloaded the source code and compiled it according to the instruction on the website on my machine.
++main.cpp:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <cstdlib>
int main(int argc, char** argv) {
int cameraNumber = 0;
if (argc>1)
cameraNumber = atoi(argv[1]);
cv::VideoCapture camera;
camera.open(cameraNumber);
if(!camera.isOpened()) {
std::cerr<<"Error opening camera"<<std::endl;
exit(1);
}
camera.set(CV_CAP_PROP_FRAME_WIDTH,640);
camera.set(CV_CAP_PROP_FRAME_HEIGHT,480);
while(true) {
cv::Mat cameraFrame;
camera>>cameraFrame;
if (cameraFrame.empty()){
std::cerr<<"No frame read from camera"<<std::endl;
exit(1);
}
imshow("Camera",cameraFrame);
char keypress = cv::waitKey(20);
if (keypress==27) {
break;
}
}
return 0;
}
++test.pro
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/release/ -lopencv_core
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/debug/ -lopencv_core
else:unix: LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/ -lopencv_core
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/release/ -lopencv_highgui
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/debug/ -lopencv_highgui
else:unix: LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/ -lopencv_highgui
INCLUDEPATH += $$PWD/../../../../opt/OpenCV-2.4.3/include
DEPENDPATH += $$PWD/../../../../opt/OpenCV-2.4.3/include
However, when running the program it will output Error opening camera and exit, which means the camera is not opened successfully. I have been googled a while and didn't find any possible solutions to solve this issue. Could some one give me some advice on how to solve this problem? Thanks!
Perhaps you are missing some addition libraries that are required for linux.
According to OpenCV install guide, Extra Prerequisites, when using OpenCV on linux, you need to install these libraries: ffmpeg, libgstreamer, libv4l, libxine, unicap, libdc1394 2.x.
On Ubuntu 12.04 , installing the following packages worked for me (*sudo apt-get install __*):
python-opencv
libhighgui2.3
libhighgui-dev
ffmpeg
libgstreamer0.10-0
libv4l-0
libv4l-dev
libxine2
libunicap2
libdc1394-22
Good Luck!