Git Product home page Git Product logo

computer-vision-with-opencv-3-and-qt5's Introduction

Computer Vision with OpenCV 3 and Qt5

This is the code repository for Computer Vision with OpenCV 3 and Qt5, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish.

About the Book

Developers have been using OpenCV library to develop computer vision applications for a long time. However, they now need a more effective tool to get the job done and in a much better and modern way. Qt is one of the major frameworks available for this task at the moment.

Instructions and Navigation

All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02.

Chapter 11 has no code file, rest all chapter code files are present in their respective folder.

The code will look like the following:

#include "mainwindow.h"
#include
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  MainWindow w;
  w.show();
  return a.exec();
}

Although every required tool and software, the correct version, and how it is installed and configured is covered in the initial chapters of the book, the following is a list that can be used as a quick reference:

  • A regular computer with a more recent version of Windows, macOS, or Linux (such as Ubuntu) operating system installed on it.
  • Microsoft Visual Studio (on Windows)
  • Xcode (on macOS)
  • CMake
  • Qt Framework
  • OpenCV Framework To get an idea of what a regular computer is these days, you can search online or ask a local shop; however, the one you already have is most probably enough to get you started.

Related Products

Suggestions and Feedback

Click here if you have any feedback or suggestions.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to download a free PDF copy of this book.

https://packt.link/free-ebook/9781788472395

computer-vision-with-opencv-3-and-qt5's People

Contributors

amahta avatar packt-itservice avatar packtutkarshr avatar sonam-packt avatar supriyathabe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

computer-vision-with-opencv-3-and-qt5's Issues

Chapter 5: mouseMoveEvent function is missing

In qenhancedgraphicsview.h (and of course also in qenhancedgraphicsview.cpp) you should have functions wheelEvent, mouseMoveEvent and mousePressEvent. The mouseMoveEvent function is missing.

ch7:Plugin Error Message : "Select a secondary image first!"

I tried to put an image on the keypoint_plugin, but adding an image will prompt me:

Plugin Error Message : "Select a secondary image first!"

