Tag Archives: C++

Decomposing Projection Using OpenCV and C++



And the output is:


How to use image_geometry and camera_info_manager in ROS







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.




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



Install DevIl Image library

open makefile and enable siftgpu_enable_cuda

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


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.


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.

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.

Peak Signal-to-Noise Ratio (PSNR) in Image using OpenCV and Matlab


Peak signal-to-noise ratio (PSNR) shows the ratio between the maximum possible power of a signal and the power of the same image with noise. PSNR is usually expressed in logarithmic decibel scale.

\( MSE =1/m*n \sum_{i=0}^{m-1} \sum_{j=0}^{n-1}  [   Image( i,j)  -NoisyImage( i,j)  ]  ^2   \)
\( PSNR =10* \log_{10} \Bigg(MAXI^2/MSE\Bigg)  \)

MSE is Mean Square Error and MAXI is the maximum possible pixel value of the image. For instance if the image is uint8, it will be 255.


Ref [1],[2], [3], 4

get template parameter name and type with Boost demangle

Have you ever tied to get the type of a variable by its name? for instance “int”  or “string“?

The following code snippet shows how to use boost demangle to get the type:


Finding roll, pitch yaw from 3X3 rotation matrix with Eigen


pkg-config and CMake

The environmental variable:
PKG_CONFIG_PATH is the place that you should place all of your “.pc” files.

Type in the shell:

Then you can type:

Now how to print environmental variable in CMake file:

How to set environmental variable in CMake file:

After setting environmental variable PKG_CONFIG_PATH pointing to your .pc file you can call


How to find CMake from arbitrary installed locations

In my other tutorial, I showed you how to install your code in an arbitrary location in Unix/ Linux systems. In this tutorial, I’m gonna show you how to find them after installation. Here I have two examples: OpenCV, PCL point cloud

I can assume that you have compiled and installed them using the following command:

1)PCL point cloud

put this line in your CMake file:

and check if everything is correct:


put this line in your CMake file:

and check if everything is correct:

if you don’t want to make changes to your CMakeList.txt file you can send <>__DIR as CMake parameter. Example:


Installing programs into arbitrary location in Unix/ Linux systems

After you compiled and built your code, you should install it by calling sudo install to put headers and shared libraries into /usr/include/ and /usr/lib/ and configuration files into /usr/local and /usr/share

usually, I don’t like to touch my system binaries and I prefer to install my compiled code into my home directory so I can safely delete them anytime. If you using CMake use the following parameters to install everything in “/home/<user_name>/usr” instead of “/usr

if you are just using make, use the following: