QT + OpenCV undefiend reference to cv::stereoBM::create(int,int) - qt

I need your help for a problem in OpenCV cv::StereoBM because I got an error when I tried bo compile the code below:
std::string myImgLeftString = myImgLeft.toUtf8().constData();
std::string myImgRightString = myImgRight.toUtf8().constData();
cv::Mat img1 = cv::imread(myImgLeftString,CV_LOAD_IMAGE_COLOR);
cv::Mat img2 = cv::imread(myImgRightString,CV_LOAD_IMAGE_COLOR);
cv::Mat img3;
cv::Mat img1grey, img2grey;
cv::cvtColor(img1,img1grey,CV_BGR2GRAY);
cv::cvtColor(img2,img2grey,CV_BGR2GRAY);
cv::Ptr<cv::StereoBM> match = cv::StereoBM::create(0,21);
match->compute(img1grey,img2grey,img3);
It gives me : undefiend reference to cv::StereoBM::create(int,int)
But I already include all the headers necessary and not necessary
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/imgproc.hpp>
#include <stdio.h>
#include <iostream>
#include <opencv2/core/affine.hpp>
#include "opencv2/core/hal/intrin.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/ximgproc.hpp"
And I've added two lignes of code in my .pro file
LIBS += -L ./opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs
INCLUDEPATH += -I /opt/local/stow/opencv-3.4.3
I don't know what is wrong, please kindly help, thanks.

cv::StereoBM is in calib3d module of OpenCV, so you need to link to the lib file of that module, to do that add -lopencv_calib3d to the LIBS in your .pro file:
LIBS += -L ./opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_calib3d
Don't forget to run qmake after you modify your .pro file.

Related

Qt and OpenCv CrossCompile for Raspberry Pi Error

I'm trying to use opencv in a QT project for a raspberry pi 4. I'm on a Linux machine
Here is my .pro file and errors I get. And my mainwindow.cpp
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
TRANSLATIONS += \
SCWWS_fr_FR.ts
CONFIG += lrelease
CONFIG += embed_translations
# Default rules for deployment.
qnx: target.pHere is my mainwindow.cppath = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
resources.qrc
unix:!macx: LIBS += -L$$PWD/../../Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_shape -lopencv_videoio
INCLUDEPATH += $$PWD/../../Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/include
DEPENDPATH += $$PWD/../../Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/include
Here is my mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore>
#include <QFontDatabase>
#include <QDebug>
#include <QImage>
//#include "opencv2/core.hpp"
//#include "opencv2/highgui.hpp"
//using namespace cv;
mainwindow::mainwindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::mainwindow)
{
QFontDatabase::addApplicationFont(":/fonts/roboto-light.ttf");
ui->setupUi(this);
qDebug() << "Hello World !";
//cv::VideoCapture camera = VideoCapture(0);
//
//Mat frame;
//camera >> frame;
//QImage img(frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
//ui->label->setPixmap(QPixmap::fromImage(img));
}
mainwindow::~mainwindow()
{
delete ui;
}
And here are errors I get
libXinerama.so.1, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libgdk-3.so.0, not found (try using -rpath or -rpath-link)
libmmal_core.so, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libavcodec.so.58, not found (try using -rpath or -rpath-link)
libmmal_vc_client.so, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libavcodec.so.58, not found (try using -rpath or -rpath-link)
.
.
.
liblapack.so.3, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/lib/libarmadillo.so.9, not found (try using -rpath or -rpath-link)
/home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libopenmpt.so.0:-1: error: undefined reference to `std::random_device::_M_getentropy() const#GLIBCXX_3.4.25'
Errors arrives has soon has I uncomment my code. The version of open cv on the RP4 is 3.2 and when I install it on my machine it's 4.5. Event if I use the same command sudo apt-get install libopencv-dev
Thanks for your help
**EDIT**
I was able to get rid of these errors with this response. But a new one appeared
undefined reference to std::random_device::_M_getentropy() const#GLIBCXX_3.4.25
Regarding OpenCV I suggest to build it from source, for the RPi I always cross-compile using docker, as described here (just remove the references to openvino).
At this point you also need to cross-compile Qt for the RPi, but I guess you already did it.

Ploting an image with 'imshow' of opencv in webots

hi I am using opencv in webots and I want to plot an image . This is the controller:
#include <webots/Robot.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace webots;
using namespace cv;
int main(int argc, char **argv){
Robot *robot = new Robot();
int timeStep = (int) robot->getBasicTimeStep();
while (robot->step(timeStep) != -1) {
Mat a1 = imread("/home/alireza/Desktop/1.jpg");
cv::imshow("test",a1);
};
delete robot;
return 0;
}
and this is the makefile:
OPENCV = `pkg-config opencv --cflags --libs`
LIBRARIES = $(OPENCV)
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
RESOURCES_PATH = $(WEBOTS_HOME)/projects/robots/robotis
CXX_SOURCES = $(wildcard *.cpp)
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
I make it successfully but when I want to run it I face a runtime error about Qt :
[co] qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
[co] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
I really need help.

Using DLL's in Qt: undefined reference

I want to use an SDK I got for using a scanner. I'm using Qt 5.3 with MingW32 (on Windows 7).
The very first test I wanted to build should just print the SDK version.
Here is my project file
QT += core
QT -= gui
TARGET = Kojak1
CONFIG += console
CONFIG -= app_bundle
KOJAKDIR = "C:/Program Files/Integrated Biometrics/IBScanUltimateSDK_x64"
TEMPLATE = app
INCLUDEPATH += $$KOJAKDIR/Include
SOURCES += main.cpp
LIBS +=-L$$KOJAKDIR/lib/ -lIBScanUltimate
and here is the source code
#include <QCoreApplication>
#include "stdio.h"
#include <windows.h>
#include "IBScanUltimateApi.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
IBSU_SdkVersion sdk_version;
IBSU_GetSDKVersion(&sdk_version);
printf("%s %s",sdk_version.File,sdk_version.Product);
return a.exec();
}
Unforturnately I get the message
D:\devt\QTProjects\Kojak1\main.cpp:10: error: undefined reference to `IBSU_GetSDKVersion#4'
when trying to compile the program.
My lib directory does contain IBScanUltimate.lib and IBScanUltimate.dll.

