Category Archives: C++

How to develop GUI Application with PyQt (python Qt)

There are two main methods for developing GUI application with qt:
1) Adding all widgets in your code (your cpp or python code)
2) Creating qt UI files, adding widgets there and load everything into your application.

1)Adding all widgets in your code

Here is the snippet for adding all widgets and their slots in code:

2) Creating qt UI files, adding widgets there and load everything into your application

Now let’s do what we have done in the first method in a UI file and load it. First, create a text file and put the followings in it and save it as “mainwindow.ui”

Now call it in your python file like this:

The results should be the same as what you got in the first method.

Adding Qt UI files to your CMake

Qt uses qmake  to generate classes from UI files and compile everything in the project, luckily there are some macros in CMake that allows you to bring everything into your CMake and build everything there, here is what you need to do:

you can find the full project at my Github

 

Clang format and code beautifier for Qt Creator

Different developers use different styles with different IDE (i.e some people use space, some use tab) which may cause lots of change in your git repository. One solution to this is to use some standard code formatting and beautifier. clang is a great tool for this purpose and can be easily integrated with git hooks and IDE.
First, install it by:

now if you have a file like this:

after running the following:

now you can use it like:

Available styles are LLVM, Google, Chromium, Mozilla, WebKit.

You can config clang for Qt Creator:

go to Tools>Option then:

And then go to the Environment>keyboard and set your shortcut:

This is what I get after pressing shift+s:

 

Human detection and Pose Estimation with Deep Learning for Sport Analysis

Pose estimation and tracking human is one the key step in sports analysis. Here is in this work I used openpose for analysis of player in a Bundesliga game HSV Hamburg vs Bayer München. Warning: the video might be disturbing for HSV fans 🙂

 

Original Video

Analyzed Video

Original Video

Analyzed Video

Original Video

Analyzed Video

Original Video

Analyzed Video

Vaganova_Ballet_Academy from Behnam Asadi on Vimeo.

 

Original Video

Analyzed Video

 

 

Thiem_Zverev from Behnam Asadi on Vimeo.

Installing NVIDIA DIGIST Ubuntu 16.04

Prerequisite

Protobuf 3

caffe

Install caffe as being explained in my other post here.

DIGITS

visit https://github.com/NVIDIA/DIGITS/

Dependencies

# Install repo packages

Building DIGITS

Open in the browser:

http://localhost:5000/

How to use OpenCV 3 Contribution Modules

OpenCV Contribution Modules are developed code from the community of OpenCV and are not very stable but after they got stable they will be part f OpenCV. Anyhow, there are a lot of cool modules there (fuzzy logic, sfm, cnn, …) that made me have look at them and try them.

 

1)gflags

2)glog

3)ceres-solver

 

4)OpenCV

To install them download OpenCV3 and OpenCV’s extra modules.

Add the following lines to the top of CMakeLists at root of OpenCV

Make a build directory in OpenCV3 and changed the current directory to that, then run the following command:

 

Open source Structure-from-Motion and Multi-View Stereo tools with C++

Structure-from-Motion (SFM) is genuinely an interesting topic in computer vision, Basically making 3D structure from something 2D is absolutely mesmerizing 🙂

There two open source yet very robust tools for SFM, which sometimes compiling them might be complicated, here I will share my experience with you.

1)VisualSFM

Prerequisite:

1)Glew

Download the glew from SF at http://glew.sourceforge.net/. Do NOT get it from Github as to seems to have some problems.

2)SiftGPU

Prerequisite:

Install DevIl Image library

open makefile and enable siftgpu_enable_cuda

now go to bin directory and libsiftgpu.so to your vsfm bin directory

VSFM

you can see the some of my results here:

Note: if you don’t have cuda or Nvidia driver you can use your CPU but then you have to limit your file image size and sift binary should be available in your vsfm/bin directory.

Download http://www.cs.ubc.ca/~lowe/keypoints/siftDemoV4.zip and make it and copy the sift binary to vsfm/bin.

2)Colmap

The installation fo this one is almost straightforward except you need the latest version of Ceres Solver (do not use the one binary package from Ubuntu they are old and they won’t work). So download and make and install the Ceres Solver using the following:

Now in the colmap CMakeList.txt add the following line:

just before “find_package(Ceres REQUIRED)”

and now you can make and install it. You can see some of my results here:

In the next post, I will show you how can you do that in OpenCV.

Computing OpticalFlow with OpenCV

There are two main approaches for computing optical flow, computing optical flow for all pixel or computing optical flow for corners.

1. Computing optical flow for all pixel

2. Computing optical flow for corners

 

 

Finding Homography Matrix using Singular-value Decomposition and RANSAC in OpenCV and Matlab

\(\)

Solving a Homography problem leads to solving a set of homogeneous linear equations such below:

\begin{equation}
\left(
\begin{array}{ccccccccc}
-x1 & -y1 & -1 & 0 & 0 & 0 & x1*xp1 & y1*xp1 & xp1\\
0 & 0 & 0 & -x1 & -y1 & -1 & x1*yp1 & y1*yp1 &  yp1\\
-x2 & -y2 & -1 & 0 & 0 & 0 & x2*xp2 & y2*xp2 & xp2\\
0 & 0 & 0 & -x2 & -y2 & -1 & x2*yp2 & y2*yp2 & yp2\\
-x3 & -y3 & -1 & 0 & 0 & 0 & x3*xp3 & y3*xp3 & xp3\\
0 & 0 & 0 & -x3 & -y3 & -1 & x3*yp3 & y3*yp3 & yp3\\
-x4 & -y4 & -1 & 0 & 0 & 0 & x4*xp4 & y4*xp4 & xp4\\
0 & 0 & 0 & -x4 & -y4 & -1 & x4*yp4 & y4*yp4 & yp4\\
\end{array}
\right) *H=0
\end{equation}

\( H^{*} \underset{H}{\mathrm{argmin}}= \|AH\|^{2}  \) subject to \( \|H\|=1 \)

We can’t use least square since it’s a homogeneous linear equations (the other side of equation is 0 therfore we can’t just multyly it by the psudo inverse). To solve this problem we use Singular-value Decomposition (SVD).

For any given matrix \( A_{M{\times}N} \)

\begin{equation}
\underbrace{\mathbf{A}}_{M \times N} = \underbrace{\mathbf{U}}_{M \times M} \times \underbrace{\mathbf{\Sigma}}_{M\times N} \times \underbrace{\mathbf{V}^{\text{T}}}_{N \times N}
\end{equation}

\(U\) is an \( {M\times M} \) matrix with orthogonal matrix (columns are eigen vectors of A).
\(\Sigma\) is an \( {M\times N} \) matrix with non-negative entries, termed the singular values  (diagonal entries are eigen values of A).
\(V \) is an \( {N\times N} \) orthogonal matrix.

\( H^{*} \) is the last column of \(V \)

Finding homography matrix in Matlab between 4 pairs of points

Finding homography matrix in OpenCV between 4 pairs of points

 

Finding homography matrix in OpenCV between N pairs of points

Applying homography matrix in OpenCV