Visual Studio Setup Blocked or Can’t Uninstall

For some reason a Visual Studio 2015 Community Edition installation I had on one of my machines was experiencing problems: solution files were not loading properly, and what’s worse is that installation instance had gone totally missing from “Uninstall a Program” in Windows Control Panel. Also, every time I tried running the setup file vs_community.exe from the ISO image, I would get an error saying “The product version that you are trying to set up is earlier than the version already installed on this computer”.

What I ended up doing was to run the setup file with the two following switches:

vs_community.exe /uninstall /force

Luckily, it went forward with uninstalling the instance I had on my machine.

Create Bootable USB Flash Drive from ISO Image (with UEFI Support)

Update: If you’re looking for Windows 10 UEFI installation, take a look at the addendum at the end of the post!

Although there are a lot of applications for creating a bootable flash drive using an ISO image (such as UNetBootin), not many of them support the creation of a bootable flash drive that can be used for installing the operating system in UEFI mode (I’ve never succeeded with UNetBootin personally!).

There is a comprehensive guide about installing Linux in UEFI mode that details all the do’s and don’ts. Most of us are already familiar with all the necessary steps but the creation of a bootable UEFI compatible flash drive from an ISO file 😀 . There are two ways to create a UEFI compatible flash drive:


There is a great application called rufus that does the trick for you. You can find it here. The good thing about this app is that the USB flash drive will end up with a single partition and is still usable in Windows.


(That’s Too Long; Wanna Read; for the lack of a better acronym!)

The other possibility is to use the good ol’ Linux utility disk dump ( dd). dd It should be already available under any Linux installation. It is also available under Windows if you have Cygwin installed. The procedure is as follows.

WARNING: You will loose all the data on your flash drive.

NOTE: If you’re using Cygwin, make sure to run Cygwin as Administrator (right click, run as Administrator).

  1. Insert the flash drive and determine what device it has been mapped to by running.
    cat /proc/partitionsThis should output a list of partitions in /dev. The devices and the partitions are numbered. Since you want to work directly with the whole drive, ignore the numbers at the end. In my case, I found out that my flash drive was mapped to /dev/sde (by observing two entries in the list: /dev/sde and /dev/sde1). Make sure you select the correct partition otherwise you’ll ruin another storage device.
  2. Dump the ISO file to the device you noted in step 1:
    dd if=/path/to/your/image.iso of=[the device above] bs=4MIn my case it was:
    dd if=~/image.iso of=/dev/sde bs=4M

This will start dumping the image onto the flash drive. You won’t get any output from the command while the operation is in progress. To check the progress, you need to open another terminal (command) window, determine the PID of dd process by running ps -e (which will give you PID), and then running the command kill -USR1 [PID]; sleep 1; to see the output of dd in the original terminal (command) window.

After the operation has completed, you can boot the flash drive in UEFI mode. The flash drive is booted in UEFI mode if the output of the following command is a list of files:

ls /sys/firmware/efi

Hopefully, the next time I want to install a Linux distro in UEFI mode, I wouldn’t have to Google for two hours.


Unsurprisingly, rufust can also be used for Windows 10 UEFI installation. Unfortunately, I didn’t have much luck with Microsoft’s media creation tool. I used it at first, yet I was getting the black screen which says the installation cannot continue (wish I had taken a note of what it said exactly).

Nevertheless, installation with rufus went smoothly. Here’s a direct link to Windows 10 ISO (link courtesy of Reddit). Grab the image, run rufus, select GPT Partition Scheme for UEFI, file system MUST be FAT32 (I chose the block size of 8192, anything other than FAT32 did not boot for me). Click start and you’re golden 🙂 I also had CSM enabled in my bios settings. Not sure if that really mattered though!

UPDATE: I noticed that the above settings had to be slightly different if the goal was an MBR/BIOS installation. What I had to do was to select “MBR Partition Scheme for BIOS or UEFI-CSM“, and the file system must have been NTFS. Also, I had to completely disable secure boot in the BIOS settings to get the flash drive too boot up.


Align Depth and Color Frames – Depth and RGB Registration

Sometimes it is necessary to create a point cloud from a given depth and color (RGB) frame. This is especially the case when a scene is captured using depth cameras such as Kinect. The process of aligning the depth and the RGB frame is called “registration” and it is very easy to do (and the algorithm’s pseudo-code is surprisingly hard to find with a simple Google search! 😀 )

To perform registration, you would need 4 pieces of information:

  1. The depth camera intrinsics:
    1. Focal lengths fxd and fyd (in pixel units)
    2. Optical centers (sometimes called image centers) Cxd and Cyd
  2. The RGB camera intrinsics:
    1. Focal lengths fxrgb and fyrgb (in pixel units)
    2. Optical centers (sometimes called image centers) Cxrgb and Cyrgb
  3. The extrinsics relating the depth camera to the RGB camera. This is a 4×4 matrix containing rotation and translation values.
  4. (Obviously) the depth and the RGB frames. Note that they do not have to have the same resolution. Applying the intrinsics takes care of the resolution issue. Using camera’s such as Kinect, the depth values should usually be in meters (the unit of the depth values is very important as using incorrect units will result in a registration in which the colors and the depth values are off and are clearly misaligned).
    Also, note that some data sets apply a scale and a bias to the depth values in the depth frame. Make sure to account for this scaling and offsetting before proceeding. In order words, make sure there are no scales applied to the depth values of your depth frame.

Let depthData contain the depth frame and rgbData contain the RGB frame. The pseudo-code for registration in MATLAB is as follows:

A few things to note here:

  1. The indices x and y in the second group of for loops may be invalid which indicates that the obtained RGB pixel is not visible to the RGB camera.
  2. Some kind of interpolation may be necessary when using x and y. I just did rounding.
  3. This code can be readily used with savepcd function to save the point cloud into a PCL compatible format.

The registration formulas were obtained from the paper “On-line Incremental 3D Human Body Reconstruction for HMI or AR Applications” by Almeida et al (2011). The same formulas can be found here. Hope this helps 🙂


C++ Function in Header throws Linker “already defined” Errors

If you define a function in the global namespace in a C++ header file and encounter linker errors (complaining about the function already defined elsewhere), there’s a simple fix! Simply mark the function as inline. This will prevent the duplication of the function in other source files.

Note that using inclusion guards does not solve this problem and you must define the function as inline.

SimpleScalar Installation Under Windows

Installing the SimpleScalar simulator is relatively straightforward under Linux. For Windows installation, the Cygwin toolchain is required. Grab the latest Cygwin installer (setup-x86_64) from here: (note that this is intended for 64-bit machines).

After running the installer, just proceed through the wizard. The default installation directory is C:\cygwin64. When selecting a mirror website, usually is the fastest mirror. Select where you want the Cygwin packages to be installed. In the package installation window, select the following packages under Devel:

  1. gcc-core
  2. gcc-g++
  3. make

Also, under Web select the w3m package (this will make the download process much easier). The installer will say that additional dependencies are needed. Click “Yes” to install the additional dependency packages.

Note: To install a package, you can simply click on the circular arrows next to the name of the package. The text next to the arrow will cycle between “skip” and the desired version of the package. Feel free to install the latest available version of each of the packages above.

After the installation of Cygwin is finished, simply open a Cygwin bash terminal (by opening “Cygwin64 Terminal” from the installed programs in Start menu) and follow these steps (credits go to Ramya Pradhan):

  1. Download SimpleScalar:
    Use the arrow keys to navigate to the bottom of the page to accept the terms. Move the cursor to ‘I Agree’ and hit enter. You will see a message ‘(Download) Save file to: simplesim-3v0e.tgz’ at the bottom of the page, hit enter to save file in the current directory. To get out of the browser, press q.
  2. Compile SimpleScalar
     tar xvzf simplesim-3v0e.tgz
     cd simplesim-3.0
     make config-pisa
  3. Test the installation using
     ./sim-safe tests/bin.little/test-math

Git: Merge Specific Commit from Another Branch to Main Branch

Let’s say that in your git repository, you have a master branch and an experimental branch. You’ve fixed a bug on file A on the experimental branch and you would like to commit that fix to the master branch. This is possible using the git cherry-pick command.

First, switch to the experimental branch and execute git log. Take note of the ID of the commit you’d like to merge into the master branch. Now switch to the master branch and use the command git cherry-pick ID where ID is the ID of the commit you noted earlier. This will merge the selected commit into the master branch.

3D Line Fitting in 5 Easy Steps with SVD

Least squares fit is used for 2D line fitting. In 3D space, the line is called 3D Orthogonal Distance Regression (ODR) line. The line can be easily found in 3D using SVD (singular value decomposition).

Assuming that we have a bunch of 3D points (x0, y0, z0) to (xn, yn, zn), the algorithm (in MATLAB) is as follows:


Intersection of a Ray and a Line Segment in 3D

This page contains methods for performing various intersection tests. Although it does not have an entry for ray vs. line segment intersection, I tried the suggested ray vs. ray intersection test (page 782 of Real-Time Rendering 3rd Edition) and it did not work in my case.

I looked around quite a bit and based on an adaptation of this answer, I finally found a method that works fine. Given a ray (with a start point, an end point and direction) and a line segment with the defined start and end points, we perform the 3D line intersection test. However, note that in various graphics APIs, there is always some error when converting screen points to lines (because there is no 1-1 mapping from screen pixels to exact 3D points in space). Therefore, when performing intersection tests, some degree of tolerance must be considered. This is especially important in the early rejection step of the intersection test algorithm. The early rejection test, checks to see whether the two 3D lines are co-planer. If they aren’t, then no intersection will be reported.

After finding the intersection point, we must check and see if this point lies between the start and end points of the line segment. This can be done by comparing the length of the line segment with the sum of distances of the intersection point from the start point and end point of the line segment respectively. If the length is “almost” equal, then it means that the original ray will intersect with the line segment.

Here is the pseudo-code of the described process (adapted from the original answer):


Tutorial : Use CUDA and C++11 Code in MATLAB

As it turns out, incorporating CUDA code in MATLAB can be easily done! 🙂

MATLAB provides functionality for loading arbitrary dynamic libraries and invoking their functions. This is especially easy for invoking C/C++ code in a MATLAB program. Such functionality is possible using the so called MEX functions.


Mex functions can be created with the mex command in MATLAB. Essentially, mex takes as input a C/C++ source file, invokes the default C/C++ compiler installed in the operating system (GCC or CL), and creates a mexa64 file (on a 64-bit machine) which can be used like any other MATLAB function.

The C/C++ file that is passed to mex must have the following included in it:

The arguments that are passed from MATLAB are accessible using the prhs parameter (which stands for parameters-right hand side). Any output that the gateway function generates can be returned using the plhs parameter (which stands for parameter-left hand side). The number of the arguments that are passed to the gateway function is stored in the nrhs parameter and the number of outputs that the MATLAB code expects from the gateway function is stored in the nlhs parameter. From this point on, I refer to the file containing the above code as the mex gateway file. Also, I will refer to the mexFunction above as the gateway function.

Continue reading Tutorial : Use CUDA and C++11 Code in MATLAB