cpp:void Keypoint_Plugin::processImage(const cv::Mat &inputImage, cv::Mat &outputImage)
{
if(secondImage.empty())
{
emit errorMessage("Select a secondary image first!");
return;
}
I'm not quite sure what secondImage is

None of samples compile on Mac

I tried to compile samples but none of them work on my MacOS, e.g. regarding ch2 Hello_Qt_OpenCV I get like 20 Qt related errors. First error I think is related to Q_OBJECT macro (unknown type name 'QT_WARNING_PUSH') and then cascade of other Qt errors. It might be something related to mainwindow.ui or QMainWindow but I have no clue.

I tested my Qt 5.11 and Qt 5.12rc2 environment and both work with official samples. My OpenCV 3.4.3 setup also works (tested both C++ using Xcode and python bindings).
I'm using
MacOS 10.13.6 High Sierra
Xcode 10.1
Qt 5.11 and Qt 5.12rc2

ch5 : error: C2039: “borderTypeComboBox”: is not “Ui::PluginGui” member

hello,

void CopyMakeBorder_Plugin::setupUi(QWidget *parent)
{
    ui = new Ui::PluginGui;
    ui->setupUi(parent);
    QStringList items;
    items.append("BORDER_CONSTANT");
    items.append("BORDER_REPLICATE");
    items.append("BORDER_REFLECT");
    items.append("BORDER_WRAP");
    items.append("BORDER_REFLECT_101");
    ui->borderTypeComboBox->addItems(items);
    connect(ui->borderTypeComboBox,
            SIGNAL(currentIndexChanged(int)),
            this,
            SLOT(on_borderTypeComboBox_currentIndexChanged(int)));
}

微信截图_20220825203117

微信截图_20220825203238

I am a freshman on qt programming. Could you tell me how to address this problem?

error in ch6 and ch7 #include "cvplugininterface.h"

when i build color _plugin.pro project in ch6, I got this error: cvplugininterface.h" No such file or directory.

furthermore, how can I load the whole ch.6 as explained in the reference, because it has been separated into many projects.

thanks in advance

Run ch7 keypoint_plugin for keypoint detection

Hello, I am reading chapter 7 of your new book on opencv3-qt5. For experimenting with the presented keypoint detection algorithms, I put the keypoint_plug in the context computer_vision project developed the previous chapters.

I have got a plugin error message: "Select a secondary image first!" (for the generated Computer Vision GUI, I loaded the image as shown in the book). Switching any algorithm available gives the message. I feel only image should be fine with keypoint detection rather than matching.

If I perform the matching operation, the interface is easily to be crashed for some reason.

Working environment: OpenCV3.4 + Qt5.8

Thanks

Run the code Hello_Qt_Opencv

i tried to build and run the code it build and run but the actual output was not display i din get where the problem is i have tried all the possible way but can't find the solution even i try the any example it is same it build and run but it won't show the output.
SOURCE CODE
MAININDOW.CPP
//*
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
loadSettings();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_pressed()
{
QString fileName =QFileDialog::getOpenFileName(this,
"Open Input Image"
,QDir::currentPath(),
"Image(
.Jpg .png .bmp)");
if (QFile::exists (fileName))
{
ui->lineEdit->setText(fileName);
}
}
void MainWindow::on_pushButton_2_pressed()
{
QString fileName =QFileDialog::getSaveFileName(this,"Select Output Image",
QDir::currentPath(),
"
.jpg;;
.png;;.bmp");
if (!fileName.isEmpty())
{
ui->lineEdit_2->setText(fileName);
using namespace cv;
Mat inpImg, outImg;
inpImg = imread (ui->lineEdit-> text().toStdString());
if (ui->radioButton->isChecked())
cv::medianBlur(inpImg,outImg,5);
else if (ui->radioButton_2->isChecked())
cv::GaussianBlur(inpImg,outImg,Size(5,5),1.25);
imwrite(fileName.toStdString(),outImg);
if (ui->checkBox ->isChecked())
imshow("Output Image",outImg);
}
}
void MainWindow::closeEvent(QCloseEvent event)
{ int result = QMessageBox::warning(this,"Exit",
"Are you sure you want to close this program?",
QMessageBox::Yes,
QMessageBox::No);
if(result == QMessageBox::Yes)
{
saveSettings();
event->accept();
}
else
{
event->ignore();
}
}
void MainWindow::loadSettings()
{
QSettings settings("Packt", "window",this);
ui->lineEdit->setText(settings.value("lineEdit","").toString());
ui->lineEdit_2->setText(settings.value("lineEdit_2","").toString());
ui->radioButton->setChecked(settings.value("radioButton",true).toBool());
ui->radioButton_2->setChecked(settings.value("radioButton_2",false).toBool());
ui->checkBox->setChecked(settings.value("checkBox",false).toBool());
}
void MainWindow::saveSettings()
{
QSettings settings("Packt","window",this);
settings.setValue("lineEdit",
ui->lineEdit->text());
settings.setValue("lineEdit_2",
ui->lineEdit_2->text());
settings.setValue("radioButton",
ui->radioButton->isChecked());
settings.setValue("radioButton_2",
ui->radioButton_2->isChecked());
settings.setValue("checkBox",
ui->checkBox->isChecked());
}
//

MAINWINDOW.H
//

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include
#include
#include
#include
#include
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs.hpp"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_pressed();
protected:
void closeEvent(QCloseEvent event);
void on_pushButton_2_pressed();
private:
Ui::MainWindow ui;
void loadSettings();
void saveSettings();
};
#endif // MAINWINDOW_H
//

MAIN.CPP
//

#include "mainwindow.h"
#include
int main(int argc, char argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
//

Chapter 5: byteCount is deprecated

In file qcustomgraphicseffect.cpp byteCount is deprecated in Qt 5.10. You should use sizeInBytes instead. Of course, your book was published about a month before Qt 5.10, but people probably have installed a newer version of Qt than what is used in the book.

Chapter 5: compute_vision.pro

Instead of compute_vision.pro, you should use computer_vision.pro. Unless there is some hidden meaning or reason I haven't figured out.

Running error with copymakeborder_plugin

I am following the instructions in the book page 226-233 to run the first example on copymakeboder_plugin. After building Computer_Vision project, there is no cvplugins folder generated in the build folder. My build results in three subfolders: copymakeborder_plugin, mainapp and temp_plugin.

I tried to copy the CopyMakeBorder_Plugin.lib (I assumed it was the library file needed) in the copymakeborder_plugin build folder, to the mainapp build folder, and then run the mainapp , but got the error message windows:

No Plugins This application cannot work without plugins! Make sure that/cvplugins/folder exists in the same folder as the application and that there are some filter plugins inside it.

Is this folder automatically generated after building?

I am using Qt5.8 with OpenCV3.4 in windows10.

Thanks in advance!

LNK2019:unresolved external symbol "void_cdcl cv:...." in run the ch2 Hello_Qt_OpenCV

I am running the example project Hello_Qt_OpenCV in ch02 in QtCreater4.5 with opencv3.2. The only change I made to the original Hello_Qt_OpenCV .pro file is the link to my opencv library. The configuration of opencv in Qt works fine with other qt projects.

Three issues are shown in building the project:
File not found: mainwindow.obj: LNK2019: unresolved external symbol "void __cdecl cv::medianBlur(class cv::_InputArray const &,class cv::_OutputArray const &,int)" (?medianBlur@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@H@Z) referenced in function "private: void __cdecl MainWindow::on_outputPushButton_pressed(void)" (?on_outputPushButton_pressed@MainWindow@@AEAAXXZ)

File not found: mainwindow.obj: LNK2019: unresolved external symbol "void __cdecl cv::GaussianBlur(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::Size_<int>,double,double,int)" (?GaussianBlur@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@V?$Size_@H@1@NNH@Z) referenced in function "private: void __cdecl MainWindow::on_outputPushButton_pressed(void)" (?on_outputPushButton_pressed@MainWindow@@AEAAXXZ)

LNK1120: 2 unresolved externals release\Hello_Qt_OpenCV.exe:-1: error

I tried clean, run qmake and build as suggested here: https://stackoverflow.com/questions/15864177/file-not-found-mainwindow-obj, but still cannot solve these issues.

ch8.error stray \342 in program

trying to build project from chapter 8 MultithreadedCV in QtCreator under Archlinux I got :

/usr/bin/uic ../MultithreadedCV/mainwindow.ui -o ui_mainwindow.h
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../MultithreadedCV -I. -isystem /usr/local/include/opencv -isystem /usr/local/include -isystem /usr/include/qt -isystem /usr/include/qt/QtWidgets -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -isystem /usr/include/libdrm -I. -I/usr/lib/qt/mkspecs/linux-g++ -o main.o ../MultithreadedCV/main.cpp
../MultithreadedCV/main.cpp:26:16: error: stray ‘\342’ in program
         return “”;
                ^
../MultithreadedCV/main.cpp:26:17: error: stray ‘\200’ in program
         return “”;
                 ^
../MultithreadedCV/main.cpp:26:18: error: stray ‘\234’ in program
         return “”;
                  ^
../MultithreadedCV/main.cpp:26:19: error: stray ‘\342’ in program
         return “”;
                   ^
../MultithreadedCV/main.cpp:26:20: error: stray ‘\200’ in program
         return “”;
                    ^
../MultithreadedCV/main.cpp:26:21: error: stray ‘\235’ in program
         return “”;
                     ^
../MultithreadedCV/main.cpp:32:31: error: stray ‘\342’ in program
                       QString(“\”).toStdWString().c_str(),
                               ^
../MultithreadedCV/main.cpp:32:32: error: stray ‘\200’ in program
                       QString(“\”).toStdWString().c_str(),
                                ^
../MultithreadedCV/main.cpp:32:33: error: stray ‘\234’ in program
                       QString(“\”).toStdWString().c_str(),
                                 ^
../MultithreadedCV/main.cpp:32:34: error: stray ‘\’ in program
                       QString(“\”).toStdWString().c_str(),
                                  ^
../MultithreadedCV/main.cpp:32:35: error: stray ‘\342’ in program
                       QString(“\”).toStdWString().c_str(),
                                   ^
../MultithreadedCV/main.cpp:32:36: error: stray ‘\200’ in program
                       QString(“\”).toStdWString().c_str(),
                                    ^
../MultithreadedCV/main.cpp:32:37: error: stray ‘\235’ in program
                       QString(“\”).toStdWString().c_str(),
                                     ^
../MultithreadedCV/main.cpp: In function ‘QString getVersionString(QString)’:
../MultithreadedCV/main.cpp:18:5: error: ‘DWORD’ was not declared in this scope
     DWORD dwHandle;
     ^~~~~
../MultithreadedCV/main.cpp:19:11: error: expected ‘;’ before ‘dwLen’
     DWORD dwLen = GetFileVersionInfoSize(fName.toStdWString().c_str(), &dwHandle);
           ^~~~~
../MultithreadedCV/main.cpp:21:5: error: ‘LPVOID’ was not declared in this scope
     LPVOID lpData = new BYTE[dwLen];
     ^~~~~~
../MultithreadedCV/main.cpp:22:58: error: ‘dwHandle’ was not declared in this scope
     if(!GetFileVersionInfo(fName.toStdWString().c_str(), dwHandle, dwLen, lpData))
                                                          ^~~~~~~~
../MultithreadedCV/main.cpp:22:58: note: suggested alternative: ‘drand48’
     if(!GetFileVersionInfo(fName.toStdWString().c_str(), dwHandle, dwLen, lpData))
                                                          ^~~~~~~~
                                                          drand48
../MultithreadedCV/main.cpp:22:68: error: ‘dwLen’ was not declared in this scope
     if(!GetFileVersionInfo(fName.toStdWString().c_str(), dwHandle, dwLen, lpData))
                                                                    ^~~~~
../MultithreadedCV/main.cpp:22:75: error: ‘lpData’ was not declared in this scope
     if(!GetFileVersionInfo(fName.toStdWString().c_str(), dwHandle, dwLen, lpData))
                                                                           ^~~~~~
../MultithreadedCV/main.cpp:22:75: note: suggested alternative: ‘QMapData’
     if(!GetFileVersionInfo(fName.toStdWString().c_str(), dwHandle, dwLen, lpData))
                                                                           ^~~~~~
                                                                           QMapData
../MultithreadedCV/main.cpp:22:9: error: ‘GetFileVersionInfo’ was not declared in this scope
     if(!GetFileVersionInfo(fName.toStdWString().c_str(), dwHandle, dwLen, lpData))
         ^~~~~~~~~~~~~~~~~~
../MultithreadedCV/main.cpp:25:18: error: type ‘<type error>’ argument given to ‘delete’, expected pointer
         delete[] lpData;
                  ^~~~~~
../MultithreadedCV/main.cpp:26:9: error: return-statement with no value, in function returning ‘QString’ [-fpermissive]
         return “”;
         ^~~~~~
../MultithreadedCV/main.cpp:29:5: error: ‘VS_FIXEDFILEINFO’ was not declared in this scope
     VS_FIXEDFILEINFO *lpBuffer = NULL;
     ^~~~~~~~~~~~~~~~
../MultithreadedCV/main.cpp:29:23: error: ‘lpBuffer’ was not declared in this scope
     VS_FIXEDFILEINFO *lpBuffer = NULL;
                       ^~~~~~~~
../MultithreadedCV/main.cpp:29:23: note: suggested alternative: ‘setbuffer’
     VS_FIXEDFILEINFO *lpBuffer = NULL;
                       ^~~~~~~~
                       setbuffer
../MultithreadedCV/main.cpp:30:5: error: ‘UINT’ was not declared in this scope
     UINT uLen;
     ^~~~
../MultithreadedCV/main.cpp:30:5: note: suggested alternative: ‘MIN’
     UINT uLen;
     ^~~~
     MIN
../MultithreadedCV/main.cpp:31:23: error: ‘lpData’ was not declared in this scope
     if(!VerQueryValue(lpData,
                       ^~~~~~
../MultithreadedCV/main.cpp:31:23: note: suggested alternative: ‘QMapData’
     if(!VerQueryValue(lpData,
                       ^~~~~~
                       QMapData
../MultithreadedCV/main.cpp:33:31: error: expected primary-expression before ‘)’ token
                       (LPVOID*)&lpBuffer,
                               ^
../MultithreadedCV/main.cpp:34:24: error: ‘uLen’ was not declared in this scope
                       &uLen))
                        ^~~~
../MultithreadedCV/main.cpp:34:24: note: suggested alternative: ‘QPen’
                       &uL``en))
                        ^~~~
                        QPen
../MultithreadedCV/main.cpp:31:9: error: ‘VerQueryValue’ was not declared in this scope
     if(!VerQueryValue(lpData,
         ^~~~~~~~~~~~~
../MultithreadedCV/main.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make: *** [Makefile:603: main.o] Error 1
16:51:15: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project MultithreadedCV (kit: Desktop)
When executing step "Make"
16:51:15: Elapsed time: 00:03.

Hi, I tried to compile the sample of ch02, got this error

Undefined symbols for architecture x86_64:
"cv::medianBlur(cv::_InputArray const&, cv::_OutputArray const&, int)", referenced from:
MainWindow::on_outputPushButton_pressed() in mainwindow.o
"cv::GaussianBlur(cv::_InputArray const&, cv::OutputArray const&, cv::Size, double, double, int)", referenced from:
MainWindow::on_outputPushButton_pressed() in mainwindow.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in mainwindow.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in main.o
cv::String::operator=(cv::String const&) in main.o
cv::String::~String() in mainwindow.o
cv::String::operator=(cv::String const&) in mainwindow.o
cv::String::~String() in moc_mainwindow.o
cv::String::operator=(cv::String const&) in moc_mainwindow.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) in mainwindow.o
cv::String::String(char const*) in mainwindow.o
"cv::imread(cv::String const&, int)", referenced from:
MainWindow::on_outputPushButton_pressed() in mainwindow.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
MainWindow::on_outputPushButton_pressed() in mainwindow.o
"cv::imwrite(cv::String const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator > const&)", referenced from:
MainWindow::on_outputPushButton_pressed() in mainwindow.o
"cv::fastFree(void*)", referenced from:
cv::Mat::operator=(cv::Mat&&) in mainwindow.o
cv::Mat::~Mat() in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Hello_Qt_OpenCV.app/Contents/MacOS/Hello_Qt_OpenCV] Error 1
17:36:19: 进程"/usr/bin/make"退出,退出代码 2 。
Error while building/deploying project Hello_Qt_OpenCV (kit: Desktop Qt 5.9.1 clang 64bit)
When executing step "Make"
17:36:19: Elapsed time: 00:07.

OS: Macbook pro 10.14
QT Creator: 5.9.1
Opencv version: 3.3.1

Chapter 6: transform_plugin.cpp: Invalid number of channels in input image

Error message:

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.3) /Users/tomihasa/Downloads/opencv-3.4.3/modules/imgproc/src/color.hpp:255: error: (-2:Unspecified error) in function 'cv::CvtHelper<cv::Set<1, -1, -1>, cv::Set<3, 4, -1>, cv::Set<0, 2, 5>, cv::SizePolicy::NONE>::CvtHelper(InputArray, OutputArray, int) [VScn = cv::Set<1, -1, -1>, VDcn = cv::Set<3, 4, -1>, VDepth = cv::Set<0, 2, 5>, sizePolicy = cv::SizePolicy::NONE]'

Invalid number of channels in input image:
'VScn::contains(scn)'
where
'scn' is 3

Instead of using line:

cvtColor(inputImage, outputImage, CV_GRAY2RGBA);

Use line:

cvtColor(inputImage, outputImage, CV_32FC(1));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.