# How to develop GUI Application with PyQt (python Qt)

There are two main methods for developing GUI application with qt:

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

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.

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 🙂

# Installing NVIDIA DIGIST Ubuntu 16.04

### caffe

Install caffe as being explained in my other post here.

### 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

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

### 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.

### 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.

# 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:

\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

$$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}$$

\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}

$$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$$

# Examples of Dynamic Programming with C++ and Matlab

In this tutorial, I will give you examples of using dynamic programming for solving the following problems:

1)Minimum number of coins for summing X.

2)The most (least) costly path on a grid (dynamic time warping).

3)Levenshtein edit distance.

4)Seam Carving. I have written a tutorial on that here and the recursive part is in the following lines:

The examples are taken from “Competitive Programmer’s Handbook” written by Antti Laaksonen.