Boost in Qt: Installation and Symbol(s) not found for architectures x86_64

I am back to Qt and C++ programming after a year break. I am trying to install boost library into Qt on Mac (10.9.4) and I am completely confused. This is what I did:
I installed boost using homebrew.
I see that hpp files are installed here:
/usr/local/Cellar/boost/1.55.0_2/include/boost
and libraries here:
/usr/local/Cellar/boost/1.55.0_2/lib
Now I start a new Qt console project.
the project file:
QT += core
QT -= gui
TARGET = testQt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/Cellar/boost/1.55.0_2
And the main file:
#include <QCoreApplication>
#include <QtCore>
#include <iostream>
#include <QDebug>
#include <boost/regex.hpp>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
return a.exec();
}
Not compiling. Issues:
Symbol(s) not found for architectures x86_64
linker command failed with exist code 1
Since I am absolutely noob with boost, did I do it right? If yes, why is it not compiling?
Thanks a lot!
You need to link with boost too!
LIBS += -L/usr/local/Cellar/boost/1.55.0_2/lib -lboost

error: 'qmlRegisterType' was not declared in this scope

Working with Qt 5 and QtQuick 2.0
.pro
# Add more folders to ship with the application, here
folder_01.source = qml/untitled
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
#CONFIG += qt plugin
#QT += qml quick
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
../DummyClass.cpp \
../aa.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
HEADERS += \
../DummyClass.h \
../aa.h
main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "/home/***/qmllistproperties/DummyClass.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
const char* ocuui = "OCUUI"; // #uri OCUUI
qmlRegisterType <DummyClass> (ocuui, 1, 0, "DummyClass");
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/untitled/main.qml"));
viewer.showExpanded();
return app.exec();
}
qmlRegisterType is in QtQml. You have to include QtQml:
#include <QtQml>

Resources